Module: UsersHelper

Included in:
API::Entities::User, UserStatusTooltip
Defined in:
app/helpers/users_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_user_menu?(item) ⇒ Boolean

Returns:

  • (Boolean)

43
44
45
# File 'app/helpers/users_helper.rb', line 43

def current_user_menu?(item)
  current_user_menu_items.include?(item)
end

#current_user_menu_itemsObject


39
40
41
# File 'app/helpers/users_helper.rb', line 39

def current_user_menu_items
  @current_user_menu_items ||= get_current_user_menu_items
end

#impersonation_enabled?Boolean

Returns:

  • (Boolean)

81
82
83
# File 'app/helpers/users_helper.rb', line 81

def impersonation_enabled?
  Gitlab.config.gitlab.impersonation_enabled
end

#load_max_project_member_accesses(projects) ⇒ Object

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


50
51
52
# File 'app/helpers/users_helper.rb', line 50

def load_max_project_member_accesses(projects)
  current_user&.max_member_access_for_project_ids(projects.pluck(:id))
end

#max_project_member_access(project) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


55
56
57
# File 'app/helpers/users_helper.rb', line 55

def max_project_member_access(project)
  current_user&.max_member_access_for_project(project.id) || Gitlab::Access::NO_ACCESS
end

#max_project_member_access_cache_key(project) ⇒ Object


59
60
61
# File 'app/helpers/users_helper.rb', line 59

def max_project_member_access_cache_key(project)
  "access:#{max_project_member_access(project)}"
end

#profile_tab?(tab) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
# File 'app/helpers/users_helper.rb', line 24

def profile_tab?(tab)
  profile_tabs.include?(tab)
end

#profile_tabsObject


20
21
22
# File 'app/helpers/users_helper.rb', line 20

def profile_tabs
  @profile_tabs ||= get_profile_tabs
end

#user_badges_in_admin_section(user) ⇒ Object


85
86
87
88
89
90
91
92
# File 'app/helpers/users_helper.rb', line 85

def user_badges_in_admin_section(user)
  [].tap do |badges|
    badges << { text: s_('AdminUsers|Blocked'), variant: 'danger' } if user.blocked?
    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

#user_email_help_text(user) ⇒ Object


10
11
12
13
14
15
16
17
18
# File 'app/helpers/users_helper.rb', line 10

def user_email_help_text(user)
  return 'We also use email for avatar detection if no avatar is uploaded' unless user.unconfirmed_email.present?

  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 ') +
    (:strong) { user.unconfirmed_email } + h('.') +
    (:p) { confirmation_link }
end

#user_internal_regex_dataObject


28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/users_helper.rb', line 28

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

4
5
6
7
8
# File 'app/helpers/users_helper.rb', line 4

def user_link(user)
  link_to(user.name, user_path(user),
          title: user.email,
          class: 'has-tooltip commit-committer-link')
end

#user_status(user) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/users_helper.rb', line 63

def user_status(user)
  return unless user

  unless user.association(:status).loaded?
    exception = RuntimeError.new("Status was not preloaded")
    Gitlab::ErrorTracking.track_and_raise_for_dev_exception(exception, user: user.inspect)
  end

  return unless user.status

   :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

#work_information(user) ⇒ Object


94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/helpers/users_helper.rb', line 94

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