GitLab steht aufgrund wichtiger Wartungsarbeiten am Montag, den 8. März, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Commit f2df2966 authored by Timothy Andrew's avatar Timothy Andrew

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
......@@ -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)
......
......@@ -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
......
......@@ -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 @@ def check_access(user)
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
......@@ -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 @@ def check_access(user)
false
end
end
def humanize
self.class.human_access_levels[self.access_level]
end
end
......@@ -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
......
......@@ -83,11 +83,7 @@ def set_protected_branch_name(branch_name)
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')
......@@ -120,10 +116,7 @@ def set_protected_branch_name(branch_name)
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')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment