diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 562c65aa7..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 @@ -201,6 +201,11 @@ 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/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4ffec4be6..79ae8ac3d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -61,10 +61,14 @@ 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] + 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', '#', link_opts_reduced 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), link_opts_reduced end end diff --git a/app/models/community_user.rb b/app/models/community_user.rb index a62926dcc..43e8fa1e3 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 21798863b..bd4327c00 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -138,6 +138,27 @@ 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 + !cu&.user_id.nil? || false + end + + def reputation_on(community_id) + cu = community_users.where(community_id: community_id).first + cu&.reputation || 1 + end + + def post_count_on(community_id) + cu = community_users.where(community_id: community_id).first + cu&.post_count || 0 + end + + def is_moderator_on(community_id) + cu = community_users.where(community_id: community_id).first + cu&.is_moderator || cu&.privilege?('mod') + 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 new file mode 100644 index 000000000..a1f9258aa --- /dev/null +++ b/app/views/users/_network.html.erb @@ -0,0 +1,22 @@ +
Profile on Community | +Posts | +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) %> | +
+ Links to profiles on other communities on this network. +
+ +<%= render 'network' %> + diff --git a/config/routes.rb b/config/routes.rb index f4066cdc4..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,6 +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/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