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_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

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


28
29
30
31
32
33
34
# File 'app/helpers/groups_helper.rb', line 28

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


80
81
82
83
84
85
86
# File 'app/helpers/groups_helper.rb', line 80

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_title(group, name = nil, url = nil) ⇒ Object


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

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

107
108
109
# File 'app/helpers/groups_helper.rb', line 107

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

#parent_group_options(current_group) ⇒ Object


115
116
117
118
119
120
121
122
123
# File 'app/helpers/groups_helper.rb', line 115

def parent_group_options(current_group)
  exclude_groups = current_group.self_and_descendants.pluck_primary_key
  exclude_groups << current_group.parent_id if current_group.parent_id
  groups = GroupsFinder.new(current_user, min_access_level: Gitlab::Access::OWNER, exclude_group_ids: exclude_groups).execute.sort_by(&:human_name).map do |group|
    { id: group.id, text: group.human_name }
  end

  groups.to_json
end

#prevent_sharing_groups_outside_hierarchy_help_text(group) ⇒ Object


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

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


133
134
135
# File 'app/helpers/groups_helper.rb', line 133

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

#projects_lfs_status(group) ⇒ Object


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

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


88
89
90
91
# File 'app/helpers/groups_helper.rb', line 88

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)

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

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

#require_verification_for_namespace_creation_enabled?Boolean

Returns:

  • (Boolean)

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

def require_verification_for_namespace_creation_enabled?
  # overridden in EE
  false
end

#share_with_group_lock_help_text(group) ⇒ Object


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

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_thanks_for_purchase_banner?Boolean

Returns:

  • (Boolean)

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

def show_thanks_for_purchase_banner?
  params.key?(:purchased_quantity) && params[:purchased_quantity].to_i > 0
end

#verification_for_group_creation_dataObject


137
138
139
140
# File 'app/helpers/groups_helper.rb', line 137

def verification_for_group_creation_data
  # overridden in EE
  {}
end