Skip to content
Snippets Groups Projects
Commit f2df2966 authored by Timothy Andrew's avatar Timothy Andrew
Browse files

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.
parent c647540c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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)
Loading
Loading
@@ -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)
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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)
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
Loading
Loading
@@ -13,4 +21,8 @@ class ProtectedBranch::PushAccessLevel < ActiveRecord::Base
false
end
end
def humanize
self.class.human_access_levels[self.access_level]
end
end
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -83,11 +83,7 @@ feature 'Projected Branches', feature: true, js: true do
end
 
describe "access control" do
[
['developers', 'Developers + Masters'],
['masters', 'Masters'],
['no_one', 'No one']
].each do |access_type_id, access_type_name|
ProtectedBranch::PushAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)|
it "allows creating protected branches that #{access_type_name} can push to" do
visit namespace_project_protected_branches_path(project.namespace, project)
set_protected_branch_name('master')
Loading
Loading
@@ -120,10 +116,7 @@ feature 'Projected Branches', feature: true, js: true do
end
end
 
[
['developers', 'Developers + Masters'],
['masters', 'Masters']
].each do |access_type_id, access_type_name|
ProtectedBranch::MergeAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)|
it "allows creating protected branches that #{access_type_name} can merge to" do
visit namespace_project_protected_branches_path(project.namespace, project)
set_protected_branch_name('master')
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment