Module: GroupsHelper

Included in:
GroupEntity, Groups::SettingsHelper
Defined in:
app/helpers/groups_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_admin_group_member?(group) ⇒ Boolean

Returns:

  • (Boolean)


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

def can_admin_group_member?(group)
  Ability.allowed?(current_user, :admin_group_member, group)
end

#can_admin_service_accounts?(group) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/helpers/groups_helper.rb', line 28

def can_admin_service_accounts?(group)
  false
end

#can_change_group_visibility_level?(group) ⇒ Boolean

Returns:

  • (Boolean)


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

def can_change_group_visibility_level?(group)
  can?(current_user, :change_visibility_level, group)
end

#can_change_prevent_sharing_groups_outside_hierarchy?(group) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/helpers/groups_helper.rb', line 16

def can_change_prevent_sharing_groups_outside_hierarchy?(group)
  can?(current_user, :change_prevent_sharing_groups_outside_hierarchy, group)
end

#can_change_share_with_group_lock?(group) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/helpers/groups_helper.rb', line 12

def can_change_share_with_group_lock?(group)
  can?(current_user, :change_share_with_group_lock, group)
end

#can_disable_group_emails?(group) ⇒ Boolean

Returns:

  • (Boolean)


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

def can_disable_group_emails?(group)
  can?(current_user, :set_emails_disabled, group) && !group.parent&.emails_disabled?
end

#can_update_default_branch_protection?(group) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/helpers/groups_helper.rb', line 8

def can_update_default_branch_protection?(group)
  can?(current_user, :update_default_branch_protection, group)
end

#enabled_git_access_protocol_options_for_groupObject



189
190
191
192
193
194
195
196
197
198
# File 'app/helpers/groups_helper.rb', line 189

def enabled_git_access_protocol_options_for_group
  case ::Gitlab::CurrentSettings.enabled_git_access_protocol
  when nil, ""
    [[_("Both SSH and HTTP(S)"), "all"], [_("Only SSH"), "ssh"], [_("Only HTTP(S)"), "http"]]
  when "ssh"
    [[_("Only SSH"), "ssh"]]
  when "http"
    [[_("Only HTTP(S)"), "http"]]
  end
end

#group_icon_url(group, options = {}) ⇒ Object



32
33
34
35
36
37
38
# File 'app/helpers/groups_helper.rb', line 32

def group_icon_url(group, options = {})
  if group.is_a?(String)
    group = Group.find_by_full_path(group)
  end

  group.try(:avatar_url) || ActionController::Base.helpers.image_path('no_group_avatar.png')
end

#group_lfs_status(group) ⇒ Object



84
85
86
87
88
89
90
# File 'app/helpers/groups_helper.rb', line 84

def group_lfs_status(group)
  status = group.lfs_enabled? ? 'enabled' : 'disabled'

  (:span, class: "lfs-#{status}") do
    "#{status.humanize} #{projects_lfs_status(group)}"
  end
end

#group_name_and_path_app_dataObject



141
142
143
144
145
146
# File 'app/helpers/groups_helper.rb', line 141

def group_name_and_path_app_data
  {
    base_path: root_url,
    mattermost_enabled: Gitlab.config.mattermost.enabled.to_s
  }
end

#group_overview_tabs_app_data(group) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'app/helpers/groups_helper.rb', line 148

def group_overview_tabs_app_data(group)
  {
    group_id: group.id,
    subgroups_and_projects_endpoint: group_children_path(group, format: :json),
    shared_projects_endpoint: group_shared_projects_path(group, format: :json),
    archived_projects_endpoint: group_children_path(group, format: :json, archived: 'only'),
    current_group_visibility: group.visibility,
    initial_sort: project_list_sort_by,
    show_schema_markup: 'true',
    new_subgroup_path: new_group_path(parent_id: group.id, anchor: 'create-group-pane'),
    new_project_path: new_project_path(namespace_id: group.id),
    new_subgroup_illustration: image_path('illustrations/subgroup-create-new-sm.svg'),
    new_project_illustration: image_path('illustrations/project-create-new-sm.svg'),
    empty_projects_illustration: image_path('illustrations/empty-state/empty-projects-md.svg'),
    empty_subgroup_illustration: image_path('illustrations/empty-state/empty-subgroup-md.svg'),
    render_empty_state: 'true',
    can_create_subgroups: can?(current_user, :create_subgroup, group).to_s,
    can_create_projects: can?(current_user, :create_projects, group).to_s
  }
end

#group_readme_app_data(group_readme) ⇒ Object



169
170
171
172
173
174
# File 'app/helpers/groups_helper.rb', line 169

def group_readme_app_data(group_readme)
  {
    web_path: group_readme.present.web_path,
    name: group_readme.present.name
  }
end

#group_settings_readme_app_data(group) ⇒ Object



180
181
182
183
184
185
186
187
# File 'app/helpers/groups_helper.rb', line 180

def group_settings_readme_app_data(group)
  {
    group_readme_path: group.group_readme&.present&.web_path,
    readme_project_path: group.readme_project&.present&.path_with_namespace,
    group_path: group.full_path,
    group_id: group.id
  }
end

#group_title(group, name = nil, url = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/groups_helper.rb', line 40

def group_title(group, name = nil, url = nil)
  @has_group_title = true
  full_title = []

  sorted_ancestors(group).with_route.reverse_each.with_index do |parent, index|
    if index > 0
      add_to_breadcrumb_collapsed_links(group_title_link(parent), location: :before)
    else
      full_title << breadcrumb_list_item(group_title_link(parent, hidable: false))
    end

    push_to_schema_breadcrumb(simple_sanitize(parent.name), group_path(parent))
  end

  full_title << render("layouts/nav/breadcrumbs/collapsed_inline_list", location: :before, title: _("Show all breadcrumbs"))

  full_title << breadcrumb_list_item(group_title_link(group))
  push_to_schema_breadcrumb(simple_sanitize(group.name), group_path(group))

  if name
    full_title << ' &middot; '.html_safe + link_to(simple_sanitize(name), url, class: 'group-path breadcrumb-item-text js-breadcrumb-item-text')
    push_to_schema_breadcrumb(simple_sanitize(name), url)
  end

  full_title.join.html_safe
end


112
113
114
# File 'app/helpers/groups_helper.rb', line 112

def link_to_group(group)
  link_to(group.name, group_path(group))
end

#prevent_sharing_groups_outside_hierarchy_help_text(group) ⇒ Object



116
117
118
# File 'app/helpers/groups_helper.rb', line 116

def prevent_sharing_groups_outside_hierarchy_help_text(group)
  s_("GroupSettings|Available only on the top-level group. Applies to all subgroups. Groups already shared with a group outside %{group} are still shared unless removed manually.").html_safe % { group: link_to_group(group) }
end

#project_list_sort_byObject



128
129
130
# File 'app/helpers/groups_helper.rb', line 128

def project_list_sort_by
  @group_projects_sort || @sort || params[:sort] || sort_value_recently_created
end

#projects_lfs_status(group) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/groups_helper.rb', line 67

def projects_lfs_status(group)
  lfs_status =
    if group.lfs_enabled?
      group.projects.count(&:lfs_enabled?)
    else
      group.projects.count { |project| !project.lfs_enabled? }
    end

  size = group.projects.size

  if lfs_status == size
    'for all projects'
  else
    "for #{lfs_status} out of #{pluralize(size, 'project')}"
  end
end

#remove_group_message(group) ⇒ Object

Overridden in EE



93
94
95
96
# File 'app/helpers/groups_helper.rb', line 93

def remove_group_message(group)
  _("You are going to remove %{group_name}. This will also delete all of its subgroups and projects. Removed groups CANNOT be restored! Are you ABSOLUTELY sure?") %
    { group_name: group.name }
end

#render_setting_to_allow_project_access_token_creation?(group) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
# File 'app/helpers/groups_helper.rb', line 120

def render_setting_to_allow_project_access_token_creation?(group)
  group.root? && current_user.can?(:admin_setting_to_allow_resource_access_token_creation, group)
end

#share_with_group_lock_help_text(group) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/helpers/groups_helper.rb', line 98

def share_with_group_lock_help_text(group)
  return default_help unless group.parent&.share_with_group_lock?

  if group.share_with_group_lock?
    if can?(current_user, :change_share_with_group_lock, group.parent)
      ancestor_locked_but_you_can_override(group)
    else
      ancestor_locked_so_ask_the_owner(group)
    end
  else
    ancestor_locked_and_has_been_overridden(group)
  end
end

#show_group_readme?(group) ⇒ Boolean

Returns:

  • (Boolean)


176
177
178
# File 'app/helpers/groups_helper.rb', line 176

def show_group_readme?(group)
  group.group_readme
end

#show_thanks_for_purchase_alert?(quantity) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
# File 'app/helpers/groups_helper.rb', line 124

def show_thanks_for_purchase_alert?(quantity)
  quantity.to_i > 0
end

#subgroup_creation_data(group) ⇒ Object



132
133
134
135
136
137
138
139
# File 'app/helpers/groups_helper.rb', line 132

def subgroup_creation_data(group)
  {
    parent_group_url: group.parent && group_url(group.parent),
    parent_group_name: group.parent&.name,
    import_existing_group_path: new_group_path(parent_id: group.parent_id, anchor: 'import-group-pane'),
    is_saas: Gitlab.com?.to_s
  }
end