2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-12-09 07:15:43 -05:00
|
|
|
class GroupPolicy < Namespaces::GroupProjectNamespaceSharedPolicy
|
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) }
|
2022-05-11 05:08:10 -04:00
|
|
|
condition(:migration_bot, scope: :user) { @user.migration_bot? }
|
2022-06-01 17:08:14 -04:00
|
|
|
condition(:can_read_group_member) { can_read_group_member? }
|
2017-09-01 21:00:46 -04:00
|
|
|
|
2022-01-07 19:14:32 -05:00
|
|
|
desc "User is a project bot"
|
|
|
|
condition(:project_bot) { user.project_bot? && access_level >= GroupMember::GUEST }
|
|
|
|
|
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-11-13 16:09:31 -05:00
|
|
|
condition(:dependency_proxy_available) do
|
|
|
|
@subject.dependency_proxy_feature_available?
|
|
|
|
end
|
|
|
|
|
2021-08-04 05:08:21 -04:00
|
|
|
condition(:dependency_proxy_access_allowed) do
|
2022-05-06 17:08:35 -04:00
|
|
|
access_level(for_any_session: true) >= GroupMember::GUEST || valid_dependency_proxy_deploy_token
|
2021-08-04 05:08:21 -04:00
|
|
|
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
|
2021-03-26 17:09:22 -04:00
|
|
|
condition(:resource_access_token_feature_available) { resource_access_token_feature_available? }
|
|
|
|
condition(:resource_access_token_creation_allowed) { resource_access_token_creation_allowed? }
|
2020-09-30 14:09:52 -04:00
|
|
|
|
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? }
|
|
|
|
|
2022-06-17 08:09:20 -04:00
|
|
|
condition(:crm_enabled, score: 0, scope: :subject) { @subject.crm_enabled? }
|
2021-10-29 11:11:56 -04:00
|
|
|
|
2022-02-23 10:14:44 -05:00
|
|
|
condition(:group_runner_registration_allowed) do
|
2022-05-06 11:09:03 -04:00
|
|
|
Feature.disabled?(:runner_registration_control) || Gitlab::CurrentSettings.valid_runner_registrars.include?('group')
|
2021-12-16 16:14:09 -05:00
|
|
|
end
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
rule { can?(:read_group) & design_management_enabled }.policy do
|
2020-06-19 14:08:39 -04:00
|
|
|
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
|
2021-09-15 08:11:13 -04:00
|
|
|
enable :guest_access
|
2022-02-10 01:17:41 -05:00
|
|
|
enable :read_release
|
2017-12-06 06:36:11 -05:00
|
|
|
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
|
2021-03-02 19:10:50 -05:00
|
|
|
enable :read_issue_board_list
|
2018-04-23 12:12:26 -04:00
|
|
|
enable :read_label
|
2021-03-02 19:10:50 -05:00
|
|
|
enable :read_issue_board
|
2020-09-14 11:09:28 -04:00
|
|
|
enable :read_group_member
|
2020-11-16 16:09:02 -05:00
|
|
|
enable :read_custom_emoji
|
2021-08-24 14:10:53 -04:00
|
|
|
enable :read_counts
|
2018-04-23 12:12:26 -04:00
|
|
|
end
|
2017-04-06 17:06:42 -04:00
|
|
|
|
2021-08-24 14:10:53 -04:00
|
|
|
rule { ~public_group & ~has_access }.prevent :read_counts
|
|
|
|
|
2022-06-01 17:08:14 -04:00
|
|
|
rule { ~can_read_group_member }.policy do
|
|
|
|
prevent :read_group_member
|
|
|
|
end
|
|
|
|
|
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
|
2020-04-07 14:09:19 -04:00
|
|
|
enable :create_metrics_dashboard_annotation
|
|
|
|
enable :delete_metrics_dashboard_annotation
|
|
|
|
enable :update_metrics_dashboard_annotation
|
2020-11-16 16:09:02 -05:00
|
|
|
enable :create_custom_emoji
|
2021-07-26 17:08:38 -04:00
|
|
|
enable :create_package
|
2021-09-15 08:11:13 -04:00
|
|
|
enable :developer_access
|
2021-10-29 11:11:56 -04:00
|
|
|
enable :admin_crm_organization
|
|
|
|
enable :admin_crm_contact
|
2022-01-27 19:14:06 -05:00
|
|
|
enable :read_cluster
|
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
|
2022-07-13 20:08:59 -04:00
|
|
|
enable :read_harbor_registry
|
2021-03-02 19:10:50 -05:00
|
|
|
enable :admin_issue_board
|
2018-02-19 14:06:16 -05:00
|
|
|
enable :admin_label
|
2022-04-29 14:08:18 -04:00
|
|
|
enable :admin_milestone
|
2021-03-02 19:10:50 -05:00
|
|
|
enable :admin_issue_board_list
|
2018-02-19 14:06:16 -05:00
|
|
|
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
|
2022-01-11 07:14:06 -05:00
|
|
|
enable :read_crm_organization
|
|
|
|
enable :read_crm_contact
|
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
|
2021-07-26 17:08:38 -04:00
|
|
|
enable :destroy_package
|
2022-05-11 08:09:03 -04:00
|
|
|
enable :admin_package
|
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-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
|
2021-09-15 08:11:13 -04:00
|
|
|
enable :maintainer_access
|
2022-07-28 11:09:27 -04:00
|
|
|
enable :read_upload
|
|
|
|
enable :destroy_upload
|
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
|
|
|
|
2022-01-10 22:16:07 -05:00
|
|
|
enable :read_group_runners
|
|
|
|
enable :admin_group_runners
|
|
|
|
enable :register_group_runners
|
|
|
|
|
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
|
2022-08-25 20:10:28 -04:00
|
|
|
enable :change_prevent_sharing_groups_outside_hierarchy
|
2022-09-06 14:10:28 -04:00
|
|
|
enable :set_show_diff_preview_in_email
|
2021-07-14 17:09:44 -04:00
|
|
|
enable :change_new_user_signups_cap
|
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
|
2021-10-14 14:13:40 -04:00
|
|
|
enable :update_runners_registration_token
|
2021-09-15 08:11:13 -04:00
|
|
|
enable :owner_access
|
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
|
|
|
|
|
2020-11-27 07:09:14 -05:00
|
|
|
rule { owner | admin }.policy do
|
|
|
|
enable :owner_access
|
|
|
|
enable :read_statistics
|
|
|
|
end
|
2019-08-22 18:08:28 -04:00
|
|
|
|
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
|
2020-11-16 16:09:02 -05:00
|
|
|
enable :read_package
|
2020-09-25 14:09:46 -04:00
|
|
|
enable :read_group
|
|
|
|
end
|
|
|
|
|
2021-08-04 05:08:21 -04:00
|
|
|
rule { dependency_proxy_access_allowed & dependency_proxy_available }
|
2020-11-13 16:09:31 -05:00
|
|
|
.enable :read_dependency_proxy
|
|
|
|
|
2022-05-10 23:07:57 -04:00
|
|
|
rule { maintainer & dependency_proxy_available }.policy do
|
2021-09-13 20:10:45 -04:00
|
|
|
enable :admin_dependency_proxy
|
|
|
|
end
|
2020-11-13 16:09:31 -05:00
|
|
|
|
2022-01-07 19:14:32 -05:00
|
|
|
rule { project_bot }.enable :project_bot_access
|
|
|
|
|
2021-03-26 17:09:22 -04:00
|
|
|
rule { can?(:admin_group) & resource_access_token_feature_available }.policy do
|
|
|
|
enable :read_resource_access_tokens
|
|
|
|
enable :destroy_resource_access_tokens
|
2021-04-05 23:09:02 -04:00
|
|
|
enable :admin_setting_to_allow_project_access_token_creation
|
2021-03-26 17:09:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
rule { resource_access_token_creation_allowed & can?(:read_resource_access_tokens) }.policy do
|
|
|
|
enable :create_resource_access_tokens
|
2020-09-30 14:09:52 -04:00
|
|
|
end
|
|
|
|
|
2022-01-07 19:14:32 -05:00
|
|
|
rule { can?(:project_bot_access) }.policy do
|
|
|
|
prevent :create_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
|
|
|
|
|
2021-10-29 11:11:56 -04:00
|
|
|
rule { ~crm_enabled }.policy do
|
|
|
|
prevent :read_crm_contact
|
|
|
|
prevent :read_crm_organization
|
|
|
|
prevent :admin_crm_contact
|
|
|
|
prevent :admin_crm_organization
|
|
|
|
end
|
|
|
|
|
2022-02-23 10:14:44 -05:00
|
|
|
rule { ~admin & ~group_runner_registration_allowed }.policy do
|
2021-12-16 16:14:09 -05:00
|
|
|
prevent :register_group_runners
|
|
|
|
end
|
|
|
|
|
2022-05-11 05:08:10 -04:00
|
|
|
rule { migration_bot }.policy do
|
|
|
|
enable :read_resource_access_tokens
|
|
|
|
enable :destroy_resource_access_tokens
|
|
|
|
end
|
|
|
|
|
2021-08-11 17:10:33 -04:00
|
|
|
def access_level(for_any_session: false)
|
2017-04-06 17:06:42 -04:00
|
|
|
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
|
|
|
|
2021-08-11 17:10:33 -04:00
|
|
|
@access_level ||= lookup_access_level!(for_any_session: for_any_session)
|
2019-05-06 12:18:03 -04:00
|
|
|
end
|
|
|
|
|
2021-08-11 17:10:33 -04:00
|
|
|
def lookup_access_level!(for_any_session: false)
|
2019-05-06 12:18:03 -04:00
|
|
|
@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
|
|
|
|
|
2021-03-26 17:09:22 -04:00
|
|
|
def resource_access_token_feature_available?
|
2020-09-30 14:09:52 -04:00
|
|
|
true
|
|
|
|
end
|
2021-03-26 17:09:22 -04:00
|
|
|
|
2022-06-01 17:08:14 -04:00
|
|
|
def can_read_group_member?
|
|
|
|
!(@subject.private? && access_level == GroupMember::NO_ACCESS)
|
|
|
|
end
|
|
|
|
|
2021-03-26 17:09:22 -04:00
|
|
|
def resource_access_token_creation_allowed?
|
2021-04-05 23:09:02 -04:00
|
|
|
resource_access_token_feature_available? && group.root_ancestor.namespace_settings.resource_access_token_creation_allowed?
|
2021-03-26 17:09:22 -04:00
|
|
|
end
|
2021-08-04 05:08:21 -04:00
|
|
|
|
|
|
|
def valid_dependency_proxy_deploy_token
|
|
|
|
@user.is_a?(DeployToken) && @user&.valid_for_dependency_proxy? && @user&.has_access_to_group?(@subject)
|
|
|
|
end
|
2016-08-16 19:28:47 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
GroupPolicy.prepend_mod_with('GroupPolicy')
|