diff options
-rw-r--r-- | app/controllers/projects/labels_controller.rb | 41 | ||||
-rw-r--r-- | app/models/ability.rb | 1 | ||||
-rw-r--r-- | config/routes.rb | 2 |
3 files changed, 42 insertions, 2 deletions
diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb index d2c5e90b257..4d0723a26df 100644 --- a/app/controllers/projects/labels_controller.rb +++ b/app/controllers/projects/labels_controller.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index d33ca41118a..09a652ecaad 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -164,6 +164,7 @@ class Ability :modify_merge_request, :admin_issue, :admin_milestone, + :admin_label, :admin_project_snippet, :admin_team_member, :admin_merge_request, diff --git a/config/routes.rb b/config/routes.rb index 3b34ad40297..261fbb50e38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 |