Module: NamespacesHelper

Defined in:
app/helpers/namespaces_helper.rb

Instance Method Summary collapse

Instance Method Details

#cascading_namespace_setting_locked?(attribute, group, **args) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
# File 'app/helpers/namespaces_helper.rb', line 77

def cascading_namespace_setting_locked?(attribute, group, **args)
  return false if group.nil?

  method_name = "#{attribute}_locked?"
  return false unless group.namespace_settings.respond_to?(method_name)

  group.namespace_settings.public_send(method_name, **args) # rubocop:disable GitlabSecurity/PublicSend
end

#cascading_namespace_settings_tooltip_data(attribute, group, settings_path_helper) ⇒ Object



24
25
26
27
28
29
# File 'app/helpers/namespaces_helper.rb', line 24

def cascading_namespace_settings_tooltip_data(attribute, group, settings_path_helper)
  {
    tooltip_data: cascading_namespace_settings_tooltip_raw_data(attribute, group, settings_path_helper).to_json,
    testid: 'cascading-settings-lock-icon'
  }
end

#cascading_namespace_settings_tooltip_raw_data(attribute, group, settings_path_helper) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/namespaces_helper.rb', line 31

def cascading_namespace_settings_tooltip_raw_data(attribute, group, settings_path_helper)
  return {} if group.nil?

  locked_by_ancestor = check_group_lock(group, "#{attribute}_locked_by_ancestor?")
  locked_by_application = check_group_lock(group, "#{attribute}_locked_by_application_setting?")

  tooltip_data = {
    locked_by_application_setting: locked_by_application,
    locked_by_ancestor: locked_by_ancestor
  }

  if locked_by_ancestor
    ancestor_namespace = group.namespace_settings&.public_send("#{attribute}_locked_ancestor")&.namespace # rubocop:disable GitlabSecurity/PublicSend

    if ancestor_namespace
      tooltip_data[:ancestor_namespace] = {
        full_name: ancestor_namespace.full_name,
        path: settings_path_helper.call(ancestor_namespace)
      }
    end
  end

  tooltip_data
end

#check_group_lock(group, method) ⇒ Object



8
9
10
11
12
13
14
# File 'app/helpers/namespaces_helper.rb', line 8

def check_group_lock(group, method)
  if group.namespace_settings.respond_to?(method)
    group.namespace_settings.public_send(method) # rubocop:disable GitlabSecurity/PublicSend
  else
    false
  end
end

#check_project_lock(project, method) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/namespaces_helper.rb', line 16

def check_project_lock(project, method)
  if project.project_setting.respond_to?(method)
    project.project_setting.public_send(method) # rubocop:disable GitlabSecurity/PublicSend
  else
    false
  end
end

#group_usage_quotas_url(group, *args) ⇒ Object



113
114
115
# File 'app/helpers/namespaces_helper.rb', line 113

def group_usage_quotas_url(group, *args)
  Rails.application.routes.url_helpers.group_usage_quotas_url(group.root_ancestor, *args)
end

#import_usage_app_data(namespace) ⇒ Object



104
105
106
107
108
109
110
111
# File 'app/helpers/namespaces_helper.rb', line 104

def import_usage_app_data(namespace)
  placeholder_user_limit = ::Import::PlaceholderUserLimit.new(namespace: namespace)

  {
    placeholder_users_count: placeholder_user_limit.count,
    placeholder_users_limit: placeholder_user_limit.limit
  }
end

#namespace_id_from(params) ⇒ Object



4
5
6
# File 'app/helpers/namespaces_helper.rb', line 4

def namespace_id_from(params)
  params.dig(:project, :namespace_id) || params[:namespace_id]
end

#pipeline_usage_app_data(namespace) ⇒ Object



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

def pipeline_usage_app_data(namespace)
  {
    namespace_actual_plan_name: namespace.actual_plan_name,
    namespace_id: namespace.id,
    user_namespace: namespace.user_namespace?.to_s,
    page_size: page_size
  }
end

#project_cascading_namespace_settings_tooltip_data(attribute, project, settings_path_helper) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/namespaces_helper.rb', line 56

def project_cascading_namespace_settings_tooltip_data(attribute, project, settings_path_helper)
  return unless attribute && project && settings_path_helper

  data = cascading_namespace_settings_tooltip_raw_data(attribute, project.parent, settings_path_helper)
  return data if data[:locked_by_ancestor]

  data[:locked_by_application_setting] = check_project_lock(project, "#{attribute}_locked_by_application_setting?")
  locked_by_ancestor = check_project_lock(project, "#{attribute}_locked_by_ancestor?")
  locked_by_project = check_project_lock(project, "#{attribute}_locked?")

  return data unless locked_by_ancestor || locked_by_project

  data[:locked_by_ancestor] = true
  data[:ancestor_namespace] = {
    full_name: project.parent.name,
    path: Gitlab::UrlBuilder.build(project.parent, only_path: true)
  }

  data
end

#storage_usage_app_data(namespace) ⇒ Object



95
96
97
98
99
100
101
102
# File 'app/helpers/namespaces_helper.rb', line 95

def storage_usage_app_data(namespace)
  {
    namespace_id: namespace.id,
    namespace_path: namespace.full_path,
    user_namespace: namespace.user_namespace?.to_s,
    default_per_page: page_size
  }
end