Add create/update to Labels controller

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-07-30 13:12:11 +03:00
parent 81aebaa189
commit 048a21974e
No known key found for this signature in database
GPG key ID: 627C5F589F467F17
3 changed files with 42 additions and 2 deletions

View file

@ -1,7 +1,8 @@
class Projects::LabelsController < Projects::ApplicationController
before_filter :module_enabled
before_filter :label, only: [:edit, :update]
before_filter :authorize_labels!
before_filter :authorize_admin_labels!, only: [:edit, :update, :new, :create, :destroy]
respond_to :js, :html
@ -9,6 +10,32 @@ class Projects::LabelsController < Projects::ApplicationController
@labels = @project.labels
end
def new
@label = @project.labels.new
end
def create
@label = @project.labels.create(label_params)
if @label.valid?
redirect_to project_labels_path(@project)
else
render 'new'
end
end
def edit
end
def update
if @label.update_attributes(label_params)
redirect_to project_labels_path(@project)
else
render 'edit'
end
end
def generate
Gitlab::IssuesLabels.generate(@project)
@ -28,4 +55,16 @@ class Projects::LabelsController < Projects::ApplicationController
return render_404
end
end
def label_params
params.require(:label).permit(:title, :color)
end
def label
@label = @project.labels.find(params[:id])
end
def authorize_admin_labels!
return render_404 unless can?(current_user, :admin_label, @project)
end
end

View file

@ -164,6 +164,7 @@ class Ability
:modify_merge_request,
:admin_issue,
:admin_milestone,
:admin_label,
:admin_project_snippet,
:admin_team_member,
:admin_merge_request,

View file

@ -297,7 +297,7 @@ Gitlab::Application.routes.draw do
end
end
resources :labels, only: [:index] do
resources :labels, constraints: {id: /\d+/} do
collection do
post :generate
end