gitlab-org--gitlab-foss/app/helpers/groups_helper.rb

148 lines
5.1 KiB
Ruby
Raw Normal View History

module GroupsHelper
2016-03-01 15:22:29 +00:00
def can_change_group_visibility_level?(group)
can?(current_user, :change_visibility_level, group)
end
2017-09-05 19:43:48 +00:00
def can_change_share_with_group_lock?(group)
can?(current_user, :change_share_with_group_lock, group)
end
def group_icon(group, options = {})
img_path = group_icon_url(group, options)
image_tag img_path, options
end
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
def group_title(group, name = nil, url = nil)
2017-03-01 02:59:55 +00:00
@has_group_title = true
full_title = ''
group.ancestors.reverse.each_with_index do |parent, index|
2017-09-06 11:19:03 +00:00
if index > 0
add_to_breadcrumb_dropdown(group_title_link(parent, hidable: false, show_avatar: true, for_dropdown: true), location: :before)
else
2017-09-06 11:19:03 +00:00
full_title += breadcrumb_list_item group_title_link(parent, hidable: false)
end
end
2017-09-06 11:19:03 +00:00
full_title += render "layouts/nav/breadcrumbs/collapsed_dropdown", location: :before, title: _("Show parent subgroups")
2017-09-06 11:19:03 +00:00
full_title += breadcrumb_list_item group_title_link(group)
full_title += ' · '.html_safe + link_to(simple_sanitize(name), url, class: 'group-path breadcrumb-item-text js-breadcrumb-item-text') if name
2017-09-06 11:19:03 +00:00
full_title.html_safe
end
def projects_lfs_status(group)
lfs_status =
if group.lfs_enabled?
group.projects.select(&:lfs_enabled?).size
else
group.projects.reject(&:lfs_enabled?).size
end
2016-09-05 20:40:49 +00:00
size = group.projects.size
if lfs_status == size
'for all projects'
else
"for #{lfs_status} out of #{pluralize(size, 'project')}"
end
end
def group_lfs_status(group)
2016-09-05 20:40:49 +00:00
status = group.lfs_enabled? ? 'enabled' : 'disabled'
content_tag(:span, class: "lfs-#{status}") do
"#{status.humanize} #{projects_lfs_status(group)}"
end
end
def group_issues(group)
IssuesFinder.new(current_user, group_id: group.id).execute
end
2017-06-30 16:52:11 +00:00
def remove_group_message(group)
_("You are going to remove %{group_name}. Removed groups CANNOT be restored! Are you ABSOLUTELY sure?") %
{ group_name: group.name }
end
2017-09-06 00:02:11 +00:00
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
2017-06-30 16:52:11 +00:00
private
def group_title_link(group, hidable: false, show_avatar: false, for_dropdown: false)
link_to(group_path(group), class: "group-path #{'breadcrumb-item-text' unless for_dropdown} js-breadcrumb-item-text #{'hidable' if hidable}") do
2017-06-30 16:52:11 +00:00
output =
2017-09-06 11:19:03 +00:00
if (group.try(:avatar_url) || show_avatar) && !Rails.env.test?
2017-10-09 08:45:23 +00:00
group_icon(group, class: "avatar-tile", width: 15, height: 15)
2017-06-30 16:52:11 +00:00
else
""
end
output << simple_sanitize(group.name)
output.html_safe
end
end
def ancestor_group(group)
2017-09-06 00:02:11 +00:00
ancestor = oldest_consecutively_locked_ancestor(group)
if can?(current_user, :read_group, ancestor)
link_to ancestor.name, group_path(ancestor)
else
ancestor.name
end
2017-09-06 00:02:11 +00:00
end
def remove_the_share_with_group_lock_from_ancestor(group)
2017-09-06 05:11:49 +00:00
ancestor = oldest_consecutively_locked_ancestor(group)
text = s_("GroupSettings|remove the share with group lock from %{ancestor_group_name}") % { ancestor_group_name: ancestor.name }
if can?(current_user, :admin_group, ancestor)
link_to text, edit_group_path(ancestor)
else
text
end
2017-09-06 05:11:49 +00:00
end
2017-09-06 00:02:11 +00:00
def oldest_consecutively_locked_ancestor(group)
group.ancestors.find do |group|
!group.has_parent? || !group.parent.share_with_group_lock?
end
2017-09-05 21:53:32 +00:00
end
def default_help
s_("GroupSettings|This setting will be applied to all subgroups unless overridden by a group owner. Groups that already have access to the project will continue to have access unless removed manually.")
end
2017-09-06 00:02:11 +00:00
def ancestor_locked_but_you_can_override(group)
s_("GroupSettings|This setting is applied on %{ancestor_group}. You can override the setting or %{remove_ancestor_share_with_group_lock}.").html_safe % { ancestor_group: ancestor_group(group), remove_ancestor_share_with_group_lock: remove_the_share_with_group_lock_from_ancestor(group) }
end
2017-09-06 00:02:11 +00:00
def ancestor_locked_so_ask_the_owner(group)
s_("GroupSettings|This setting is applied on %{ancestor_group}. To share projects in this group with another group, ask the owner to override the setting or %{remove_ancestor_share_with_group_lock}.").html_safe % { ancestor_group: ancestor_group(group), remove_ancestor_share_with_group_lock: remove_the_share_with_group_lock_from_ancestor(group) }
end
2017-09-06 00:02:11 +00:00
def ancestor_locked_and_has_been_overridden(group)
2017-09-06 09:05:50 +00:00
s_("GroupSettings|This setting is applied on %{ancestor_group} and has been overridden on this subgroup.").html_safe % { ancestor_group: ancestor_group(group) }
end
end