summaryrefslogtreecommitdiff
path: root/app/models/protected_branch.rb
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-07-07 13:06:28 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-07-29 15:20:39 +0530
commit134fe5af83167f95205a080f7932452de7d77496 (patch)
tree6f253ad95afc8fc0525c6501ce9345294dd1ff45 /app/models/protected_branch.rb
parent21bece443d5f871680a3d7649c2d16861035196d (diff)
downloadgitlab-ce-134fe5af83167f95205a080f7932452de7d77496.tar.gz
Use the `{Push,Merge}AccessLevel` models in the UI.
1. Improve error handling while creating protected branches. 2. Modify coffeescript code so that the "Developers can *" checkboxes send a '1' or '0' even when using AJAX. This lets us keep the backend code simpler. 3. Use services for both creating and updating protected branches. Destruction is taken care of with `dependent: :destroy`
Diffstat (limited to 'app/models/protected_branch.rb')
-rw-r--r--app/models/protected_branch.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb
index a411cb417e2..b0fde6c6c1b 100644
--- a/app/models/protected_branch.rb
+++ b/app/models/protected_branch.rb
@@ -5,13 +5,21 @@ class ProtectedBranch < ActiveRecord::Base
validates :name, presence: true
validates :project, presence: true
- has_one :merge_access_level
- has_one :push_access_level
+ has_one :merge_access_level, dependent: :destroy
+ has_one :push_access_level, dependent: :destroy
def commit
project.commit(self.name)
end
+ def developers_can_push
+ self.push_access_level && self.push_access_level.developers?
+ end
+
+ def developers_can_merge
+ self.merge_access_level && self.merge_access_level.developers?
+ end
+
# Returns all protected branches that match the given branch name.
# This realizes all records from the scope built up so far, and does
# _not_ return a relation.