Commit 048a2197 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add create/update to Labels controller

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 81aebaa1
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
......@@ -164,6 +164,7 @@ class Ability
:modify_merge_request,
:admin_issue,
:admin_milestone,
:admin_label,
:admin_project_snippet,
:admin_team_member,
:admin_merge_request,
......
......@@ -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
......
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