Module: GroupsHelper
- Included in:
- GroupEntity
- Defined in:
- app/helpers/groups_helper.rb
Instance Method Summary collapse
- #access_level_roles_user_can_assign(group, roles) ⇒ Object
- #can_admin_group_member?(group) ⇒ Boolean
- #can_change_group_visibility_level?(group) ⇒ Boolean
- #can_change_prevent_sharing_groups_outside_hierarchy?(group) ⇒ Boolean
- #can_change_share_with_group_lock?(group) ⇒ Boolean
- #can_disable_group_emails?(group) ⇒ Boolean
- #can_invite_group_member?(group) ⇒ Boolean
- #can_set_group_diff_preview_in_email?(group) ⇒ Boolean
- #can_update_default_branch_protection?(group) ⇒ Boolean
- #enabled_git_access_protocol_options_for_group ⇒ Object
- #group_icon_url(group, options = {}) ⇒ Object
- #group_lfs_status(group) ⇒ Object
- #group_merge_requests(group) ⇒ Object
- #group_name_and_path_app_data ⇒ Object
- #group_overview_tabs_app_data(group) ⇒ Object
- #group_readme_app_data(group_readme) ⇒ Object
- #group_settings_readme_app_data(group) ⇒ Object
- #groups_list_with_filtered_search_app_data(endpoint) ⇒ Object
- #groups_projects_more_actions_dropdown_data(source) ⇒ Object
- #link_to_group(group) ⇒ Object
- #new_custom_emoji_path(group) ⇒ Object
- #prevent_sharing_groups_outside_hierarchy_help_text(group) ⇒ Object
- #project_list_sort_by ⇒ Object
- #projects_lfs_status(group) ⇒ Object
- #push_group_breadcrumbs(group) ⇒ Object
- #render_setting_to_allow_project_access_token_creation?(group) ⇒ Boolean
- #share_with_group_lock_help_text(group) ⇒ Object
- #show_group_readme?(group) ⇒ Boolean
- #show_prevent_inviting_groups_outside_hierarchy_setting?(group) ⇒ Boolean
- #show_thanks_for_purchase_alert?(quantity) ⇒ Boolean
- #subgroup_creation_data(group) ⇒ Object
Instance Method Details
#access_level_roles_user_can_assign(group, roles) ⇒ Object
191 192 193 194 195 196 |
# File 'app/helpers/groups_helper.rb', line 191 def access_level_roles_user_can_assign(group, roles) max_access_level = group.max_member_access_for_user(current_user) roles.select do |_name, access_level| access_level <= max_access_level end end |
#can_admin_group_member?(group) ⇒ Boolean
30 31 32 |
# File 'app/helpers/groups_helper.rb', line 30 def can_admin_group_member?(group) Ability.allowed?(current_user, :admin_group_member, group) end |
#can_change_group_visibility_level?(group) ⇒ 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
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
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
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_invite_group_member?(group) ⇒ Boolean
34 35 36 |
# File 'app/helpers/groups_helper.rb', line 34 def can_invite_group_member?(group) Ability.allowed?(current_user, :invite_group_members, group) end |
#can_set_group_diff_preview_in_email?(group) ⇒ Boolean
24 25 26 27 28 |
# File 'app/helpers/groups_helper.rb', line 24 def can_set_group_diff_preview_in_email?(group) return false if group.parent&.show_diff_preview_in_email?.equal?(false) can?(current_user, :set_show_diff_preview_in_email, group) end |
#can_update_default_branch_protection?(group) ⇒ 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_group ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'app/helpers/groups_helper.rb', line 173 def 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
42 43 44 45 46 |
# File 'app/helpers/groups_helper.rb', line 42 def group_icon_url(group, = {}) group = Group.find_by_full_path(group) if group.is_a?(String) group.try(:avatar_url) || ActionController::Base.helpers.image_path('no_group_avatar.png') end |
#group_lfs_status(group) ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/helpers/groups_helper.rb', line 73 def group_lfs_status(group) status = group.lfs_enabled? ? 'enabled' : 'disabled' content_tag(:span, class: "lfs-#{status}") do "#{status.humanize} #{projects_lfs_status(group)}" end end |
#group_merge_requests(group) ⇒ Object
238 239 240 |
# File 'app/helpers/groups_helper.rb', line 238 def group_merge_requests(group) MergeRequestsFinder.new(current_user, group_id: group.id, include_subgroups: true, non_archived: true).execute end |
#group_name_and_path_app_data ⇒ Object
124 125 126 127 128 129 |
# File 'app/helpers/groups_helper.rb', line 124 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
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/groups_helper.rb', line 131 def group_overview_tabs_app_data(group) { group_id: group.id, subgroups_and_projects_endpoint: group_children_path(group, format: :json, archived: false, not_aimed_for_deletion: true), shared_projects_endpoint: group_shared_projects_path(group, format: :json), inactive_projects_endpoint: group_children_path(group, format: :json, active: false), 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), empty_projects_illustration: image_path('illustrations/empty-state/empty-projects-md.svg'), empty_subgroup_illustration: image_path('illustrations/empty-state/empty-projects-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
151 152 153 154 155 156 |
# File 'app/helpers/groups_helper.rb', line 151 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
164 165 166 167 168 169 170 171 |
# File 'app/helpers/groups_helper.rb', line 164 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 |
#groups_list_with_filtered_search_app_data(endpoint) ⇒ Object
231 232 233 234 235 236 |
# File 'app/helpers/groups_helper.rb', line 231 def groups_list_with_filtered_search_app_data(endpoint) { endpoint: endpoint, initial_sort: project_list_sort_by }.to_json end |
#groups_projects_more_actions_dropdown_data(source) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'app/helpers/groups_helper.rb', line 198 def groups_projects_more_actions_dropdown_data(source) model_name = source.model_name.to_s.downcase dropdown_data = { is_group: source.is_a?(Group).to_s, id: source.id } return dropdown_data unless current_user if source.is_a?(Group) dropdown_data[:can_edit] = can?(current_user, :admin_group, source).to_s dropdown_data[:edit_path] = edit_group_path(source) else dropdown_data[:can_edit] = can?(current_user, :admin_project, source).to_s dropdown_data[:edit_path] = edit_project_path(source) end if can?(current_user, :"destroy_#{model_name}_member", source.members.find_by(user_id: current_user.id)) # rubocop: disable CodeReuse/ActiveRecord -- we need to fetch it dropdown_data[:leave_path] = polymorphic_path([:leave, source, :members]) dropdown_data[:leave_confirm_message] = (source) elsif source.requesters.find_by(user_id: current_user.id) # rubocop: disable CodeReuse/ActiveRecord -- we need to fetch it requester = source.requesters.find_by(user_id: current_user.id) # rubocop: disable CodeReuse/ActiveRecord -- we need to fetch it if can?(current_user, :withdraw_member_access_request, requester) dropdown_data[:withdraw_path] = polymorphic_path([:leave, source, :members]) dropdown_data[:withdraw_confirm_message] = (requester) end elsif source.request_access_enabled && can?(current_user, :request_access, source) dropdown_data[:request_access_path] = polymorphic_path([:request_access, source, :members]) end dropdown_data end |
#link_to_group(group) ⇒ Object
95 96 97 |
# File 'app/helpers/groups_helper.rb', line 95 def link_to_group(group) link_to(group.name, group_path(group)) end |
#new_custom_emoji_path(group) ⇒ Object
184 185 186 187 188 189 |
# File 'app/helpers/groups_helper.rb', line 184 def new_custom_emoji_path(group) return unless group return unless can?(current_user, :create_custom_emoji, group) new_group_custom_emoji_path(group) end |
#prevent_sharing_groups_outside_hierarchy_help_text(group) ⇒ Object
99 100 101 |
# File 'app/helpers/groups_helper.rb', line 99 def prevent_sharing_groups_outside_hierarchy_help_text(group) safe_format(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."), group: link_to_group(group)) end |
#project_list_sort_by ⇒ Object
111 112 113 |
# File 'app/helpers/groups_helper.rb', line 111 def project_list_sort_by @group_projects_sort || @sort || params[:sort] || sort_value_recently_created end |
#projects_lfs_status(group) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/groups_helper.rb', line 56 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 |
#push_group_breadcrumbs(group) ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/helpers/groups_helper.rb', line 48 def (group) sorted_ancestors(group).with_route.reverse_each do |parent| (simple_sanitize(parent.name), group_path(parent), parent.try(:avatar_url)) end (simple_sanitize(group.name), group_path(group), group.try(:avatar_url)) end |
#render_setting_to_allow_project_access_token_creation?(group) ⇒ Boolean
103 104 105 |
# File 'app/helpers/groups_helper.rb', line 103 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
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/groups_helper.rb', line 81 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
158 159 160 161 162 |
# File 'app/helpers/groups_helper.rb', line 158 def show_group_readme?(group) return false unless group.group_readme can?(current_user, :read_code, group.readme_project) end |
#show_prevent_inviting_groups_outside_hierarchy_setting?(group) ⇒ Boolean
38 39 40 |
# File 'app/helpers/groups_helper.rb', line 38 def show_prevent_inviting_groups_outside_hierarchy_setting?(group) group.root? end |
#show_thanks_for_purchase_alert?(quantity) ⇒ Boolean
107 108 109 |
# File 'app/helpers/groups_helper.rb', line 107 def show_thanks_for_purchase_alert?(quantity) quantity.to_i > 0 end |
#subgroup_creation_data(group) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'app/helpers/groups_helper.rb', line 115 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 |