Commit 92eb3974 authored by Marin Jankovski's avatar Marin Jankovski

Add option to disable/enable developers push to already protected branches.

parent 770b2a5c
...@@ -15,6 +15,23 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController ...@@ -15,6 +15,23 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
redirect_to project_protected_branches_path(@project) redirect_to project_protected_branches_path(@project)
end end
def update
protected_branch = @project.protected_branches.find(params[:id])
if protected_branch &&
protected_branch.update_attributes(
developers_can_push: params[:developers_can_push]
)
flash[:notice] = 'Branch was successfully updated.'
else
flash[:alert] = 'Could not update the branch.'
end
respond_to do |format|
format.html { redirect_to project_protected_branches_path }
end
end
def destroy def destroy
@project.protected_branches.find(params[:id]).destroy @project.protected_branches.find(params[:id]).destroy
......
...@@ -40,8 +40,15 @@ ...@@ -40,8 +40,15 @@
%span.label.label-info default %span.label.label-info default
%span.label.label-success %span.label.label-success
%i.fa.fa-lock %i.fa.fa-lock
- if branch.developers_can_push
%span.label.label-warning
%i.fa.fa-group
.pull-right .pull-right
- if can? current_user, :admin_project, @project - if can? current_user, :admin_project, @project
- if branch.developers_can_push
= link_to 'Disable developers push', [@project, branch, { developers_can_push: false }], data: { confirm: 'Branch will be no longer writable for developers. Are you sure?' }, method: :put, class: "btn btn-grouped btn-small"
- else
= link_to 'Allow developers to push', [@project, branch, { developers_can_push: true }], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :put, class: "btn btn-grouped btn-small"
= link_to 'Unprotect', [@project, branch], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :delete, class: "btn btn-remove btn-small" = link_to 'Unprotect', [@project, branch], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :delete, class: "btn btn-remove btn-small"
- if commit = branch.commit - if commit = branch.commit
......
...@@ -256,7 +256,7 @@ Gitlab::Application.routes.draw do ...@@ -256,7 +256,7 @@ Gitlab::Application.routes.draw do
resources :branches, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } resources :branches, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
resources :tags, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } resources :tags, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
resources :protected_branches, only: [:index, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } resources :protected_branches, only: [:index, :create, :update, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
resources :refs, only: [] do resources :refs, only: [] do
collection do collection do
......
...@@ -80,7 +80,7 @@ module Gitlab ...@@ -80,7 +80,7 @@ module Gitlab
action = if project.protected_branch?(branch_name(ref)) action = if project.protected_branch?(branch_name(ref))
protected_branch_action(project, oldrev, newrev, branch_name(ref)) protected_branch_action(project, oldrev, newrev, branch_name(ref))
elsif protected_tag?(tag_name(ref)) elsif protected_tag?(project, tag_name(ref))
# Prevent any changes to existing git tag unless user has permissions # Prevent any changes to existing git tag unless user has permissions
:admin_project :admin_project
else else
...@@ -114,7 +114,7 @@ module Gitlab ...@@ -114,7 +114,7 @@ module Gitlab
end end
end end
def protected_tag?(tag_name) def protected_tag?(project, tag_name)
project.repository.tag_names.include?(tag_name) project.repository.tag_names.include?(tag_name)
end end
......
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