2013-01-07 13:48:57 -05:00
module GroupsHelper
2018-02-06 07:17:23 -05:00
def group_nav_link_paths
2018-04-08 06:20:05 -04:00
%w[ groups # projects groups # edit badges # index ci_cd # show ldap_group_links # index hooks # index audit_events # index pipeline_quota # index ]
2018-02-06 07:17:23 -05:00
end
2017-12-11 09:21:06 -05:00
def group_sidebar_links
@group_sidebar_links || = get_group_sidebar_links
end
def group_sidebar_link? ( link )
group_sidebar_links . include? ( link )
end
2016-03-01 10:22:29 -05:00
def can_change_group_visibility_level? ( group )
can? ( current_user , :change_visibility_level , group )
end
2017-09-05 15:43:48 -04:00
def can_change_share_with_group_lock? ( group )
can? ( current_user , :change_share_with_group_lock , group )
end
2018-02-23 07:10:57 -05:00
def group_issues_count ( state : )
IssuesFinder
. new ( current_user , group_id : @group . id , state : state , non_archived : true , include_subgroups : true )
. execute
. count
end
def group_merge_requests_count ( state : )
MergeRequestsFinder
. new ( current_user , group_id : @group . id , state : state , non_archived : true , include_subgroups : true )
. execute
. count
end
2017-10-02 07:35:01 -04:00
def group_icon ( group , options = { } )
img_path = group_icon_url ( group , options )
image_tag img_path , options
end
def group_icon_url ( group , options = { } )
2015-03-12 16:56:53 -04:00
if group . is_a? ( String )
2016-10-31 07:00:53 -04:00
group = Group . find_by_full_path ( group )
2015-03-12 16:56:53 -04:00
end
2017-10-10 04:59:07 -04:00
group . try ( :avatar_url ) || ActionController :: Base . helpers . image_path ( 'no_group_avatar.png' )
2015-03-12 16:56:53 -04:00
end
2015-09-07 07:18:11 -04:00
2015-09-17 06:16:24 -04:00
def group_title ( group , name = nil , url = nil )
2017-02-28 21:59:55 -05:00
@has_group_title = true
2016-12-08 11:28:49 -05:00
full_title = ''
2017-08-16 05:35:59 -04:00
group . ancestors . reverse . each_with_index do | parent , index |
2017-09-06 07:19:03 -04:00
if index > 0
2017-09-12 04:54:01 -04:00
add_to_breadcrumb_dropdown ( group_title_link ( parent , hidable : false , show_avatar : true , for_dropdown : true ) , location : :before )
2017-08-16 08:13:34 -04:00
else
2017-09-06 07:19:03 -04:00
full_title += breadcrumb_list_item group_title_link ( parent , hidable : false )
2017-08-16 08:13:34 -04:00
end
end
2017-09-06 07:19:03 -04:00
full_title += render " layouts/nav/breadcrumbs/collapsed_dropdown " , location : :before , title : _ ( " Show parent subgroups " )
2016-12-08 11:28:49 -05:00
2017-09-06 07:19:03 -04:00
full_title += breadcrumb_list_item group_title_link ( group )
2017-09-06 06:55:23 -04:00
full_title += ' · ' . html_safe + link_to ( simple_sanitize ( name ) , url , class : 'group-path breadcrumb-item-text js-breadcrumb-item-text' ) if name
2015-09-17 06:16:24 -04:00
2017-09-06 07:19:03 -04:00
full_title . html_safe
2015-09-07 07:18:11 -04:00
end
2016-09-01 19:49:48 -04:00
2016-09-06 12:48:00 -04:00
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 16:40:49 -04:00
2016-09-05 14:14:49 -04:00
size = group . projects . size
2016-09-06 12:48:00 -04:00
if lfs_status == size
'for all projects'
2016-09-05 14:14:49 -04:00
else
2016-09-06 12:48:00 -04:00
" for #{ lfs_status } out of #{ pluralize ( size , 'project' ) } "
2016-09-05 14:14:49 -04:00
end
end
def group_lfs_status ( group )
2016-09-05 16:40:49 -04:00
status = group . lfs_enabled? ? 'enabled' : 'disabled'
content_tag ( :span , class : " lfs- #{ status } " ) do
2016-09-06 12:48:00 -04:00
" #{ status . humanize } #{ projects_lfs_status ( group ) } "
2016-09-05 14:14:49 -04:00
end
2016-09-01 19:49:48 -04:00
end
2016-11-05 13:28:29 -04:00
2017-07-04 11:18:51 -04:00
def remove_group_message ( group )
2017-08-14 07:35:28 -04:00
_ ( " You are going to remove %{group_name}. Removed groups CANNOT be restored! Are you ABSOLUTELY sure? " ) %
2017-07-04 11:18:51 -04:00
{ group_name : group . name }
end
2017-09-05 20:02:11 -04: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
2017-09-01 01:58:05 -04:00
end
2018-02-05 19:10:58 -05:00
def parent_group_options ( current_group )
groups = current_user . owned_groups . sort_by ( & :human_name ) . map do | group |
{ id : group . id , text : group . human_name }
end
groups . delete_if { | group | group [ :id ] == current_group . id }
groups . to_json
end
def supports_nested_groups?
Group . supports_nested_groups?
end
2017-06-30 12:52:11 -04:00
private
2017-12-11 09:21:06 -05:00
def get_group_sidebar_links
links = [ :overview , :group_members ]
2018-07-03 08:08:46 -04:00
resources = [ :activity , :issues , :boards , :labels , :milestones ,
:merge_requests ]
links += resources . select do | resource |
can? ( current_user , " read_group_ #{ resource } " . to_sym , @group )
2017-12-11 09:21:06 -05:00
end
if can? ( current_user , :admin_group , @group )
links << :settings
end
links
end
2017-09-12 04:54:01 -04:00
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 12:52:11 -04:00
output =
2017-09-06 07:19:03 -04:00
if ( group . try ( :avatar_url ) || show_avatar ) && ! Rails . env . test?
2017-10-09 04:45:23 -04:00
group_icon ( group , class : " avatar-tile " , width : 15 , height : 15 )
2017-06-30 12:52:11 -04:00
else
" "
end
output << simple_sanitize ( group . name )
output . html_safe
end
end
2017-09-01 01:58:05 -04:00
2017-09-06 02:49:57 -04:00
def ancestor_group ( group )
2017-09-05 20:02:11 -04:00
ancestor = oldest_consecutively_locked_ancestor ( group )
2017-09-06 02:49:57 -04:00
if can? ( current_user , :read_group , ancestor )
link_to ancestor . name , group_path ( ancestor )
else
ancestor . name
end
2017-09-05 20:02:11 -04:00
end
2017-09-06 14:31:45 -04:00
def remove_the_share_with_group_lock_from_ancestor ( group )
2017-09-06 01:11:49 -04:00
ancestor = oldest_consecutively_locked_ancestor ( group )
2017-09-06 14:31:45 -04:00
text = s_ ( " GroupSettings|remove the share with group lock from %{ancestor_group_name} " ) % { ancestor_group_name : ancestor . name }
2017-09-06 02:49:57 -04:00
if can? ( current_user , :admin_group , ancestor )
link_to text , edit_group_path ( ancestor )
else
text
end
2017-09-06 01:11:49 -04:00
end
2017-09-05 20:02:11 -04: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 17:53:32 -04:00
end
2017-09-01 01:58:05 -04:00
def default_help
2017-09-22 06:10:25 -04:00
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. " )
2017-09-01 01:58:05 -04:00
end
2017-09-05 20:02:11 -04:00
def ancestor_locked_but_you_can_override ( group )
2017-09-06 14:31:45 -04:00
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 ) }
2017-09-01 01:58:05 -04:00
end
2017-09-05 20:02:11 -04:00
def ancestor_locked_so_ask_the_owner ( group )
2017-09-06 14:31:45 -04:00
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 ) }
2017-09-01 01:58:05 -04:00
end
2017-09-05 20:02:11 -04:00
def ancestor_locked_and_has_been_overridden ( group )
2017-09-06 05:05:50 -04:00
s_ ( " GroupSettings|This setting is applied on %{ancestor_group} and has been overridden on this subgroup. " ) . html_safe % { ancestor_group : ancestor_group ( group ) }
2017-09-01 01:58:05 -04:00
end
2013-01-07 13:48:57 -05:00
end