Module: ProfilesHelper
- Includes:
- UsersHelper
- Defined in:
- app/helpers/profiles_helper.rb
Instance Method Summary
collapse
#admin_user_actions_data_attributes, #admin_users_data_attributes, #can_force_email_confirmation?, #can_impersonate_user, #confirm_user_data, #current_user_menu?, #current_user_menu_items, #display_public_email?, #email_verification_token_expired?, #has_contact_info?, #impersonation_enabled?, #impersonation_error_text, #impersonation_tokens_enabled?, #load_max_project_member_accesses, #max_project_member_access, #moderation_status, #profile_actions, #user_badges_in_admin_section, #user_clear_status_at, #user_display_name, #user_email_help_text, #user_internal_regex_data, #user_link, #user_profile_actions_data, #user_profile_app_data, #user_status, #work_information
Instance Method Details
#attribute_provider_label(attribute) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'app/helpers/profiles_helper.rb', line 20
def attribute_provider_label(attribute)
user_synced_attributes_metadata = current_user.user_synced_attributes_metadata
if user_synced_attributes_metadata&.synced?(attribute)
if user_synced_attributes_metadata.provider
Gitlab::Auth::OAuth::Provider.label_for(user_synced_attributes_metadata.provider)
else
'LDAP'
end
end
end
|
#commit_email_select_options(user) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/helpers/profiles_helper.rb', line 6
def commit_email_select_options(user)
private_email = user.private_commit_email
verified_emails = user.verified_emails - [private_email]
[
[s_('Use primary email (%{email})') % { email: user.email }, ''],
[
safe_format(s_("Profiles|Use a private email - %{email}"), email: private_email),
Gitlab::PrivateCommitEmail::TOKEN
],
*verified_emails
]
end
|
#delete_account_modal_data ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'app/helpers/profiles_helper.rb', line 105
def delete_account_modal_data
{
action_url: user_registration_path,
confirm_with_password: current_user.confirm_deletion_with_password?.to_s,
username: current_user.username,
delay_user_account_self_deletion: Gitlab::CurrentSettings.delay_user_account_self_deletion.to_s
}
end
|
#email_otp_enrollment_restriction_confirm_data(user) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'app/helpers/profiles_helper.rb', line 184
def email_otp_enrollment_restriction_confirm_data(user)
disabled = !user.can_modify_email_otp_enrollment?
help_text = email_otp_enrollment_restriction_readable_reason(user) if disabled
email_otp_required = user.email_otp_required_as_boolean
{
help_text: help_text,
disabled: disabled.to_s,
email_otp_required: email_otp_required.to_s,
path: user_settings_profile_path
}
end
|
#email_otp_enrollment_restriction_readable_reason(user) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'app/helpers/profiles_helper.rb', line 159
def email_otp_enrollment_restriction_readable_reason(user)
return unless user && !user.can_modify_email_otp_enrollment?
case user.email_otp_enrollment_restriction
when :feature_disabled
s_('ProfilesAuthentication|You cannot modify your enrollment because the feature is disabled.')
when :uses_external_authenticator
s_('ProfilesAuthentication|You cannot modify your enrollment because your account does not use a password to sign in.')
when :global_enforcement
s_('ProfilesAuthentication|You cannot modify your enrollment because the instance requires OTP or WebAuthn two-factor authentication.')
when :admin_2fa_enforcement
s_('ProfilesAuthentication|You cannot modify your enrollment because administrators are required to use OTP or WebAuthn two-factor authentication.')
when :group_enforcement
s_('ProfilesAuthentication|You cannot modify your enrollment because a group you belong to requires OTP or WebAuthn two-factor authentication.')
when :future_enforcement
safe_format(s_("ProfilesAuthentication|You can skip email verification for now. Email verification becomes mandatory on %{date}."), date: l(user.email_otp_required_after.to_date, format: :long))
when :email_otp_required
s_('ProfilesAuthentication|You cannot modify your enrollment because email verification is required at a minimum.')
else
s_('ProfilesAuthentication|You cannot modify your enrollment because of an email OTP enrollment restriction.')
end
end
|
#email_profile_data(user) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'app/helpers/profiles_helper.rb', line 114
def email_profile_data(user)
{
email: user.temp_oauth_email? ? '' : (user.email || ''),
public_email: user.public_email,
commit_email: user.commit_email,
public_email_options: [
{ text: s_('Profiles|Do not show on profile'), value: '' },
*user.public_verified_emails.map { |email| { text: email, value: email } }
].to_json,
commit_email_options: commit_email_select_options(user).map do |option|
if option.is_a?(Array)
{ text: option[0], value: option[1] }
else
{ text: option, value: option }
end
end.to_json,
email_help_text: sanitized_email_help_text(user),
email_resend_confirmation_link: email_resend_confirmation_link(user),
is_email_readonly: user.read_only_attribute?(:email),
email_change_disabled: user.respond_to?(:managing_group) && user.managing_group.present?,
managing_group_name: user.respond_to?(:managing_group) ? user.managing_group&.name : nil,
needs_password_confirmation: needs_password_confirmation?(user).to_s,
password_automatically_set: user.password_automatically_set?.to_s,
allow_password_authentication_for_web: user.allow_password_authentication_for_web?.to_s,
provider_label: attribute_provider_label(:email)
}
end
|
#email_resend_confirmation_link(user) ⇒ Object
63
64
65
66
67
|
# File 'app/helpers/profiles_helper.rb', line 63
def email_resend_confirmation_link(user)
return unless user.unconfirmed_email.present?
Rails.application.routes.url_helpers.user_confirmation_path(user: { email: user.unconfirmed_email })
end
|
#prevent_delete_account? ⇒ Boolean
Overridden in EE::ProfilesHelper#prevent_delete_account?
59
60
61
|
# File 'app/helpers/profiles_helper.rb', line 59
def prevent_delete_account?
false
end
|
#sanitized_email_help_text(user) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'app/helpers/profiles_helper.rb', line 142
def sanitized_email_help_text(user)
help_text = user_email_help_text(user)
return help_text unless help_text&.include?('<a')
doc = Nokogiri::HTML::DocumentFragment.parse(help_text)
doc.css('p').each do |p|
should_remove = p.css('a[href*="user_confirmation"]').any? ||
p.css('a[href*="confirmation"]').any? ||
p.css('a').any? { |link| !link.text.strip.empty? && link['href']&.include?('confirmation') }
p.remove if should_remove
end
sanitize(doc.to_html, tags: %w[strong p], attributes: [])
end
|
#ssh_key_expiration_policy_enabled? ⇒ Boolean
Overridden in EE::ProfilesHelper#ssh_key_expiration_policy_enabled?
54
55
56
|
# File 'app/helpers/profiles_helper.rb', line 54
def ssh_key_expiration_policy_enabled?
false
end
|
Overridden in EE::ProfilesHelper#ssh_key_expiration_tooltip
44
45
46
|
# File 'app/helpers/profiles_helper.rb', line 44
def ssh_key_expiration_tooltip(key)
key.errors.full_messages.join(', ') if key.errors.full_messages.any?
end
|
#ssh_key_expires_field_description ⇒ Object
Overridden in EE::ProfilesHelper#ssh_key_expires_field_description
49
50
51
|
# File 'app/helpers/profiles_helper.rb', line 49
def ssh_key_expires_field_description
s_('Profiles|Optional but recommended. If set, key becomes invalid on the specified date.')
end
|
#ssh_key_usage_types ⇒ Object
35
36
37
38
39
40
41
|
# File 'app/helpers/profiles_helper.rb', line 35
def ssh_key_usage_types
{
s_('SSHKey|Authentication & Signing') => 'auth_and_signing',
s_('SSHKey|Authentication') => 'auth',
s_('SSHKey|Signing') => 'signing'
}
end
|
#user_profile? ⇒ Boolean
31
32
33
|
# File 'app/helpers/profiles_helper.rb', line 31
def user_profile?
params[:controller] == 'users'
end
|
#user_profile_data(user) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'app/helpers/profiles_helper.rb', line 69
def user_profile_data(user)
{
profile_path: user_settings_profile_path,
profile_avatar_path: profile_avatar_path,
avatar_url: avatar_icon_for_user(user, current_user: current_user),
has_avatar: user.avatar?.to_s,
gravatar_enabled: gravatar_enabled?.to_s,
gravatar_link: { hostname: Gitlab.config.gravatar.host, url: "https://#{Gitlab.config.gravatar.host}" }.to_json,
brand_profile_image_guidelines: if current_appearance&.profile_image_guidelines?
brand_profile_image_guidelines
else
''
end,
cropper_css_path: ActionController::Base.helpers.stylesheet_path('lazy_bundles/cropper.css'),
user_path: user_path(current_user),
timezones: timezone_data_with_unique_identifiers.to_json,
user_timezone: user.timezone,
id: user.id,
name: user.name,
pronouns: user.pronouns,
location: user.location,
pronunciation: user.pronunciation,
website_url: user.website_url,
job_title: user.job_title,
organization: user.user_detail_organization,
bio: user.bio,
include_private_contributions: user.include_private_contributions?.to_s,
achievements_enabled: user.achievements_enabled.to_s,
private_profile: user.private_profile?.to_s,
**email_profile_data(user),
**user_status_properties(user)
}
end
|