From 4f71c29c8bb35642ed5d26015619fc3f838f5e56 Mon Sep 17 00:00:00 2001 From: James Edwards-Jones Date: Mon, 3 Apr 2017 19:28:54 +0100 Subject: Moved default_branch_protected? out of Project --- app/models/project.rb | 13 +------------ app/models/protected_branch.rb | 7 ++++++- 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'app/models') diff --git a/app/models/project.rb b/app/models/project.rb index 5cc224b4440..fdb0a679e28 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -883,11 +883,6 @@ class Project < ActiveRecord::Base "#{url}.git" end - - def empty_and_default_branch_protected? - empty_repo? && default_branch_protected? - end - #TODO: Check with if this is still needed, maybe because of `.select {` in ProtectedRefsMatcher #Either with tests or by asking Tim def protected_tags_array @@ -899,7 +894,7 @@ class Project < ActiveRecord::Base end def user_can_push_to_empty_repo?(user) - !default_branch_protected? || team.max_member_access(user.id) > Gitlab::Access::DEVELOPER + !ProtectedBranch.default_branch_protected? || team.max_member_access(user.id) > Gitlab::Access::DEVELOPER end def forked? @@ -1366,12 +1361,6 @@ class Project < ActiveRecord::Base "projects/#{id}/pushes_since_gc" end - #TODO: Move this and methods which depend upon it - def default_branch_protected? - current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_FULL || - current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE - end - # Similar to the normal callbacks that hook into the life cycle of an # Active Record object, you can also define callbacks that get triggered # when you add an object to an association collection. If any of these diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index eca8d5e0f7d..0f0ac18b1a3 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -13,9 +13,14 @@ class ProtectedBranch < ActiveRecord::Base # Check if branch name is marked as protected in the system def self.protected?(project, ref_name) - return true if project.empty_and_default_branch_protected? + return true if project.empty_repo? && default_branch_protected? protected_refs = project.protected_branches_array self.matching(ref_name, protected_refs: protected_refs).present? end + + def self.default_branch_protected? + current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_FULL || + current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE + end end -- cgit v1.2.1