2016-08-16 19:29:19 -04:00
|
|
|
class GlobalPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "User is blocked"
|
|
|
|
with_options scope: :user, score: 0
|
2018-05-09 06:55:31 -04:00
|
|
|
condition(:blocked) { @user&.blocked? }
|
2017-06-29 03:43:41 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "User is an internal user"
|
|
|
|
with_options scope: :user, score: 0
|
2018-05-09 06:55:31 -04:00
|
|
|
condition(:internal) { @user&.internal? }
|
2016-08-30 14:14:07 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "User's access has been locked"
|
|
|
|
with_options scope: :user, score: 0
|
2018-05-09 06:55:31 -04:00
|
|
|
condition(:access_locked) { @user&.access_locked? }
|
2017-02-28 16:09:23 -05:00
|
|
|
|
2018-05-09 06:55:31 -04:00
|
|
|
condition(:can_create_fork, scope: :user) { @user && @user.manageable_namespaces.any? { |namespace| @user.can?(:create_projects, namespace) } }
|
2017-09-29 07:14:39 -04:00
|
|
|
|
2018-05-08 09:07:55 -04:00
|
|
|
condition(:required_terms_not_accepted, scope: :user, score: 0) do
|
|
|
|
@user&.required_terms_not_accepted?
|
|
|
|
end
|
|
|
|
|
2017-06-30 09:29:34 -04:00
|
|
|
rule { anonymous }.policy do
|
|
|
|
prevent :log_in
|
|
|
|
prevent :receive_notifications
|
|
|
|
prevent :use_quick_actions
|
|
|
|
prevent :create_group
|
|
|
|
end
|
2017-04-06 17:06:42 -04:00
|
|
|
|
|
|
|
rule { default }.policy do
|
|
|
|
enable :log_in
|
|
|
|
enable :access_api
|
|
|
|
enable :access_git
|
|
|
|
enable :receive_notifications
|
|
|
|
enable :use_quick_actions
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { blocked | internal }.policy do
|
|
|
|
prevent :log_in
|
|
|
|
prevent :access_api
|
|
|
|
prevent :access_git
|
|
|
|
prevent :receive_notifications
|
|
|
|
prevent :use_quick_actions
|
|
|
|
end
|
|
|
|
|
2018-05-08 09:07:55 -04:00
|
|
|
rule { required_terms_not_accepted }.policy do
|
|
|
|
prevent :access_api
|
|
|
|
prevent :access_git
|
|
|
|
end
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { can_create_group }.policy do
|
|
|
|
enable :create_group
|
|
|
|
end
|
|
|
|
|
2017-09-29 07:14:39 -04:00
|
|
|
rule { can_create_fork }.policy do
|
|
|
|
enable :create_fork
|
|
|
|
end
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { access_locked }.policy do
|
|
|
|
prevent :log_in
|
2016-08-16 19:29:19 -04:00
|
|
|
end
|
2017-06-30 09:29:34 -04:00
|
|
|
|
2017-08-01 03:46:13 -04:00
|
|
|
rule { ~(anonymous & restricted_public_level) }.policy do
|
2017-06-30 09:29:34 -04:00
|
|
|
enable :read_users_list
|
2016-08-16 19:29:19 -04:00
|
|
|
end
|
2017-09-28 12:49:42 -04:00
|
|
|
|
|
|
|
rule { admin }.policy do
|
|
|
|
enable :read_custom_attribute
|
|
|
|
enable :update_custom_attribute
|
|
|
|
end
|
2016-08-16 19:29:19 -04:00
|
|
|
end
|