BigW Consortium Gitlab

Add create/update to Labels controller

parent 81aebaa1
class Projects::LabelsController < Projects::ApplicationController class Projects::LabelsController < Projects::ApplicationController
before_filter :module_enabled before_filter :module_enabled
before_filter :label, only: [:edit, :update]
before_filter :authorize_labels! before_filter :authorize_labels!
before_filter :authorize_admin_labels!, only: [:edit, :update, :new, :create, :destroy]
respond_to :js, :html respond_to :js, :html
...@@ -9,6 +10,32 @@ class Projects::LabelsController < Projects::ApplicationController ...@@ -9,6 +10,32 @@ class Projects::LabelsController < Projects::ApplicationController
@labels = @project.labels @labels = @project.labels
end 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 def generate
Gitlab::IssuesLabels.generate(@project) Gitlab::IssuesLabels.generate(@project)
...@@ -28,4 +55,16 @@ class Projects::LabelsController < Projects::ApplicationController ...@@ -28,4 +55,16 @@ class Projects::LabelsController < Projects::ApplicationController
return render_404 return render_404
end end
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 end
...@@ -164,6 +164,7 @@ class Ability ...@@ -164,6 +164,7 @@ class Ability
:modify_merge_request, :modify_merge_request,
:admin_issue, :admin_issue,
:admin_milestone, :admin_milestone,
:admin_label,
:admin_project_snippet, :admin_project_snippet,
:admin_team_member, :admin_team_member,
:admin_merge_request, :admin_merge_request,
......
...@@ -297,7 +297,7 @@ Gitlab::Application.routes.draw do ...@@ -297,7 +297,7 @@ Gitlab::Application.routes.draw do
end end
end end
resources :labels, only: [:index] do resources :labels, constraints: {id: /\d+/} do
collection do collection do
post :generate post :generate
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