diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-07-14 06:42:16 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-07-29 12:50:39 +0300 |
commit | f2df2966aabc601dd1d6a6f9e75ead84db8a2765 (patch) | |
tree | 541e68b69d76145ef55b04f6907ceaefe5a88b3d /app/models/protected_branch | |
parent | c647540c1010fd1e51bced1db90947aa00c83fa8 (diff) |
Humanize protected branches' access levels at one location.
1. The model now contains this humanization data, which is the once
source of truth.
2. Previously, this was being listed out in the dropdown component as well.
Diffstat (limited to 'app/models/protected_branch')
-rw-r--r-- | app/models/protected_branch/merge_access_level.rb | 11 | ||||
-rw-r--r-- | app/models/protected_branch/push_access_level.rb | 12 |
2 files changed, 23 insertions, 0 deletions
diff --git a/app/models/protected_branch/merge_access_level.rb b/app/models/protected_branch/merge_access_level.rb index 3d2a6971702..d536f816317 100644 --- a/app/models/protected_branch/merge_access_level.rb +++ b/app/models/protected_branch/merge_access_level.rb @@ -4,6 +4,13 @@ class ProtectedBranch::MergeAccessLevel < ActiveRecord::Base enum access_level: [:masters, :developers] + def self.human_access_levels + { + "masters" => "Masters", + "developers" => "Developers + Masters" + }.with_indifferent_access + end + def check_access(user) if masters? user.can?(:push_code, project) if project.team.master?(user) @@ -11,4 +18,8 @@ class ProtectedBranch::MergeAccessLevel < ActiveRecord::Base user.can?(:push_code, project) if project.team.master?(user) || project.team.developer?(user) end end + + def humanize + self.class.human_access_levels[self.access_level] + end end diff --git a/app/models/protected_branch/push_access_level.rb b/app/models/protected_branch/push_access_level.rb index d446c1a03f0..bb46b39b714 100644 --- a/app/models/protected_branch/push_access_level.rb +++ b/app/models/protected_branch/push_access_level.rb @@ -4,6 +4,14 @@ class ProtectedBranch::PushAccessLevel < ActiveRecord::Base enum access_level: [:masters, :developers, :no_one] + def self.human_access_levels + { + "masters" => "Masters", + "developers" => "Developers + Masters", + "no_one" => "No one" + }.with_indifferent_access + end + def check_access(user) if masters? user.can?(:push_code, project) if project.team.master?(user) @@ -13,4 +21,8 @@ class ProtectedBranch::PushAccessLevel < ActiveRecord::Base false end end + + def humanize + self.class.human_access_levels[self.access_level] + end end |