2018-07-24 10:00:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 23:28:47 +00:00
|
|
|
class GroupPolicy < BasePolicy
|
2018-12-04 21:38:15 +00:00
|
|
|
include ClusterableActions
|
|
|
|
|
2017-04-06 21:06:42 +00:00
|
|
|
desc "Group is public"
|
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:public_group) { @subject.public? }
|
|
|
|
|
|
|
|
with_score 0
|
|
|
|
condition(:logged_in_viewable) { @user && @subject.internal? && !@user.external? }
|
|
|
|
|
|
|
|
condition(:has_access) { access_level != GroupMember::NO_ACCESS }
|
2016-08-16 23:28:47 +00:00
|
|
|
|
2017-04-06 21:06:42 +00:00
|
|
|
condition(:guest) { access_level >= GroupMember::GUEST }
|
2017-09-13 20:32:58 +00:00
|
|
|
condition(:developer) { access_level >= GroupMember::DEVELOPER }
|
2017-04-06 21:06:42 +00:00
|
|
|
condition(:owner) { access_level >= GroupMember::OWNER }
|
2018-07-11 14:36:08 +00:00
|
|
|
condition(:maintainer) { access_level >= GroupMember::MAINTAINER }
|
2017-04-06 21:06:42 +00:00
|
|
|
condition(:reporter) { access_level >= GroupMember::REPORTER }
|
2016-08-16 23:28:47 +00:00
|
|
|
|
2018-12-18 12:15:51 +00:00
|
|
|
condition(:nested_groups_supported, scope: :global) { Group.supports_nested_objects? }
|
2017-08-09 10:58:00 +00:00
|
|
|
|
2017-09-07 16:42:15 +00:00
|
|
|
condition(:has_parent, scope: :subject) { @subject.has_parent? }
|
2017-09-06 18:31:45 +00:00
|
|
|
condition(:share_with_group_locked, scope: :subject) { @subject.share_with_group_lock? }
|
|
|
|
condition(:parent_share_with_group_locked, scope: :subject) { @subject.parent&.share_with_group_lock? }
|
2017-09-07 16:42:15 +00:00
|
|
|
condition(:can_change_parent_share_with_group_lock) { can?(:change_share_with_group_lock, @subject.parent) }
|
2017-09-02 01:00:46 +00:00
|
|
|
|
2017-04-06 21:06:42 +00:00
|
|
|
condition(:has_projects) do
|
2018-04-23 16:12:26 +00:00
|
|
|
GroupProjectsFinder.new(group: @subject, current_user: @user, options: { include_subgroups: true }).execute.any?
|
2016-08-16 23:28:47 +00:00
|
|
|
end
|
2017-04-06 21:06:42 +00:00
|
|
|
|
2018-12-04 21:38:15 +00:00
|
|
|
condition(:has_clusters, scope: :subject) { clusterable_has_clusters? }
|
|
|
|
condition(:can_have_multiple_clusters) { multiple_clusters_available? }
|
|
|
|
|
2017-04-06 21:06:42 +00:00
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:request_access_enabled) { @subject.request_access_enabled }
|
|
|
|
|
2017-12-06 19:07:47 +00:00
|
|
|
rule { public_group }.policy do
|
|
|
|
enable :read_group
|
|
|
|
enable :read_list
|
|
|
|
enable :read_label
|
|
|
|
end
|
|
|
|
|
2017-04-06 21:06:42 +00:00
|
|
|
rule { logged_in_viewable }.enable :read_group
|
2017-12-06 11:36:11 +00:00
|
|
|
|
|
|
|
rule { guest }.policy do
|
|
|
|
enable :read_group
|
2018-12-18 12:53:46 +00:00
|
|
|
enable :read_list
|
2017-12-06 11:36:11 +00:00
|
|
|
enable :upload_file
|
2017-12-06 19:07:47 +00:00
|
|
|
enable :read_label
|
2017-12-06 11:36:11 +00:00
|
|
|
end
|
|
|
|
|
2018-12-04 21:38:15 +00:00
|
|
|
rule { admin }.enable :read_group
|
2018-04-23 16:12:26 +00:00
|
|
|
|
|
|
|
rule { has_projects }.policy do
|
|
|
|
enable :read_group
|
|
|
|
enable :read_label
|
|
|
|
end
|
2017-04-06 21:06:42 +00:00
|
|
|
|
2017-11-23 14:47:15 +00:00
|
|
|
rule { has_access }.enable :read_namespace
|
|
|
|
|
2018-08-06 19:02:52 +00:00
|
|
|
rule { developer }.enable :admin_milestone
|
2018-02-19 19:06:16 +00:00
|
|
|
|
|
|
|
rule { reporter }.policy do
|
|
|
|
enable :admin_label
|
|
|
|
enable :admin_list
|
|
|
|
enable :admin_issue
|
|
|
|
end
|
2017-04-06 21:06:42 +00:00
|
|
|
|
2018-07-11 14:36:08 +00:00
|
|
|
rule { maintainer }.policy do
|
2017-04-06 21:06:42 +00:00
|
|
|
enable :create_projects
|
2017-05-03 18:51:55 +00:00
|
|
|
enable :admin_pipeline
|
|
|
|
enable :admin_build
|
2018-10-15 00:42:02 +00:00
|
|
|
enable :read_cluster
|
2018-12-04 21:38:15 +00:00
|
|
|
enable :add_cluster
|
2018-10-15 00:42:02 +00:00
|
|
|
enable :create_cluster
|
|
|
|
enable :update_cluster
|
|
|
|
enable :admin_cluster
|
2017-04-06 21:06:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rule { owner }.policy do
|
|
|
|
enable :admin_group
|
|
|
|
enable :admin_namespace
|
|
|
|
enable :admin_group_member
|
|
|
|
enable :change_visibility_level
|
2018-08-22 12:10:54 +00:00
|
|
|
|
|
|
|
enable :set_note_created_at
|
2017-04-06 21:06:42 +00:00
|
|
|
end
|
|
|
|
|
2018-07-03 12:08:46 +00:00
|
|
|
rule { can?(:read_nested_project_resources) }.policy do
|
|
|
|
enable :read_group_activity
|
|
|
|
enable :read_group_issues
|
|
|
|
enable :read_group_boards
|
|
|
|
enable :read_group_labels
|
|
|
|
enable :read_group_milestones
|
|
|
|
enable :read_group_merge_requests
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { can?(:read_cross_project) & can?(:read_group) }.policy do
|
|
|
|
enable :read_nested_project_resources
|
|
|
|
end
|
|
|
|
|
2017-09-07 18:35:45 +00:00
|
|
|
rule { owner & nested_groups_supported }.enable :create_subgroup
|
2017-04-06 21:06:42 +00:00
|
|
|
|
|
|
|
rule { public_group | logged_in_viewable }.enable :view_globally
|
|
|
|
|
|
|
|
rule { default }.enable(:request_access)
|
|
|
|
|
|
|
|
rule { ~request_access_enabled }.prevent :request_access
|
|
|
|
rule { ~can?(:view_globally) }.prevent :request_access
|
|
|
|
rule { has_access }.prevent :request_access
|
|
|
|
|
2017-09-07 16:42:15 +00:00
|
|
|
rule { owner & (~share_with_group_locked | ~has_parent | ~parent_share_with_group_locked | can_change_parent_share_with_group_lock) }.enable :change_share_with_group_lock
|
2017-09-02 01:00:46 +00:00
|
|
|
|
2018-12-04 21:38:15 +00:00
|
|
|
rule { ~can_have_multiple_clusters & has_clusters }.prevent :add_cluster
|
|
|
|
|
2017-04-06 21:06:42 +00:00
|
|
|
def access_level
|
|
|
|
return GroupMember::NO_ACCESS if @user.nil?
|
|
|
|
|
|
|
|
@access_level ||= @subject.max_member_access_for_user(@user)
|
|
|
|
end
|
2016-08-16 23:28:47 +00:00
|
|
|
end
|