2018-08-18 11:19:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-23 08:43:34 +00:00
|
|
|
module UsersHelper
|
|
|
|
def user_link(user)
|
|
|
|
link_to(user.name, user_path(user),
|
|
|
|
title: user.email,
|
|
|
|
class: 'has-tooltip commit-committer-link')
|
|
|
|
end
|
2017-04-28 15:33:23 +00:00
|
|
|
|
|
|
|
def user_email_help_text(user)
|
2018-12-18 14:38:21 +00:00
|
|
|
return 'We also use email for avatar detection if no avatar is uploaded' unless user.unconfirmed_email.present?
|
2017-04-28 15:33:23 +00:00
|
|
|
|
|
|
|
confirmation_link = link_to 'Resend confirmation e-mail', user_confirmation_path(user: { email: @user.unconfirmed_email }), method: :post
|
|
|
|
|
|
|
|
h('Please click the link in the confirmation email before continuing. It was sent to ') +
|
|
|
|
content_tag(:strong) { user.unconfirmed_email } + h('.') +
|
|
|
|
content_tag(:p) { confirmation_link }
|
|
|
|
end
|
2017-12-11 14:21:06 +00:00
|
|
|
|
|
|
|
def profile_tabs
|
|
|
|
@profile_tabs ||= get_profile_tabs
|
|
|
|
end
|
|
|
|
|
|
|
|
def profile_tab?(tab)
|
|
|
|
profile_tabs.include?(tab)
|
|
|
|
end
|
|
|
|
|
2018-08-30 12:53:06 +00:00
|
|
|
def user_internal_regex_data
|
|
|
|
settings = Gitlab::CurrentSettings.current_application_settings
|
|
|
|
|
|
|
|
pattern, options = if settings.user_default_internal_regex_enabled?
|
|
|
|
regex = settings.user_default_internal_regex_instance
|
|
|
|
JsRegex.new(regex).to_h.slice(:source, :options).values
|
|
|
|
end
|
|
|
|
|
|
|
|
{ user_internal_regex_pattern: pattern, user_internal_regex_options: options }
|
|
|
|
end
|
|
|
|
|
2018-04-25 14:54:26 +00:00
|
|
|
def current_user_menu_items
|
|
|
|
@current_user_menu_items ||= get_current_user_menu_items
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user_menu?(item)
|
|
|
|
current_user_menu_items.include?(item)
|
|
|
|
end
|
|
|
|
|
2019-12-17 09:07:48 +00:00
|
|
|
# Used to preload when you are rendering many projects and checking access
|
|
|
|
#
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord: `projects` can be array which also responds to pluck
|
|
|
|
def load_max_project_member_accesses(projects)
|
|
|
|
current_user&.max_member_access_for_project_ids(projects.pluck(:id))
|
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
2018-07-06 07:51:31 +00:00
|
|
|
def max_project_member_access(project)
|
|
|
|
current_user&.max_member_access_for_project(project.id) || Gitlab::Access::NO_ACCESS
|
|
|
|
end
|
|
|
|
|
|
|
|
def max_project_member_access_cache_key(project)
|
|
|
|
"access:#{max_project_member_access(project)}"
|
|
|
|
end
|
|
|
|
|
2018-07-16 16:18:52 +00:00
|
|
|
def user_status(user)
|
|
|
|
return unless user
|
|
|
|
|
|
|
|
unless user.association(:status).loaded?
|
|
|
|
exception = RuntimeError.new("Status was not preloaded")
|
2019-12-16 12:07:43 +00:00
|
|
|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(exception, user: user.inspect)
|
2018-07-16 16:18:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return unless user.status
|
|
|
|
|
|
|
|
content_tag :span,
|
|
|
|
class: 'user-status-emoji has-tooltip',
|
|
|
|
title: user.status.message_html,
|
|
|
|
data: { html: true, placement: 'top' } do
|
|
|
|
emoji_icon user.status.emoji
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-24 12:39:16 +00:00
|
|
|
def impersonation_enabled?
|
|
|
|
Gitlab.config.gitlab.impersonation_enabled
|
|
|
|
end
|
|
|
|
|
2019-01-07 11:54:41 +00:00
|
|
|
def user_badges_in_admin_section(user)
|
|
|
|
[].tap do |badges|
|
2020-10-15 12:09:06 +00:00
|
|
|
badges << blocked_user_badge(user) if user.blocked?
|
2019-01-07 11:54:41 +00:00
|
|
|
badges << { text: s_('AdminUsers|Admin'), variant: 'success' } if user.admin?
|
|
|
|
badges << { text: s_('AdminUsers|External'), variant: 'secondary' } if user.external?
|
|
|
|
badges << { text: s_("AdminUsers|It's you!"), variant: nil } if current_user == user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-16 12:09:12 +00:00
|
|
|
def work_information(user)
|
|
|
|
return unless user
|
|
|
|
|
|
|
|
organization = user.organization
|
|
|
|
job_title = user.job_title
|
|
|
|
|
|
|
|
if organization.present? && job_title.present?
|
|
|
|
s_('Profile|%{job_title} at %{organization}') % { job_title: job_title, organization: organization }
|
|
|
|
elsif job_title.present?
|
|
|
|
job_title
|
|
|
|
elsif organization.present?
|
|
|
|
organization
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-15 12:09:06 +00:00
|
|
|
def can_force_email_confirmation?(user)
|
|
|
|
!user.confirmed?
|
|
|
|
end
|
|
|
|
|
2017-12-11 14:21:06 +00:00
|
|
|
private
|
|
|
|
|
2020-10-15 12:09:06 +00:00
|
|
|
def blocked_user_badge(user)
|
|
|
|
pending_approval_badge = { text: s_('AdminUsers|Pending approval'), variant: 'info' }
|
|
|
|
return pending_approval_badge if user.blocked_pending_approval?
|
|
|
|
|
|
|
|
{ text: s_('AdminUsers|Blocked'), variant: 'danger' }
|
|
|
|
end
|
|
|
|
|
2017-12-11 14:21:06 +00:00
|
|
|
def get_profile_tabs
|
2018-07-24 12:46:19 +00:00
|
|
|
tabs = []
|
|
|
|
|
|
|
|
if can?(current_user, :read_user_profile, @user)
|
2019-01-27 10:18:09 +00:00
|
|
|
tabs += [:overview, :activity, :groups, :contributed, :projects, :starred, :snippets]
|
2018-07-24 12:46:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
tabs
|
2017-12-11 14:21:06 +00:00
|
|
|
end
|
2018-04-25 14:54:26 +00:00
|
|
|
|
2019-11-08 12:06:32 +00:00
|
|
|
def trials_link_url
|
|
|
|
'https://about.gitlab.com/free-trial/'
|
|
|
|
end
|
|
|
|
|
|
|
|
def trials_allowed?(user)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-04-25 14:54:26 +00:00
|
|
|
def get_current_user_menu_items
|
2018-04-27 12:56:50 +00:00
|
|
|
items = []
|
2018-04-25 14:54:26 +00:00
|
|
|
|
2018-04-27 12:56:50 +00:00
|
|
|
items << :sign_out if current_user
|
|
|
|
|
2018-05-08 13:07:55 +00:00
|
|
|
return items if current_user&.required_terms_not_accepted?
|
2018-04-27 12:56:50 +00:00
|
|
|
|
2018-05-08 13:07:55 +00:00
|
|
|
items << :help
|
|
|
|
items << :profile if can?(current_user, :read_user, current_user)
|
|
|
|
items << :settings if can?(current_user, :update_user, current_user)
|
2019-11-08 12:06:32 +00:00
|
|
|
items << :start_trial if trials_allowed?(current_user)
|
2018-04-25 14:54:26 +00:00
|
|
|
|
|
|
|
items
|
|
|
|
end
|
2017-03-23 08:43:34 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
UsersHelper.prepend_if_ee('EE::UsersHelper')
|