Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-07-14 06:42:16 +0300
committerTimothy Andrew <mail@timothyandrew.net>2016-07-29 12:50:39 +0300
commitf2df2966aabc601dd1d6a6f9e75ead84db8a2765 (patch)
tree541e68b69d76145ef55b04f6907ceaefe5a88b3d /app
parentc647540c1010fd1e51bced1db90947aa00c83fa8 (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')
-rw-r--r--app/assets/javascripts/protected_branches_access_select.js.coffee6
-rw-r--r--app/controllers/projects/protected_branches_controller.rb4
-rw-r--r--app/models/protected_branch/merge_access_level.rb11
-rw-r--r--app/models/protected_branch/push_access_level.rb12
-rw-r--r--app/views/projects/protected_branches/_protected_branch.html.haml4
5 files changed, 30 insertions, 7 deletions
diff --git a/app/assets/javascripts/protected_branches_access_select.js.coffee b/app/assets/javascripts/protected_branches_access_select.js.coffee
index 6df11146ba9..2c29513ae61 100644
--- a/app/assets/javascripts/protected_branches_access_select.js.coffee
+++ b/app/assets/javascripts/protected_branches_access_select.js.coffee
@@ -3,7 +3,7 @@ class @ProtectedBranchesAccessSelect
@container.find(".allowed-to-merge").each (i, element) =>
fieldName = $(element).data('field-name')
$(element).glDropdown
- data: [{id: 'developers', text: 'Developers + Masters'}, {id: 'masters', text: 'Masters'}]
+ data: gon.merge_access_levels
selectable: true
fieldName: fieldName
clicked: _.partial(@onSelect, element)
@@ -11,9 +11,7 @@ class @ProtectedBranchesAccessSelect
@container.find(".allowed-to-push").each (i, element) =>
fieldName = $(element).data('field-name')
$(element).glDropdown
- data: [{id: 'no_one', text: 'No one'},
- {id: 'developers', text: 'Developers + Masters'},
- {id: 'masters', text: 'Masters'}]
+ data: gon.push_access_levels
selectable: true
fieldName: fieldName
clicked: _.partial(@onSelect, element)
diff --git a/app/controllers/projects/protected_branches_controller.rb b/app/controllers/projects/protected_branches_controller.rb
index 126358bfe77..ddf1824ccb9 100644
--- a/app/controllers/projects/protected_branches_controller.rb
+++ b/app/controllers/projects/protected_branches_controller.rb
@@ -9,7 +9,9 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
def index
@protected_branch = @project.protected_branches.new
- gon.push({ open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } })
+ gon.push({ open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } },
+ push_access_levels: ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text } },
+ merge_access_levels: ProtectedBranch::MergeAccessLevel.human_access_levels.map { |id, text| { id: id, text: text } } })
end
def create
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
diff --git a/app/views/projects/protected_branches/_protected_branch.html.haml b/app/views/projects/protected_branches/_protected_branch.html.haml
index 89d606d9e20..e27dea8145d 100644
--- a/app/views/projects/protected_branches/_protected_branch.html.haml
+++ b/app/views/projects/protected_branches/_protected_branch.html.haml
@@ -16,12 +16,12 @@
(branch was removed from repository)
%td
= hidden_field_tag "allowed_to_merge_#{protected_branch.id}", protected_branch.merge_access_level.access_level
- = dropdown_tag(protected_branch.merge_access_level.access_level.humanize,
+ = dropdown_tag(protected_branch.merge_access_level.humanize,
options: { title: "Allowed To Merge", toggle_class: 'allowed-to-merge', dropdown_class: 'dropdown-menu-selectable merge',
data: { field_name: "allowed_to_merge_#{protected_branch.id}", url: url, id: protected_branch.id, type: "allowed_to_merge" }})
%td
= hidden_field_tag "allowed_to_push_#{protected_branch.id}", protected_branch.push_access_level.access_level
- = dropdown_tag(protected_branch.push_access_level.access_level.humanize,
+ = dropdown_tag(protected_branch.push_access_level.humanize,
options: { title: "Allowed To Push", toggle_class: 'allowed-to-push', dropdown_class: 'dropdown-menu-selectable push',
data: { field_name: "allowed_to_push_#{protected_branch.id}", url: url, id: protected_branch.id, type: "allowed_to_push" }})
- if can_admin_project