2016-09-29 09:46:39 +05:30
|
|
|
class GroupPolicy < BasePolicy
|
2017-09-10 17:25:29 +05:30
|
|
|
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-09-29 09:46:39 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
condition(:guest) { access_level >= GroupMember::GUEST }
|
2018-03-17 18:26:18 +05:30
|
|
|
condition(:developer) { access_level >= GroupMember::DEVELOPER }
|
2017-09-10 17:25:29 +05:30
|
|
|
condition(:owner) { access_level >= GroupMember::OWNER }
|
|
|
|
condition(:master) { access_level >= GroupMember::MASTER }
|
|
|
|
condition(:reporter) { access_level >= GroupMember::REPORTER }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
condition(:nested_groups_supported, scope: :global) { Group.supports_nested_groups? }
|
|
|
|
|
|
|
|
condition(:has_parent, scope: :subject) { @subject.has_parent? }
|
|
|
|
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? }
|
|
|
|
condition(:can_change_parent_share_with_group_lock) { can?(:change_share_with_group_lock, @subject.parent) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
condition(:has_projects) do
|
2018-05-09 12:01:36 +05:30
|
|
|
GroupProjectsFinder.new(group: @subject, current_user: @user, options: { include_subgroups: true }).execute.any?
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:request_access_enabled) { @subject.request_access_enabled }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
rule { public_group }.policy do
|
|
|
|
enable :read_group
|
|
|
|
enable :read_list
|
|
|
|
enable :read_label
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
rule { logged_in_viewable }.enable :read_group
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
rule { guest }.policy do
|
|
|
|
enable :read_group
|
|
|
|
enable :upload_file
|
|
|
|
enable :read_label
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
rule { admin } .enable :read_group
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
rule { has_projects }.policy do
|
|
|
|
enable :read_group
|
|
|
|
enable :read_label
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
rule { has_access }.enable :read_namespace
|
|
|
|
|
|
|
|
rule { developer }.enable :admin_milestones
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
rule { reporter }.policy do
|
|
|
|
enable :admin_label
|
|
|
|
enable :admin_list
|
|
|
|
enable :admin_issue
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
rule { master }.policy do
|
|
|
|
enable :create_projects
|
|
|
|
enable :admin_pipeline
|
|
|
|
enable :admin_build
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { owner }.policy do
|
|
|
|
enable :admin_group
|
|
|
|
enable :admin_namespace
|
|
|
|
enable :admin_group_member
|
|
|
|
enable :change_visibility_level
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
rule { owner & nested_groups_supported }.enable :create_subgroup
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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-10 17:25:29 +05:30
|
|
|
def access_level
|
|
|
|
return GroupMember::NO_ACCESS if @user.nil?
|
|
|
|
|
|
|
|
@access_level ||= @subject.max_member_access_for_user(@user)
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|