Module: AccessTokensHelper

Includes:
AccountsHelper, ApplicationHelper
Defined in:
app/helpers/access_tokens_helper.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#active_when, #add_issuable_stylesheet, #add_page_specific_style, #add_page_startup_api_call, #add_work_items_stylesheet, #admin_section?, #ai_panel_expanded?, #asset_to_string, #autocomplete_data_sources, #bluesky_url, #body_data, #body_data_page, #client_class_list, #client_js_flags, #collapsed_super_sidebar?, community_forum, #community_forum, #conditional_link_to, #current_action?, #current_controller?, #discord_url, #dispensable_render, #dispensable_render_if_exists, #edited_time_ago_with_tooltip, #error_css, #external_storage_url_or_path, #extra_config, #github_url, #gitlab_config, #gitlab_ui_form_for, #gitlab_ui_form_with, #hexdigest, #hidden_resource_icon, #instance_review_permitted?, #last_commit, #linkedin_name, #linkedin_url, #locale_path, #mastodon_url, #orcid_url, #outdated_browser?, #page_class, #page_filter_path, #page_startup_api_calls, #partial_exists?, #path_to_key, #project_data, #project_studio_enabled?, #read_only_message, #registry_config, #render_if_exists, #show_callout?, #show_last_push_widget?, #sign_in_with_redirect?, #simple_sanitize, #static_objects_external_storage_enabled?, #support_url, #system_message_class, #template_exists?, #time_ago_with_tooltip, #twitter_url, #university_url

Methods included from ViteHelper

#universal_path_to_stylesheet, #universal_stylesheet_link_tag, #vite_enabled?, #vite_page_entrypoint_paths

Methods included from AccountsHelper

#incoming_email_token_enabled?

Instance Method Details

#expires_at_field_dataObject



68
69
70
71
72
73
# File 'app/helpers/access_tokens_helper.rb', line 68

def expires_at_field_data
  {
    min_date: 1.day.from_now.iso8601,
    max_date: max_date_allowed
  }
end

#filter_sort_scopes(scopes, sources) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/access_tokens_helper.rb', line 38

def filter_sort_scopes(scopes, sources)
  scopes.select { |scope| ::Gitlab::Auth::UI_SCOPES_ORDERED_BY_PERMISSION.include?(scope) }
  .sort_by { |scope| ::Gitlab::Auth::UI_SCOPES_ORDERED_BY_PERMISSION.index(scope) }
  .map do |value|
    {
      value: value,
      text: t(value, scope: sources)
    }
  end
end

#personal_access_token_data(token, user = current_user) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/access_tokens_helper.rb', line 49

def personal_access_token_data(token, user = current_user)
  sources = scope_description(:personal_access_token)
  scopes = ::Gitlab::Auth.available_scopes_for(user)
  {
    access_token: {
      **expires_at_field_data,
      available_scopes: filter_sort_scopes(scopes, sources).to_json,
      name: token[:name],
      description: token[:description],
      scopes: token[:scopes].to_json,
      create: ,
      granular_new: ,
      revoke: expose_url(api_v4_personal_access_tokens_path),
      rotate: expose_url(api_v4_personal_access_tokens_path),
      show: "#{expose_url(api_v4_personal_access_tokens_path)}?user_id=:id"
    }
  }
end

#scope_description(prefix) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/access_tokens_helper.rb', line 7

def scope_description(prefix)
  case prefix
  when :project_access_token
    [:doorkeeper, :project_access_token_scope_desc]
  when :group_access_token
    [:doorkeeper, :group_access_token_scope_desc]
  else
    [:doorkeeper, :scope_desc]
  end
end

#tokens_app_dataObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/access_tokens_helper.rb', line 18

def tokens_app_data
  {
    feed_token: {
      enabled: !Gitlab::CurrentSettings.disable_feed_token,
      token: current_user.feed_token,
      reset_path: reset_feed_token_profile_path
    },
    incoming_email_token: {
      enabled: incoming_email_token_enabled?,
      token: current_user.enabled_incoming_email_token,
      reset_path: reset_incoming_email_token_profile_path
    },
    static_object_token: {
      enabled: static_objects_external_storage_enabled?,
      token: current_user.enabled_static_object_token,
      reset_path: reset_static_object_token_profile_path
    }
  }.to_json
end