From 718f5c444f527f9659ef11d85b022596f7bbf7b8 Mon Sep 17 00:00:00 2001 From: Monica Cellio Date: Fri, 13 Sep 2024 15:48:14 -0400 Subject: [PATCH 1/8] checkpoint (not working) --- app/controllers/users_controller.rb | 6 ++++++ app/views/users/_network.html.erb | 15 +++++++++++++++ app/views/users/_tabs.html.erb | 5 ++++- app/views/users/network.html.erb | 10 ++++++++++ config/routes.rb | 1 + 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/views/users/_network.html.erb create mode 100644 app/views/users/network.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 562c65aa7..91fdd1999 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -201,6 +201,12 @@ def posts end end + def network + @communities = Community.all + render layout: 'without_sidebar' + end + + def activity @posts = Post.undeleted.where(user: @user).count @comments = Comment.joins(:comment_thread, :post).undeleted.where(user: @user, comment_threads: { deleted: false }, diff --git a/app/views/users/_network.html.erb b/app/views/users/_network.html.erb new file mode 100644 index 000000000..162209dc8 --- /dev/null +++ b/app/views/users/_network.html.erb @@ -0,0 +1,15 @@ + + + + + + + + <% @communities.each do |c| %> + + + + + <% end %> + +
CommunityPostsReputation
diff --git a/app/views/users/_tabs.html.erb b/app/views/users/_tabs.html.erb index 99f7fb937..bbb9eb690 100644 --- a/app/views/users/_tabs.html.erb +++ b/app/views/users/_tabs.html.erb @@ -24,5 +24,8 @@ <%= link_to notifications_path, class: "tabs--item #{current_page?(notifications_path) ? 'is-active' : ''}" do %> Notifications <% end %> + <%= link_to network_path, class: "tabs--item #{current_page?(network_path) ? 'is-active' : ''}" do %> + All Communities + <% end %> <% end %> - \ No newline at end of file + diff --git a/app/views/users/network.html.erb b/app/views/users/network.html.erb new file mode 100644 index 000000000..511892ace --- /dev/null +++ b/app/views/users/network.html.erb @@ -0,0 +1,10 @@ +<%= render 'tabs', user: current_user %> + +

Profiles for <%= user_link @user %>

+ +

+ Links to profiles on other communities on this network. +

+ +<%= render 'network' %> + diff --git a/config/routes.rb b/config/routes.rb index f4066cdc4..bd155c94c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -202,6 +202,7 @@ get '/:id/mod', to: 'users#mod', as: :mod_user get '/:id/posts', to: 'users#posts', as: :user_posts get '/:id/vote-summary', to: 'users#vote_summary', as: :vote_summary + get '/:id/network', to: 'users#network', as: :network get '/:id/mod/privileges', to: 'users#mod_privileges', as: :user_privileges post '/:id/mod/privileges', to: 'users#mod_privilege_action', as: :user_privilege_action post '/:id/mod/toggle-role', to: 'users#role_toggle', as: :toggle_user_role From d1a7d8813bdba010f22bda762f04f8ed95c54415 Mon Sep 17 00:00:00 2001 From: Monica Cellio Date: Mon, 16 Sep 2024 23:04:24 -0400 Subject: [PATCH 2/8] adds partially-working network tab to user profile: links work, posts/rep are wrong, want to replace user names in links with community names --- app/controllers/users_controller.rb | 3 +-- app/models/user.rb | 10 ++++++++++ app/views/users/_network.html.erb | 17 +++++++++++++---- app/views/users/_tabs.html.erb | 6 +++--- app/views/users/network.html.erb | 2 +- config/routes.rb | 3 ++- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 91fdd1999..4dd4a8ae2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -11,7 +11,7 @@ class UsersController < ApplicationController :annotate, :annotations, :mod_privileges, :mod_privilege_action] before_action :set_user, only: [:show, :mod, :destroy, :soft_delete, :posts, :role_toggle, :full_log, :activity, :annotate, :annotations, :mod_privileges, :mod_privilege_action, - :vote_summary, :avatar] + :vote_summary, :network, :avatar] before_action :check_deleted, only: [:show, :posts, :activity] def index @@ -205,7 +205,6 @@ def network @communities = Community.all render layout: 'without_sidebar' end - def activity @posts = Post.undeleted.where(user: @user).count diff --git a/app/models/user.rb b/app/models/user.rb index 21798863b..a50422760 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # Represents a user. Most of the User's logic is controlled by Devise and its overrides. A user, as far as the # application code (i.e. excluding Devise) is concerned, has many questions, answers, and votes. class User < ApplicationRecord @@ -138,6 +139,15 @@ def is_admin is_global_admin || community_user&.is_admin || false end + def has_profile_on(community_id) + cu = community_users.where(community_id: community_id).first + if cu&.user_id.nil? + false + else + true + end + end + def has_ability_on(community_id, ability_internal_id) cu = community_users.where(community_id: community_id).first if cu&.is_moderator || cu&.is_admin || is_global_moderator || is_global_admin || cu&.privilege?('mod') diff --git a/app/views/users/_network.html.erb b/app/views/users/_network.html.erb index 162209dc8..5f2677b63 100644 --- a/app/views/users/_network.html.erb +++ b/app/views/users/_network.html.erb @@ -1,15 +1,24 @@ +

User: <%= @user %>

+

User link: <%= user_link @user %>

+ + <% @communities.each do |c| %> - - - - + <% if @user.has_profile_on(c) %> + + + + + + <% end %> <% end %> +
User (temporary) Community Posts Reputation
<%= user_link @user, { host: c.host } %> + <%= c.name %><%= @user.posts.count %><%= @user.reputation %>
diff --git a/app/views/users/_tabs.html.erb b/app/views/users/_tabs.html.erb index bbb9eb690..fb2c9d191 100644 --- a/app/views/users/_tabs.html.erb +++ b/app/views/users/_tabs.html.erb @@ -24,8 +24,8 @@ <%= link_to notifications_path, class: "tabs--item #{current_page?(notifications_path) ? 'is-active' : ''}" do %> Notifications <% end %> - <%= link_to network_path, class: "tabs--item #{current_page?(network_path) ? 'is-active' : ''}" do %> - All Communities - <% end %> + <% end %> + <%= link_to network_path(user), class: "tabs--item #{current_page?(network_path(user)) ? 'is-active' : ''}" do %> + All Communities <% end %> diff --git a/app/views/users/network.html.erb b/app/views/users/network.html.erb index 511892ace..cb520a24e 100644 --- a/app/views/users/network.html.erb +++ b/app/views/users/network.html.erb @@ -1,4 +1,4 @@ -<%= render 'tabs', user: current_user %> +<%= render 'tabs', user: @user %>

Profiles for <%= user_link @user %>

diff --git a/config/routes.rb b/config/routes.rb index bd155c94c..f3b1c81b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -193,6 +193,7 @@ get '/edit/profile', to: 'users#edit_profile', as: :edit_user_profile patch '/edit/profile', to: 'users#update_profile', as: :update_user_profile get '/me/vote-summary', to: 'users#my_vote_summary', as: :my_vote_summary + get '/me/network', to: 'users#my_network', as: :my_network get '/avatar/:letter/:color/:size', to: 'users#specific_avatar', as: :specific_auto_avatar get '/disconnect-sso', to: 'users#disconnect_sso', as: :user_disconnect_sso post '/disconnect-sso', to: 'users#confirm_disconnect_sso', as: :user_confirm_disconnect_sso @@ -202,7 +203,7 @@ get '/:id/mod', to: 'users#mod', as: :mod_user get '/:id/posts', to: 'users#posts', as: :user_posts get '/:id/vote-summary', to: 'users#vote_summary', as: :vote_summary - get '/:id/network', to: 'users#network', as: :network + get '/:id/network', to: 'users#network', as: :network get '/:id/mod/privileges', to: 'users#mod_privileges', as: :user_privileges post '/:id/mod/privileges', to: 'users#mod_privilege_action', as: :user_privilege_action post '/:id/mod/toggle-role', to: 'users#role_toggle', as: :toggle_user_role From a553e0d90c76b0a30d7c8b4547337190d5c70bd6 Mon Sep 17 00:00:00 2001 From: Monica Cellio Date: Mon, 16 Sep 2024 23:05:32 -0400 Subject: [PATCH 3/8] Removed debugging output. --- app/views/users/_network.html.erb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/views/users/_network.html.erb b/app/views/users/_network.html.erb index 5f2677b63..315f38a4b 100644 --- a/app/views/users/_network.html.erb +++ b/app/views/users/_network.html.erb @@ -1,6 +1,3 @@ -

User: <%= @user %>

-

User link: <%= user_link @user %>

- @@ -19,6 +16,5 @@ <% end %> <% end %> -
User (temporary)
From 4c0206a1e23943f145769b5a38b932cf54f4d806 Mon Sep 17 00:00:00 2001 From: Monica Cellio Date: Tue, 17 Sep 2024 16:22:28 -0400 Subject: [PATCH 4/8] very basic working network profile --- app/helpers/users_helper.rb | 9 ++++++--- app/models/community_user.rb | 5 +++++ app/models/user.rb | 20 ++++++++++++++++++++ app/views/users/_network.html.erb | 14 ++++++++------ 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4ffec4be6..e1d885d8d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -61,10 +61,13 @@ def rtl_safe_username(user) def user_link(user, url_opts = nil, **link_opts) url_opts ||= {} - if deleted_user?(user) - link_to 'deleted user', '#', { dir: 'ltr' }.merge(link_opts) + anchortext = link_opts[:anchortext] + if anchortext != nil + link_to anchortext, user_url(user, **url_opts), { dir: 'ltr' }.merge(link_opts) + elsif deleted_user?(user) + link_to 'deleted user', '#', { dir: 'ltr' }.merge(link_opts).except(:anchortext) else - link_to user.rtl_safe_username, user_url(user, **url_opts), { dir: 'ltr' }.merge(link_opts) + link_to user.rtl_safe_username, user_url(user, **url_opts), { dir: 'ltr' }.merge(link_opts).except(:anchortext) end end diff --git a/app/models/community_user.rb b/app/models/community_user.rb index a62926dcc..f68589a43 100644 --- a/app/models/community_user.rb +++ b/app/models/community_user.rb @@ -24,6 +24,11 @@ def suspended? false end + # All undeleted posts on this community by this user. + def post_count + Post.unscoped.where(community_id: community_id).where(user: user).undeleted.count + end + # Calculation functions for privilege scores # These are quite expensive, so we'll cache them for a while def post_score diff --git a/app/models/user.rb b/app/models/user.rb index a50422760..684e62d87 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -139,6 +139,7 @@ def is_admin is_global_admin || community_user&.is_admin || false end + # Used by network profile: does this user have a profile on that other comm? def has_profile_on(community_id) cu = community_users.where(community_id: community_id).first if cu&.user_id.nil? @@ -148,6 +149,25 @@ def has_profile_on(community_id) end end + def reputation_on(community_id) + cu = community_users.where(community_id: community_id).first + cu&.reputation + end + + def post_count_on(community_id) + cu = community_users.where(community_id: community_id).first + cu&.post_count + end + + def is_moderator_on(community_id) + cu = community_users.where(community_id: community_id).first + if cu&.is_moderator || cu&.privilege?('mod') + true + else + false + end + end + def has_ability_on(community_id, ability_internal_id) cu = community_users.where(community_id: community_id).first if cu&.is_moderator || cu&.is_admin || is_global_moderator || is_global_admin || cu&.privilege?('mod') diff --git a/app/views/users/_network.html.erb b/app/views/users/_network.html.erb index 315f38a4b..a1f9258aa 100644 --- a/app/views/users/_network.html.erb +++ b/app/views/users/_network.html.erb @@ -1,7 +1,6 @@ - - + @@ -9,10 +8,13 @@ <% @communities.each do |c| %> <% if @user.has_profile_on(c) %> - - - + + + <% end %> <% end %> From acf015b212c7812878a0ba880d63542317c6b593 Mon Sep 17 00:00:00 2001 From: Monica Cellio Date: Tue, 17 Sep 2024 17:02:18 -0400 Subject: [PATCH 5/8] rubocop --- app/helpers/users_helper.rb | 2 +- app/models/community_user.rb | 2 +- app/models/user.rb | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index e1d885d8d..25cb0edca 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -62,7 +62,7 @@ def rtl_safe_username(user) def user_link(user, url_opts = nil, **link_opts) url_opts ||= {} anchortext = link_opts[:anchortext] - if anchortext != nil + if !anchortext.nil? link_to anchortext, user_url(user, **url_opts), { dir: 'ltr' }.merge(link_opts) elsif deleted_user?(user) link_to 'deleted user', '#', { dir: 'ltr' }.merge(link_opts).except(:anchortext) diff --git a/app/models/community_user.rb b/app/models/community_user.rb index f68589a43..43e8fa1e3 100644 --- a/app/models/community_user.rb +++ b/app/models/community_user.rb @@ -28,7 +28,7 @@ def suspended? def post_count Post.unscoped.where(community_id: community_id).where(user: user).undeleted.count end - + # Calculation functions for privilege scores # These are quite expensive, so we'll cache them for a while def post_score diff --git a/app/models/user.rb b/app/models/user.rb index 684e62d87..32054cd41 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,3 @@ -# coding: utf-8 # Represents a user. Most of the User's logic is controlled by Devise and its overrides. A user, as far as the # application code (i.e. excluding Devise) is concerned, has many questions, answers, and votes. class User < ApplicationRecord @@ -167,7 +166,7 @@ def is_moderator_on(community_id) false end end - + def has_ability_on(community_id, ability_internal_id) cu = community_users.where(community_id: community_id).first if cu&.is_moderator || cu&.is_admin || is_global_moderator || is_global_admin || cu&.privilege?('mod') From 31bdfc292e2f141ec1bcebba98fda7310271faf5 Mon Sep 17 00:00:00 2001 From: Monica Cellio Date: Tue, 17 Sep 2024 17:04:30 -0400 Subject: [PATCH 6/8] rubocop --- app/models/user.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 32054cd41..755d18d9a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -141,11 +141,7 @@ def is_admin # Used by network profile: does this user have a profile on that other comm? def has_profile_on(community_id) cu = community_users.where(community_id: community_id).first - if cu&.user_id.nil? - false - else - true - end + !cu&.user_id.nil? end def reputation_on(community_id) From 56f5a7fe5750e19542c2bae050ab6ea5d87d80be Mon Sep 17 00:00:00 2001 From: Monica Cellio Date: Tue, 17 Sep 2024 17:57:19 -0400 Subject: [PATCH 7/8] extra safety and style cleanup --- app/helpers/users_helper.rb | 5 +++-- app/models/user.rb | 13 +++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 25cb0edca..79ae8ac3d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -62,12 +62,13 @@ def rtl_safe_username(user) def user_link(user, url_opts = nil, **link_opts) url_opts ||= {} anchortext = link_opts[:anchortext] + link_opts_reduced = { dir: 'ltr' }.merge(link_opts).except(:anchortext) if !anchortext.nil? link_to anchortext, user_url(user, **url_opts), { dir: 'ltr' }.merge(link_opts) elsif deleted_user?(user) - link_to 'deleted user', '#', { dir: 'ltr' }.merge(link_opts).except(:anchortext) + link_to 'deleted user', '#', link_opts_reduced else - link_to user.rtl_safe_username, user_url(user, **url_opts), { dir: 'ltr' }.merge(link_opts).except(:anchortext) + link_to user.rtl_safe_username, user_url(user, **url_opts), link_opts_reduced end end diff --git a/app/models/user.rb b/app/models/user.rb index 755d18d9a..1985c9676 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # Represents a user. Most of the User's logic is controlled by Devise and its overrides. A user, as far as the # application code (i.e. excluding Devise) is concerned, has many questions, answers, and votes. class User < ApplicationRecord @@ -141,26 +142,22 @@ def is_admin # Used by network profile: does this user have a profile on that other comm? def has_profile_on(community_id) cu = community_users.where(community_id: community_id).first - !cu&.user_id.nil? + !cu&.user_id.nil? || false end def reputation_on(community_id) cu = community_users.where(community_id: community_id).first - cu&.reputation + cu&.reputation || 1 end def post_count_on(community_id) cu = community_users.where(community_id: community_id).first - cu&.post_count + cu&.post_count || 0 end def is_moderator_on(community_id) cu = community_users.where(community_id: community_id).first - if cu&.is_moderator || cu&.privilege?('mod') - true - else - false - end + cu&.is_moderator || cu&.privilege?('mod') end def has_ability_on(community_id, ability_internal_id) From ee97921c30adc3cab1e34ae688515e067c8134c1 Mon Sep 17 00:00:00 2001 From: Monica Cellio Date: Tue, 17 Sep 2024 18:40:32 -0400 Subject: [PATCH 8/8] rubocop --- app/models/user.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 1985c9676..bd4327c00 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,3 @@ -# coding: utf-8 # Represents a user. Most of the User's logic is controlled by Devise and its overrides. A user, as far as the # application code (i.e. excluding Devise) is concerned, has many questions, answers, and votes. class User < ApplicationRecord
User (temporary)CommunityProfile on Community Posts Reputation
<%= user_link @user, { host: c.host } %> - <%= c.name %><%= @user.posts.count %><%= @user.reputation %> <%= user_link @user, { host: c.host}, anchortext: c.name %> + <% if @user.is_moderator_on(c) %> + (moderator) + <% end %> + <%= @user.post_count_on(c) %> <%= @user.reputation_on(c) %>