diff options
Diffstat (limited to 'app/helpers/users_helper.rb')
-rw-r--r-- | app/helpers/users_helper.rb | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 7d4ab192f2f..a58f8a6f792 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,6 +1,13 @@ # frozen_string_literal: true module UsersHelper + def admin_users_data_attributes(users) + { + users: Admin::UserSerializer.new.represent(users).to_json, + paths: admin_users_paths.to_json + } + end + def user_link(user) link_to(user.name, user_path(user), title: user.email, @@ -60,6 +67,12 @@ module UsersHelper "access:#{max_project_member_access(project)}" end + def show_status_emoji?(status) + return false unless status + + status.message.present? || status.emoji != UserStatus::DEFAULT_EMOJI + end + def user_status(user) return unless user @@ -123,6 +136,19 @@ module UsersHelper } end + def user_unblock_data(user) + { + path: unblock_admin_user_path(user), + method: 'put', + modal_attributes: { + title: s_('AdminUsers|Unblock user %{username}?') % { username: sanitize_name(user.name) }, + message: s_('AdminUsers|You can always block their account again if needed.'), + okVariant: 'info', + okTitle: s_('AdminUsers|Unblock') + }.to_json + } + end + def user_block_effects header = tag.p s_('AdminUsers|Blocking user has the following effects:') @@ -136,8 +162,75 @@ module UsersHelper header + list end + def user_deactivation_data(user, message) + { + path: deactivate_admin_user_path(user), + method: 'put', + modal_attributes: { + title: s_('AdminUsers|Deactivate user %{username}?') % { username: sanitize_name(user.name) }, + messageHtml: message, + okVariant: 'warning', + okTitle: s_('AdminUsers|Deactivate') + }.to_json + } + end + + def user_activation_data(user) + { + path: activate_admin_user_path(user), + method: 'put', + modal_attributes: { + title: s_('AdminUsers|Activate user %{username}?') % { username: sanitize_name(user.name) }, + message: s_('AdminUsers|You can always deactivate their account again if needed.'), + okVariant: 'info', + okTitle: s_('AdminUsers|Activate') + }.to_json + } + end + + def user_deactivation_effects + header = tag.p s_('AdminUsers|Deactivating a user has the following effects:') + + list = tag.ul do + concat tag.li s_('AdminUsers|The user will be logged out') + concat tag.li s_('AdminUsers|The user will not be able to access git repositories') + concat tag.li s_('AdminUsers|The user will not be able to access the API') + concat tag.li s_('AdminUsers|The user will not receive any notifications') + concat tag.li s_('AdminUsers|The user will not be able to use slash commands') + concat tag.li s_('AdminUsers|When the user logs back in, their account will reactivate as a fully active account') + concat tag.li s_('AdminUsers|Personal projects, group and user history will be left intact') + end + + header + list + end + + def user_display_name(user) + return s_('UserProfile|Blocked user') if user.blocked? + + can_read_profile = can?(current_user, :read_user_profile, user) + return s_('UserProfile|Unconfirmed user') unless user.confirmed? || can_read_profile + + user.name + end + private + def admin_users_paths + { + edit: edit_admin_user_path(:id), + approve: approve_admin_user_path(:id), + reject: reject_admin_user_path(:id), + unblock: unblock_admin_user_path(:id), + block: block_admin_user_path(:id), + deactivate: deactivate_admin_user_path(:id), + activate: activate_admin_user_path(:id), + unlock: unlock_admin_user_path(:id), + delete: admin_user_path(:id), + delete_with_contributions: admin_user_path(:id), + admin_user: admin_user_path(:id) + } + end + def blocked_user_badge(user) pending_approval_badge = { text: s_('AdminUsers|Pending approval'), variant: 'info' } return pending_approval_badge if user.blocked_pending_approval? |