Commit b59af5fc authored by Yorick Peterse's avatar Yorick Peterse

Move EE prepend/include to the end of policies

This moves all instances of `prepend EE::Something` and `include
EE::Something` in policy classes to the last line of the corresponding
file.  This pushes EE specific code further down the files, reducing the
likelihood of developers running into merge conflicts.
parent 921d8895
......@@ -3,8 +3,6 @@
require_dependency 'declarative_policy'
class BasePolicy < DeclarativePolicy::Base
prepend EE::BasePolicy
desc "User is an instance admin"
with_options scope: :user, score: 0
condition(:admin) { @user&.admin? }
......@@ -23,3 +21,5 @@ class BasePolicy < DeclarativePolicy::Base
# This is prevented in some cases in `gitlab-ee`
rule { default }.enable :read_cross_project
end
BasePolicy.prepend(EE::BasePolicy)
......@@ -2,8 +2,6 @@
module Ci
class BuildPolicy < CommitStatusPolicy
prepend EE::Ci::BuildPolicy
condition(:protected_ref) do
access = ::Gitlab::UserAccess.new(@user, project: @subject.project)
......@@ -41,3 +39,5 @@ module Ci
rule { can?(:update_build) & terminal }.enable :create_build_terminal
end
end
Ci::BuildPolicy.prepend(EE::Ci::BuildPolicy)
......@@ -6,8 +6,6 @@
module PolicyActor
extend ActiveSupport::Concern
prepend EE::PolicyActor
def blocked?
false
end
......@@ -36,3 +34,5 @@ module PolicyActor
false
end
end
PolicyActor.prepend(EE::PolicyActor)
# frozen_string_literal: true
class EnvironmentPolicy < BasePolicy
prepend EE::EnvironmentPolicy
delegate { @subject.project }
condition(:stop_with_deployment_allowed) do
......@@ -16,3 +14,5 @@ class EnvironmentPolicy < BasePolicy
rule { stop_with_deployment_allowed | stop_with_update_allowed }.enable :stop_environment
end
EnvironmentPolicy.prepend(EE::EnvironmentPolicy)
# frozen_string_literal: true
class GlobalPolicy < BasePolicy
prepend EE::GlobalPolicy
desc "User is blocked"
with_options scope: :user, score: 0
condition(:blocked) { @user&.blocked? }
......@@ -75,3 +73,5 @@ class GlobalPolicy < BasePolicy
enable :update_custom_attribute
end
end
GlobalPolicy.prepend(EE::GlobalPolicy)
# frozen_string_literal: true
class GroupPolicy < BasePolicy
prepend EE::GroupPolicy
desc "Group is public"
with_options scope: :subject, score: 0
condition(:public_group) { @subject.public? }
......@@ -110,3 +108,5 @@ class GroupPolicy < BasePolicy
@access_level ||= @subject.max_member_access_for_user(@user)
end
end
GroupPolicy.prepend(EE::GroupPolicy)
# frozen_string_literal: true
class MergeRequestPolicy < IssuablePolicy
prepend EE::MergeRequestPolicy
end
MergeRequestPolicy.prepend(EE::MergeRequestPolicy)
......@@ -2,8 +2,6 @@
class ProjectPolicy < BasePolicy
extend ClassMethods
prepend EE::ProjectPolicy
READONLY_FEATURES_WHEN_ARCHIVED = %i[
issue
list
......@@ -442,3 +440,5 @@ class ProjectPolicy < BasePolicy
@subject
end
end
ProjectPolicy.prepend(EE::ProjectPolicy)
# frozen_string_literal: true
class ProtectedBranchPolicy < BasePolicy
prepend EE::ProtectedBranchPolicy
delegate { @subject.project }
rule { can?(:admin_project) }.policy do
......@@ -11,3 +9,5 @@ class ProtectedBranchPolicy < BasePolicy
enable :destroy_protected_branch
end
end
ProtectedBranchPolicy.prepend(EE::ProtectedBranchPolicy)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment