2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
class BasePolicy < DeclarativePolicy::Base
|
|
|
|
desc "User is an instance admin"
|
|
|
|
with_options scope: :user, score: 0
|
2019-09-26 08:06:00 -04:00
|
|
|
condition(:admin) do
|
2021-03-17 20:08:58 -04:00
|
|
|
if Gitlab::CurrentSettings.admin_mode
|
2019-09-26 08:06:00 -04:00
|
|
|
Gitlab::Auth::CurrentUserMode.new(@user).admin_mode?
|
|
|
|
else
|
|
|
|
@user&.admin?
|
|
|
|
end
|
|
|
|
end
|
2016-08-11 18:12:52 -04:00
|
|
|
|
2019-04-11 11:21:18 -04:00
|
|
|
desc "User is blocked"
|
|
|
|
with_options scope: :user, score: 0
|
|
|
|
condition(:blocked) { @user&.blocked? }
|
|
|
|
|
2019-10-09 20:06:44 -04:00
|
|
|
desc "User is deactivated"
|
|
|
|
with_options scope: :user, score: 0
|
|
|
|
condition(:deactivated) { @user&.deactivated? }
|
|
|
|
|
2020-06-22 11:09:27 -04:00
|
|
|
desc "User is support bot"
|
|
|
|
with_options scope: :user, score: 0
|
|
|
|
condition(:support_bot) { @user&.support_bot? }
|
|
|
|
|
2020-12-11 13:09:57 -05:00
|
|
|
desc "User is security bot"
|
|
|
|
with_options scope: :user, score: 0
|
|
|
|
condition(:security_bot) { @user&.security_bot? }
|
|
|
|
|
2021-06-16 08:10:18 -04:00
|
|
|
desc "User is automation bot"
|
|
|
|
with_options scope: :user, score: 0
|
|
|
|
condition(:automation_bot) { @user&.automation_bot? }
|
|
|
|
|
2020-01-30 16:08:47 -05:00
|
|
|
desc "User email is unconfirmed or user account is locked"
|
|
|
|
with_options scope: :user, score: 0
|
2020-09-24 14:09:51 -04:00
|
|
|
condition(:inactive) { @user&.confirmation_required_on_sign_in? || @user&.access_locked? }
|
2020-01-30 16:08:47 -05:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
with_options scope: :user, score: 0
|
|
|
|
condition(:external_user) { @user.nil? || @user.external? }
|
2016-08-12 14:36:16 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
with_options scope: :user, score: 0
|
|
|
|
condition(:can_create_group) { @user&.can_create_group }
|
2017-06-29 03:43:41 -04:00
|
|
|
|
2017-06-30 09:29:34 -04:00
|
|
|
desc "The application is restricted from public visibility"
|
|
|
|
condition(:restricted_public_level, scope: :global) do
|
2017-08-31 05:47:03 -04:00
|
|
|
Gitlab::CurrentSettings.current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC)
|
2017-06-29 03:43:41 -04:00
|
|
|
end
|
2017-12-11 09:21:06 -05:00
|
|
|
|
2019-04-09 11:38:58 -04:00
|
|
|
condition(:external_authorization_enabled, scope: :global, score: 0) do
|
|
|
|
::Gitlab::ExternalAuthorization.perform_check?
|
|
|
|
end
|
|
|
|
|
2020-02-06 07:10:29 -05:00
|
|
|
with_options scope: :user, score: 0
|
|
|
|
condition(:alert_bot) { @user&.alert_bot? }
|
|
|
|
|
2019-11-06 13:06:29 -05:00
|
|
|
rule { external_authorization_enabled & ~can?(:read_all_resources) }.policy do
|
2019-04-09 11:38:58 -04:00
|
|
|
prevent :read_cross_project
|
|
|
|
end
|
|
|
|
|
2021-03-09 13:09:41 -05:00
|
|
|
rule { admin }.policy do
|
|
|
|
# Only for actual administrator accounts, behaviour affected by admin mode application setting
|
|
|
|
enable :admin_all_resources
|
|
|
|
# Policy extended in EE to also enable auditors
|
|
|
|
enable :read_all_resources
|
|
|
|
enable :change_repository_storage
|
|
|
|
end
|
2019-11-06 13:06:29 -05:00
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
rule { default }.enable :read_cross_project
|
2020-06-29 08:09:20 -04:00
|
|
|
|
2021-06-16 14:10:35 -04:00
|
|
|
condition(:is_gitlab_com, score: 0, scope: :global) { ::Gitlab.dev_env_or_com? }
|
2016-08-11 18:12:52 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
BasePolicy.prepend_mod_with('BasePolicy')
|