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 @@ ...@@ -3,8 +3,6 @@
require_dependency 'declarative_policy' require_dependency 'declarative_policy'
class BasePolicy < DeclarativePolicy::Base class BasePolicy < DeclarativePolicy::Base
prepend EE::BasePolicy
desc "User is an instance admin" desc "User is an instance admin"
with_options scope: :user, score: 0 with_options scope: :user, score: 0
condition(:admin) { @user&.admin? } condition(:admin) { @user&.admin? }
...@@ -23,3 +21,5 @@ class BasePolicy < DeclarativePolicy::Base ...@@ -23,3 +21,5 @@ class BasePolicy < DeclarativePolicy::Base
# This is prevented in some cases in `gitlab-ee` # This is prevented in some cases in `gitlab-ee`
rule { default }.enable :read_cross_project rule { default }.enable :read_cross_project
end end
BasePolicy.prepend(EE::BasePolicy)
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
module Ci module Ci
class BuildPolicy < CommitStatusPolicy class BuildPolicy < CommitStatusPolicy
prepend EE::Ci::BuildPolicy
condition(:protected_ref) do condition(:protected_ref) do
access = ::Gitlab::UserAccess.new(@user, project: @subject.project) access = ::Gitlab::UserAccess.new(@user, project: @subject.project)
...@@ -41,3 +39,5 @@ module Ci ...@@ -41,3 +39,5 @@ module Ci
rule { can?(:update_build) & terminal }.enable :create_build_terminal rule { can?(:update_build) & terminal }.enable :create_build_terminal
end end
end end
Ci::BuildPolicy.prepend(EE::Ci::BuildPolicy)
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
module PolicyActor module PolicyActor
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepend EE::PolicyActor
def blocked? def blocked?
false false
end end
...@@ -36,3 +34,5 @@ module PolicyActor ...@@ -36,3 +34,5 @@ module PolicyActor
false false
end end
end end
PolicyActor.prepend(EE::PolicyActor)
# frozen_string_literal: true # frozen_string_literal: true
class EnvironmentPolicy < BasePolicy class EnvironmentPolicy < BasePolicy
prepend EE::EnvironmentPolicy
delegate { @subject.project } delegate { @subject.project }
condition(:stop_with_deployment_allowed) do condition(:stop_with_deployment_allowed) do
...@@ -16,3 +14,5 @@ class EnvironmentPolicy < BasePolicy ...@@ -16,3 +14,5 @@ class EnvironmentPolicy < BasePolicy
rule { stop_with_deployment_allowed | stop_with_update_allowed }.enable :stop_environment rule { stop_with_deployment_allowed | stop_with_update_allowed }.enable :stop_environment
end end
EnvironmentPolicy.prepend(EE::EnvironmentPolicy)
# frozen_string_literal: true # frozen_string_literal: true
class GlobalPolicy < BasePolicy class GlobalPolicy < BasePolicy
prepend EE::GlobalPolicy
desc "User is blocked" desc "User is blocked"
with_options scope: :user, score: 0 with_options scope: :user, score: 0
condition(:blocked) { @user&.blocked? } condition(:blocked) { @user&.blocked? }
...@@ -75,3 +73,5 @@ class GlobalPolicy < BasePolicy ...@@ -75,3 +73,5 @@ class GlobalPolicy < BasePolicy
enable :update_custom_attribute enable :update_custom_attribute
end end
end end
GlobalPolicy.prepend(EE::GlobalPolicy)
# frozen_string_literal: true # frozen_string_literal: true
class GroupPolicy < BasePolicy class GroupPolicy < BasePolicy
prepend EE::GroupPolicy
desc "Group is public" desc "Group is public"
with_options scope: :subject, score: 0 with_options scope: :subject, score: 0
condition(:public_group) { @subject.public? } condition(:public_group) { @subject.public? }
...@@ -110,3 +108,5 @@ class GroupPolicy < BasePolicy ...@@ -110,3 +108,5 @@ class GroupPolicy < BasePolicy
@access_level ||= @subject.max_member_access_for_user(@user) @access_level ||= @subject.max_member_access_for_user(@user)
end end
end end
GroupPolicy.prepend(EE::GroupPolicy)
# frozen_string_literal: true # frozen_string_literal: true
class MergeRequestPolicy < IssuablePolicy class MergeRequestPolicy < IssuablePolicy
prepend EE::MergeRequestPolicy
end end
MergeRequestPolicy.prepend(EE::MergeRequestPolicy)
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
class ProjectPolicy < BasePolicy class ProjectPolicy < BasePolicy
extend ClassMethods extend ClassMethods
prepend EE::ProjectPolicy
READONLY_FEATURES_WHEN_ARCHIVED = %i[ READONLY_FEATURES_WHEN_ARCHIVED = %i[
issue issue
list list
...@@ -442,3 +440,5 @@ class ProjectPolicy < BasePolicy ...@@ -442,3 +440,5 @@ class ProjectPolicy < BasePolicy
@subject @subject
end end
end end
ProjectPolicy.prepend(EE::ProjectPolicy)
# frozen_string_literal: true # frozen_string_literal: true
class ProtectedBranchPolicy < BasePolicy class ProtectedBranchPolicy < BasePolicy
prepend EE::ProtectedBranchPolicy
delegate { @subject.project } delegate { @subject.project }
rule { can?(:admin_project) }.policy do rule { can?(:admin_project) }.policy do
...@@ -11,3 +9,5 @@ class ProtectedBranchPolicy < BasePolicy ...@@ -11,3 +9,5 @@ class ProtectedBranchPolicy < BasePolicy
enable :destroy_protected_branch enable :destroy_protected_branch
end end
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