2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 19:28:47 -04:00
|
|
|
class GroupPolicy < BasePolicy
|
2019-09-04 12:33:02 -04:00
|
|
|
include FindGroupProjects
|
|
|
|
|
2017-04-06 17:06:42 -04: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 19:28:47 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:guest) { access_level >= GroupMember::GUEST }
|
2017-09-13 16:32:58 -04:00
|
|
|
condition(:developer) { access_level >= GroupMember::DEVELOPER }
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:owner) { access_level >= GroupMember::OWNER }
|
2018-07-11 10:36:08 -04:00
|
|
|
condition(:maintainer) { access_level >= GroupMember::MAINTAINER }
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:reporter) { access_level >= GroupMember::REPORTER }
|
2016-08-16 19:28:47 -04:00
|
|
|
|
2017-09-07 12:42:15 -04:00
|
|
|
condition(:has_parent, scope: :subject) { @subject.has_parent? }
|
2017-09-06 14:31:45 -04: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 12:42:15 -04:00
|
|
|
condition(:can_change_parent_share_with_group_lock) { can?(:change_share_with_group_lock, @subject.parent) }
|
2017-09-01 21:00:46 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:has_projects) do
|
2019-09-04 12:33:02 -04:00
|
|
|
group_projects_for(user: @user, group: @subject).any?
|
2016-08-16 19:28:47 -04:00
|
|
|
end
|
2017-04-06 17:06:42 -04:00
|
|
|
|
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:request_access_enabled) { @subject.request_access_enabled }
|
|
|
|
|
2019-04-05 14:49:46 -04:00
|
|
|
condition(:create_projects_disabled) do
|
|
|
|
@subject.project_creation_level == ::Gitlab::Access::NO_ONE_PROJECT_ACCESS
|
|
|
|
end
|
|
|
|
|
|
|
|
condition(:developer_maintainer_access) do
|
|
|
|
@subject.project_creation_level == ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS
|
|
|
|
end
|
|
|
|
|
2019-06-27 18:53:46 -04:00
|
|
|
condition(:maintainer_can_create_group) do
|
|
|
|
@subject.subgroup_creation_level == ::Gitlab::Access::MAINTAINER_SUBGROUP_ACCESS
|
|
|
|
end
|
|
|
|
|
2020-06-19 14:08:39 -04:00
|
|
|
condition(:design_management_enabled) do
|
|
|
|
group_projects_for(user: @user, group: @subject, only_owned: false).any? { |p| p.design_management_enabled? }
|
|
|
|
end
|
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
desc "Deploy token with read_package_registry scope"
|
|
|
|
condition(:read_package_registry_deploy_token) do
|
|
|
|
@user.is_a?(DeployToken) && @user.groups.include?(@subject) && @user.read_package_registry
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Deploy token with write_package_registry scope"
|
|
|
|
condition(:write_package_registry_deploy_token) do
|
|
|
|
@user.is_a?(DeployToken) && @user.groups.include?(@subject) && @user.write_package_registry
|
|
|
|
end
|
|
|
|
|
2020-09-30 14:09:52 -04:00
|
|
|
with_scope :subject
|
|
|
|
condition(:resource_access_token_available) { resource_access_token_available? }
|
|
|
|
|
2020-11-10 10:09:14 -05:00
|
|
|
with_scope :subject
|
|
|
|
condition(:has_project_with_service_desk_enabled) { @subject.has_project_with_service_desk_enabled? }
|
|
|
|
|
2020-06-19 14:08:39 -04:00
|
|
|
rule { design_management_enabled }.policy do
|
|
|
|
enable :read_design_activity
|
|
|
|
end
|
|
|
|
|
2017-12-06 14:07:47 -05:00
|
|
|
rule { public_group }.policy do
|
|
|
|
enable :read_group
|
2019-11-07 10:06:33 -05:00
|
|
|
enable :read_package
|
2017-12-06 14:07:47 -05:00
|
|
|
end
|
|
|
|
|
2020-05-06 11:09:42 -04:00
|
|
|
rule { logged_in_viewable }.enable :read_group
|
2017-12-06 06:36:11 -05:00
|
|
|
|
|
|
|
rule { guest }.policy do
|
|
|
|
enable :read_group
|
|
|
|
enable :upload_file
|
|
|
|
end
|
|
|
|
|
2019-10-14 11:06:07 -04:00
|
|
|
rule { admin }.policy do
|
|
|
|
enable :read_group
|
|
|
|
enable :update_max_artifacts_size
|
|
|
|
end
|
2018-04-23 12:12:26 -04:00
|
|
|
|
2020-06-29 08:09:20 -04:00
|
|
|
rule { can?(:read_all_resources) }.policy do
|
|
|
|
enable :read_confidential_issues
|
|
|
|
end
|
|
|
|
|
2018-04-23 12:12:26 -04:00
|
|
|
rule { has_projects }.policy do
|
2019-10-01 17:06:09 -04:00
|
|
|
enable :read_group
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { can?(:read_group) }.policy do
|
|
|
|
enable :read_milestone
|
2019-02-25 08:36:28 -05:00
|
|
|
enable :read_list
|
2018-04-23 12:12:26 -04:00
|
|
|
enable :read_label
|
2020-02-10 22:09:13 -05:00
|
|
|
enable :read_board
|
2020-09-14 11:09:28 -04:00
|
|
|
enable :read_group_member
|
2018-04-23 12:12:26 -04:00
|
|
|
end
|
2017-04-06 17:06:42 -04:00
|
|
|
|
2020-06-19 14:08:39 -04:00
|
|
|
rule { ~can?(:read_group) }.policy do
|
|
|
|
prevent :read_design_activity
|
|
|
|
end
|
|
|
|
|
2017-11-23 09:47:15 -05:00
|
|
|
rule { has_access }.enable :read_namespace
|
|
|
|
|
2019-11-07 10:06:33 -05:00
|
|
|
rule { developer }.policy do
|
|
|
|
enable :admin_milestone
|
2020-04-07 14:09:19 -04:00
|
|
|
enable :create_metrics_dashboard_annotation
|
|
|
|
enable :delete_metrics_dashboard_annotation
|
|
|
|
enable :update_metrics_dashboard_annotation
|
2019-11-07 10:06:33 -05:00
|
|
|
end
|
2018-02-19 14:06:16 -05:00
|
|
|
|
|
|
|
rule { reporter }.policy do
|
2020-04-21 11:21:10 -04:00
|
|
|
enable :reporter_access
|
2019-08-05 16:00:50 -04:00
|
|
|
enable :read_container_image
|
2018-02-19 14:06:16 -05:00
|
|
|
enable :admin_label
|
|
|
|
enable :admin_list
|
|
|
|
enable :admin_issue
|
2020-04-07 14:09:19 -04:00
|
|
|
enable :read_metrics_dashboard_annotation
|
2020-07-07 02:09:06 -04:00
|
|
|
enable :read_prometheus
|
2020-09-25 14:09:46 -04:00
|
|
|
enable :read_package
|
2018-02-19 14:06:16 -05:00
|
|
|
end
|
2017-04-06 17:06:42 -04:00
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
rule { maintainer }.policy do
|
2017-04-06 17:06:42 -04:00
|
|
|
enable :create_projects
|
2017-05-03 14:51:55 -04:00
|
|
|
enable :admin_pipeline
|
|
|
|
enable :admin_build
|
2018-10-14 20:42:02 -04:00
|
|
|
enable :read_cluster
|
2018-12-04 16:38:15 -05:00
|
|
|
enable :add_cluster
|
2018-10-14 20:42:02 -04:00
|
|
|
enable :create_cluster
|
|
|
|
enable :update_cluster
|
|
|
|
enable :admin_cluster
|
2020-03-11 02:10:11 -04:00
|
|
|
enable :read_deploy_token
|
2020-09-01 08:11:01 -04:00
|
|
|
enable :create_jira_connect_subscription
|
2017-04-06 17:06:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
rule { owner }.policy do
|
|
|
|
enable :admin_group
|
|
|
|
enable :admin_namespace
|
|
|
|
enable :admin_group_member
|
|
|
|
enable :change_visibility_level
|
2018-08-22 08:10:54 -04:00
|
|
|
|
|
|
|
enable :set_note_created_at
|
2019-08-15 13:37:36 -04:00
|
|
|
enable :set_emails_disabled
|
2020-04-24 05:09:44 -04:00
|
|
|
enable :update_default_branch_protection
|
2020-07-01 17:08:51 -04:00
|
|
|
enable :create_deploy_token
|
|
|
|
enable :destroy_deploy_token
|
2017-04-06 17:06:42 -04:00
|
|
|
end
|
|
|
|
|
2018-07-03 08:08:46 -04: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
|
2020-08-06 17:10:15 -04:00
|
|
|
enable :read_group_build_report_results
|
2018-07-03 08:08:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
rule { can?(:read_cross_project) & can?(:read_group) }.policy do
|
|
|
|
enable :read_nested_project_resources
|
|
|
|
end
|
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
rule { owner }.enable :create_subgroup
|
|
|
|
rule { maintainer & maintainer_can_create_group }.enable :create_subgroup
|
2017-04-06 17:06:42 -04: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 12:42:15 -04: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-01 21:00:46 -04:00
|
|
|
|
2019-04-05 14:49:46 -04:00
|
|
|
rule { developer & developer_maintainer_access }.enable :create_projects
|
|
|
|
rule { create_projects_disabled }.prevent :create_projects
|
|
|
|
|
2019-08-22 18:08:28 -04:00
|
|
|
rule { owner | admin }.enable :read_statistics
|
|
|
|
|
2019-09-23 03:42:26 -04:00
|
|
|
rule { maintainer & can?(:create_projects) }.enable :transfer_projects
|
|
|
|
|
2020-09-25 14:09:46 -04:00
|
|
|
rule { read_package_registry_deploy_token }.policy do
|
|
|
|
enable :read_package
|
|
|
|
enable :read_group
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { write_package_registry_deploy_token }.policy do
|
|
|
|
enable :create_package
|
|
|
|
enable :read_group
|
|
|
|
end
|
|
|
|
|
2020-09-30 14:09:52 -04:00
|
|
|
rule { resource_access_token_available & can?(:admin_group) }.policy do
|
|
|
|
enable :admin_resource_access_tokens
|
|
|
|
end
|
|
|
|
|
2020-11-10 10:09:14 -05:00
|
|
|
rule { support_bot & has_project_with_service_desk_enabled }.policy do
|
|
|
|
enable :read_label
|
|
|
|
end
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
def access_level
|
|
|
|
return GroupMember::NO_ACCESS if @user.nil?
|
2020-08-18 14:10:10 -04:00
|
|
|
return GroupMember::NO_ACCESS unless user_is_user?
|
2017-04-06 17:06:42 -04:00
|
|
|
|
2019-05-06 12:18:03 -04:00
|
|
|
@access_level ||= lookup_access_level!
|
|
|
|
end
|
|
|
|
|
|
|
|
def lookup_access_level!
|
|
|
|
@subject.max_member_access_for_user(@user)
|
2017-04-06 17:06:42 -04:00
|
|
|
end
|
2020-08-18 14:10:10 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user_is_user?
|
|
|
|
user.is_a?(User)
|
|
|
|
end
|
2020-09-30 14:09:52 -04:00
|
|
|
|
|
|
|
def group
|
|
|
|
@subject
|
|
|
|
end
|
|
|
|
|
|
|
|
def resource_access_token_available?
|
|
|
|
true
|
|
|
|
end
|
2016-08-16 19:28:47 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
GroupPolicy.prepend_if_ee('EE::GroupPolicy')
|