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-07 13:48:07 +0300
committerTimothy Andrew <mail@timothyandrew.net>2016-07-29 12:50:39 +0300
commitab6096c17261605d835a4a8edae21f31d90026df (patch)
tree0a4490cc0a62b86bf240fbc5bdff709b2e8d11b0 /app
parentf8a04e15371815ad39e2c66056db4ab0439555f4 (diff)
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.
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/protected_branches_access_select.js.coffee39
-rw-r--r--app/assets/stylesheets/pages/projects.scss5
-rw-r--r--app/controllers/projects/protected_branches_controller.rb2
-rw-r--r--app/models/protected_branch/push_access_level.rb2
-rw-r--r--app/services/protected_branches/base_service.rb20
-rw-r--r--app/services/protected_branches/create_service.rb28
-rw-r--r--app/views/projects/protected_branches/_branches_list.html.haml37
-rw-r--r--app/views/projects/protected_branches/_protected_branch.html.haml6
8 files changed, 95 insertions, 44 deletions
diff --git a/app/assets/javascripts/protected_branches_access_select.js.coffee b/app/assets/javascripts/protected_branches_access_select.js.coffee
new file mode 100644
index 00000000000..b472ff7ec27
--- /dev/null
+++ b/app/assets/javascripts/protected_branches_access_select.js.coffee
@@ -0,0 +1,39 @@
+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")
+
diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss
index cc3aef5199e..c6e73dd1f39 100644
--- a/app/assets/stylesheets/pages/projects.scss
+++ b/app/assets/stylesheets/pages/projects.scss
@@ -664,11 +664,14 @@ pre.light-well {
.protected-branches-list {
a {
color: $gl-gray;
- font-weight: 600;
&:hover {
color: $gl-link-color;
}
+
+ &.is-active {
+ font-weight: 600;
+ }
}
}
diff --git a/app/controllers/projects/protected_branches_controller.rb b/app/controllers/projects/protected_branches_controller.rb
index fdbe0044d3c..126358bfe77 100644
--- a/app/controllers/projects/protected_branches_controller.rb
+++ b/app/controllers/projects/protected_branches_controller.rb
@@ -56,7 +56,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
end
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
def load_protected_branches
diff --git a/app/models/protected_branch/push_access_level.rb b/app/models/protected_branch/push_access_level.rb
index 4345dc4ede4..8861632c055 100644
--- a/app/models/protected_branch/push_access_level.rb
+++ b/app/models/protected_branch/push_access_level.rb
@@ -1,5 +1,5 @@
class ProtectedBranch::PushAccessLevel < ActiveRecord::Base
belongs_to :protected_branch
- enum access_level: [:masters, :developers]
+ enum access_level: [:masters, :developers, :no_one]
end
diff --git a/app/services/protected_branches/base_service.rb b/app/services/protected_branches/base_service.rb
index d4be8698a5f..3a7c35327fe 100644
--- a/app/services/protected_branches/base_service.rb
+++ b/app/services/protected_branches/base_service.rb
@@ -1,17 +1,21 @@
module ProtectedBranches
class BaseService < ::BaseService
def set_access_levels!
- if params[:developers_can_push] == '0'
- @protected_branch.push_access_level.masters!
- elsif params[:developers_can_push] == '1'
- @protected_branch.push_access_level.developers!
- end
-
- if params[:developers_can_merge] == '0'
+ case params[:allowed_to_merge]
+ when 'masters'
@protected_branch.merge_access_level.masters!
- elsif params[:developers_can_merge] == '1'
+ when 'developers'
@protected_branch.merge_access_level.developers!
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
diff --git a/app/services/protected_branches/create_service.rb b/app/services/protected_branches/create_service.rb
index 743f7bd2ce1..ab462f3054e 100644
--- a/app/services/protected_branches/create_service.rb
+++ b/app/services/protected_branches/create_service.rb
@@ -1,19 +1,21 @@
-class ProtectedBranches::CreateService < BaseService
- attr_reader :protected_branch
+module ProtectedBranches
+ class CreateService < BaseService
+ attr_reader :protected_branch
- def execute
- ProtectedBranch.transaction do
- @protected_branch = project.protected_branches.new(name: params[:name])
- @protected_branch.save!
+ def execute
+ ProtectedBranch.transaction do
+ @protected_branch = project.protected_branches.new(name: params[:name])
+ @protected_branch.save!
- @protected_branch.create_push_access_level!
- @protected_branch.create_merge_access_level!
+ @protected_branch.create_push_access_level!
+ @protected_branch.create_merge_access_level!
- set_access_levels!
- end
+ set_access_levels!
+ end
- true
- rescue ActiveRecord::RecordInvalid
- false
+ true
+ rescue ActiveRecord::RecordInvalid
+ false
+ end
end
end
diff --git a/app/views/projects/protected_branches/_branches_list.html.haml b/app/views/projects/protected_branches/_branches_list.html.haml
index 720d67dff7c..5f9f2992dca 100644
--- a/app/views/projects/protected_branches/_branches_list.html.haml
+++ b/app/views/projects/protected_branches/_branches_list.html.haml
@@ -5,24 +5,25 @@
No branches are protected, protect a branch with the form above.
- else
- can_admin_project = can?(current_user, :admin_project, @project)
- .table-responsive
- %table.table.protected-branches-list
- %colgroup
- %col{ width: "20%" }
- %col{ width: "30%" }
- %col{ width: "25%" }
- %col{ width: "25%" }
+
+ %table.table.protected-branches-list
+ %colgroup
+ %col{ width: "20%" }
+ %col{ width: "30%" }
+ %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
- %col
- %thead
- %tr
- %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 }
+ %th
+ %tbody
+ = render partial: @protected_branches, locals: { can_admin_project: can_admin_project }
= paginate @protected_branches, theme: 'gitlab'
+
+:javascript
+ new ProtectedBranchesAccessSelect();
diff --git a/app/views/projects/protected_branches/_protected_branch.html.haml b/app/views/projects/protected_branches/_protected_branch.html.haml
index 7fda7f96047..ceae182e82c 100644
--- a/app/views/projects/protected_branches/_protected_branch.html.haml
+++ b/app/views/projects/protected_branches/_protected_branch.html.haml
@@ -15,9 +15,11 @@
- else
(branch was removed from repository)
%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
- = 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
%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"