Commit 12387b4d authored by Timothy Andrew's avatar Timothy Andrew

Allow setting "Allowed To Push/Merge" while creating a protected branch.

1. Reuse the same dropdown component that we used for updating these
   settings (`ProtectedBranchesAccessSelect`). Have it accept options
   for the parent container (so we can control the elements it sees) and
   whether or not to save changes via AJAX (we need this for update, but
   not create).

2. Change the "Developers" option to "Developers + Masters", which is
   clearer.

3. Remove `developers_can_push` and `developers_can_merge` from the
   model, since they're not needed anymore.
parent 828f6eb6
class @ProtectedBranchesAccessSelect class @ProtectedBranchesAccessSelect
constructor: () -> constructor: (@container, @saveOnSelect) ->
$(".allowed-to-merge").each (i, element) => @container.find(".allowed-to-merge").each (i, element) =>
fieldName = $(element).data('field-name') fieldName = $(element).data('field-name')
$(element).glDropdown $(element).glDropdown
data: [{id: 'developers', text: 'Developers'}, {id: 'masters', text: 'Masters'}] data: [{id: 'developers', text: 'Developers + Masters'}, {id: 'masters', text: 'Masters'}]
selectable: true selectable: true
fieldName: fieldName fieldName: fieldName
clicked: _.partial(@onSelect, element) clicked: _.partial(@onSelect, element)
$(".allowed-to-push").each (i, element) => @container.find(".allowed-to-push").each (i, element) =>
fieldName = $(element).data('field-name') fieldName = $(element).data('field-name')
$(element).glDropdown $(element).glDropdown
data: [{id: 'no_one', text: 'No one'}, data: [{id: 'no_one', text: 'No one'},
{id: 'developers', text: 'Developers'}, {id: 'developers', text: 'Developers + Masters'},
{id: 'masters', text: 'Masters'}] {id: 'masters', text: 'Masters'}]
selectable: true selectable: true
fieldName: fieldName fieldName: fieldName
...@@ -21,6 +21,7 @@ class @ProtectedBranchesAccessSelect ...@@ -21,6 +21,7 @@ class @ProtectedBranchesAccessSelect
onSelect: (dropdown, selected, element, e) => onSelect: (dropdown, selected, element, e) =>
$(dropdown).find('.dropdown-toggle-text').text(selected.text) $(dropdown).find('.dropdown-toggle-text').text(selected.text)
if @saveOnSelect
$.ajax $.ajax
type: "PATCH" type: "PATCH"
url: $(dropdown).data('url') url: $(dropdown).data('url')
......
...@@ -661,6 +661,17 @@ pre.light-well { ...@@ -661,6 +661,17 @@ pre.light-well {
} }
} }
.new_protected_branch {
.dropdown {
display: inline;
margin-left: 15px;
}
label {
min-width: 120px;
}
}
.protected-branches-list { .protected-branches-list {
a { a {
color: $gl-gray; color: $gl-gray;
......
...@@ -12,12 +12,12 @@ class ProtectedBranch < ActiveRecord::Base ...@@ -12,12 +12,12 @@ class ProtectedBranch < ActiveRecord::Base
project.commit(self.name) project.commit(self.name)
end end
def developers_can_push def allowed_to_push
self.push_access_level && self.push_access_level.developers? self.push_access_level && self.push_access_level.access_level
end end
def developers_can_merge def allowed_to_merge
self.merge_access_level && self.merge_access_level.developers? self.merge_access_level && self.merge_access_level.access_level
end end
# Returns all protected branches that match the given branch name. # Returns all protected branches that match the given branch name.
......
...@@ -26,4 +26,4 @@ ...@@ -26,4 +26,4 @@
= paginate @protected_branches, theme: 'gitlab' = paginate @protected_branches, theme: 'gitlab'
:javascript :javascript
new ProtectedBranchesAccessSelect(); new ProtectedBranchesAccessSelect($(".protected-branches-list"), true);
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
- else - else
(branch was removed from repository) (branch was removed from repository)
%td %td
= hidden_field_tag "allowed_to_merge_#{branch.id}", branch.merge_access_level.access_level = hidden_field_tag "allowed_to_merge_#{protected_branch.id}", protected_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" }}) = dropdown_tag(protected_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_#{protected_branch.id}", url: url, id: protected_branch.id, type: "allowed_to_merge" }})
%td %td
= hidden_field_tag "allowed_to_push_#{branch.id}", branch.push_access_level.access_level = hidden_field_tag "allowed_to_push_#{protected_branch.id}", protected_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" }}) = dropdown_tag(protected_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_#{protected_branch.id}", url: url, id: protected_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"
...@@ -32,19 +32,28 @@ ...@@ -32,19 +32,28 @@
are supported. are supported.
.form-group .form-group
= f.check_box :developers_can_push, class: "pull-left" .prepend-left-10
.prepend-left-20 = f.hidden_field :allowed_to_merge
= f.label :developers_can_push, "Developers can push", class: "label-light append-bottom-0" = f.label :allowed_to_merge, "Allowed to Merge: ", class: "label-light append-bottom-0"
%p.light.append-bottom-0 = dropdown_tag("<Make a selection>",
Allow developers to push to this branch options: { title: "Allowed To Merge", toggle_class: 'allowed-to-merge',
dropdown_class: 'dropdown-menu-selectable',
data: { field_name: "protected_branch[allowed_to_merge]" }})
.form-group .form-group
= f.check_box :developers_can_merge, class: "pull-left" .prepend-left-10
.prepend-left-20 = f.hidden_field :allowed_to_push
= f.label :developers_can_merge, "Developers can merge", class: "label-light append-bottom-0" = f.label :allowed_to_push, "Allowed to Push: ", class: "label-light append-bottom-0"
%p.light.append-bottom-0 = dropdown_tag("<Make a selection>",
Allow developers to accept merge requests to this branch options: { title: "Allowed To Push", toggle_class: 'allowed-to-push',
dropdown_class: 'dropdown-menu-selectable',
data: { field_name: "protected_branch[allowed_to_push]" }})
= f.submit "Protect", class: "btn-create btn protect-branch-btn", disabled: true = f.submit "Protect", class: "btn-create btn protect-branch-btn", disabled: true
%hr %hr
= render "branches_list" = render "branches_list"
:javascript
new ProtectedBranchesAccessSelect($(".new_protected_branch"), false);
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