Commit ab6096c1 authored by Timothy Andrew's avatar Timothy Andrew

Add "No One Can Push" to the protected branches UI.

1. Move to dropdowns instead of checkboxes. One each for "Allowed to
   Push" and "Allowed to Merge"

2. Refactor the `ProtectedBranches` coffeescript class into
   `ProtectedBranchesAccessSelect`.

3. Modify the backend to accept the new parameters.
parent f8a04e15
class @ProtectedBranchesAccessSelect
constructor: () ->
$(".allowed-to-merge").each (i, element) =>
fieldName = $(element).data('field-name')
$(element).glDropdown
data: [{id: 'developers', text: 'Developers'}, {id: 'masters', text: 'Masters'}]
selectable: true
fieldName: fieldName
clicked: _.partial(@onSelect, element)
$(".allowed-to-push").each (i, element) =>
fieldName = $(element).data('field-name')
$(element).glDropdown
data: [{id: 'no_one', text: 'No one'},
{id: 'developers', text: 'Developers'},
{id: 'masters', text: 'Masters'}]
selectable: true
fieldName: fieldName
clicked: _.partial(@onSelect, element)
onSelect: (dropdown, selected, element, e) =>
$(dropdown).find('.dropdown-toggle-text').text(selected.text)
$.ajax
type: "PATCH"
url: $(dropdown).data('url')
dataType: "json"
data:
id: $(dropdown).data('id')
protected_branch:
"#{$(dropdown).data('type')}": selected.id
success: ->
row = $(e.target)
row.closest('tr').effect('highlight')
error: ->
new Flash("Failed to update branch!", "alert")
...@@ -664,11 +664,14 @@ pre.light-well { ...@@ -664,11 +664,14 @@ pre.light-well {
.protected-branches-list { .protected-branches-list {
a { a {
color: $gl-gray; color: $gl-gray;
font-weight: 600;
&:hover { &:hover {
color: $gl-link-color; color: $gl-link-color;
} }
&.is-active {
font-weight: 600;
}
} }
} }
......
...@@ -56,7 +56,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController ...@@ -56,7 +56,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
end end
def protected_branch_params def protected_branch_params
params.require(:protected_branch).permit(:name, :developers_can_push, :developers_can_merge) params.require(:protected_branch).permit(:name, :allowed_to_push, :allowed_to_merge)
end end
def load_protected_branches def load_protected_branches
......
class ProtectedBranch::PushAccessLevel < ActiveRecord::Base class ProtectedBranch::PushAccessLevel < ActiveRecord::Base
belongs_to :protected_branch belongs_to :protected_branch
enum access_level: [:masters, :developers] enum access_level: [:masters, :developers, :no_one]
end end
module ProtectedBranches module ProtectedBranches
class BaseService < ::BaseService class BaseService < ::BaseService
def set_access_levels! def set_access_levels!
if params[:developers_can_push] == '0' case params[:allowed_to_merge]
@protected_branch.push_access_level.masters! when 'masters'
elsif params[:developers_can_push] == '1'
@protected_branch.push_access_level.developers!
end
if params[:developers_can_merge] == '0'
@protected_branch.merge_access_level.masters! @protected_branch.merge_access_level.masters!
elsif params[:developers_can_merge] == '1' when 'developers'
@protected_branch.merge_access_level.developers! @protected_branch.merge_access_level.developers!
end end
case params[:allowed_to_push]
when 'masters'
@protected_branch.push_access_level.masters!
when 'developers'
@protected_branch.push_access_level.developers!
when 'no_one'
@protected_branch.push_access_level.no_one!
end
end end
end end
end end
class ProtectedBranches::CreateService < BaseService module ProtectedBranches
attr_reader :protected_branch class CreateService < BaseService
attr_reader :protected_branch
def execute def execute
ProtectedBranch.transaction do ProtectedBranch.transaction do
@protected_branch = project.protected_branches.new(name: params[:name]) @protected_branch = project.protected_branches.new(name: params[:name])
@protected_branch.save! @protected_branch.save!
@protected_branch.create_push_access_level! @protected_branch.create_push_access_level!
@protected_branch.create_merge_access_level! @protected_branch.create_merge_access_level!
set_access_levels! set_access_levels!
end end
true true
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
false false
end
end end
end end
...@@ -5,24 +5,25 @@ ...@@ -5,24 +5,25 @@
No branches are protected, protect a branch with the form above. No branches are protected, protect a branch with the form above.
- else - else
- can_admin_project = can?(current_user, :admin_project, @project) - can_admin_project = can?(current_user, :admin_project, @project)
.table-responsive
%table.table.protected-branches-list %table.table.protected-branches-list
%colgroup %colgroup
%col{ width: "20%" } %col{ width: "20%" }
%col{ width: "30%" } %col{ width: "30%" }
%col{ width: "25%" } %col{ width: "25%" }
%col{ width: "25%" } %col{ width: "25%" }
%thead
%tr
%th Branch
%th Last commit
%th Allowed to Merge
%th Allowed to Push
- if can_admin_project - if can_admin_project
%col %th
%thead %tbody
%tr = render partial: @protected_branches, locals: { can_admin_project: can_admin_project }
%th Protected Branch
%th Commit
%th Developers Can Push
%th Developers Can Merge
- if can_admin_project
%th
%tbody
= render partial: @protected_branches, locals: { can_admin_project: can_admin_project }
= paginate @protected_branches, theme: 'gitlab' = paginate @protected_branches, theme: 'gitlab'
:javascript
new ProtectedBranchesAccessSelect();
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
- else - else
(branch was removed from repository) (branch was removed from repository)
%td %td
= check_box_tag("developers_can_push", protected_branch.id, protected_branch.developers_can_push, data: { url: url }) = hidden_field_tag "allowed_to_merge_#{branch.id}", branch.merge_access_level.access_level
= dropdown_tag(branch.merge_access_level.access_level.humanize, options: { title: "Allowed To Merge", toggle_class: 'allowed-to-merge', dropdown_class: 'dropdown-menu-selectable', data: { field_name: "allowed_to_merge_#{branch.id}", url: @url, id: branch.id, type: "allowed_to_merge" }})
%td %td
= check_box_tag("developers_can_merge", protected_branch.id, protected_branch.developers_can_merge, data: { url: url }) = hidden_field_tag "allowed_to_push_#{branch.id}", branch.push_access_level.access_level
= dropdown_tag(branch.push_access_level.access_level.humanize, options: { title: "Allowed To Push", toggle_class: 'allowed-to-push', dropdown_class: 'dropdown-menu-selectable', data: { field_name: "allowed_to_push_#{branch.id}", url: @url, id: branch.id, type: "allowed_to_push" }})
- if can_admin_project - if can_admin_project
%td %td
= link_to 'Unprotect', [@project.namespace.becomes(Namespace), @project, protected_branch], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :delete, class: "btn btn-warning btn-sm pull-right" = link_to 'Unprotect', [@project.namespace.becomes(Namespace), @project, protected_branch], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :delete, class: "btn btn-warning btn-sm pull-right"
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