2013-06-23 16:47:22 +00:00
|
|
|
class Projects::LabelsController < Projects::ApplicationController
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :module_enabled
|
|
|
|
before_action :label, only: [:edit, :update, :destroy]
|
2015-06-17 14:33:51 +00:00
|
|
|
before_action :authorize_read_label!
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :authorize_admin_labels!, except: [:index]
|
2012-08-24 10:05:40 +00:00
|
|
|
|
|
|
|
respond_to :js, :html
|
|
|
|
|
|
|
|
def index
|
2015-03-12 22:37:00 +00:00
|
|
|
@labels = @project.labels.page(params[:page]).per(PER_PAGE)
|
2012-08-24 10:05:40 +00:00
|
|
|
end
|
|
|
|
|
2014-07-30 10:12:11 +00:00
|
|
|
def new
|
|
|
|
@label = @project.labels.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@label = @project.labels.create(label_params)
|
|
|
|
|
|
|
|
if @label.valid?
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_labels_path(@project.namespace, @project)
|
2014-07-30 10:12:11 +00:00
|
|
|
else
|
|
|
|
render 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @label.update_attributes(label_params)
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_labels_path(@project.namespace, @project)
|
2014-07-30 10:12:11 +00:00
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-07 14:57:29 +00:00
|
|
|
def generate
|
2013-05-07 16:26:41 +00:00
|
|
|
Gitlab::IssuesLabels.generate(@project)
|
2013-05-07 14:57:29 +00:00
|
|
|
|
2014-04-15 01:12:07 +00:00
|
|
|
if params[:redirect] == 'issues'
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_issues_path(@project.namespace, @project)
|
2014-04-15 01:12:07 +00:00
|
|
|
elsif params[:redirect] == 'merge_requests'
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_merge_requests_path(@project.namespace,
|
|
|
|
@project)
|
2014-06-04 08:08:21 +00:00
|
|
|
else
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_labels_path(@project.namespace, @project)
|
2014-04-15 01:12:07 +00:00
|
|
|
end
|
2013-05-07 14:57:29 +00:00
|
|
|
end
|
|
|
|
|
2014-07-30 12:15:39 +00:00
|
|
|
def destroy
|
|
|
|
@label.destroy
|
|
|
|
|
2014-08-13 16:47:03 +00:00
|
|
|
respond_to do |format|
|
2015-01-24 18:02:58 +00:00
|
|
|
format.html do
|
|
|
|
redirect_to(namespace_project_labels_path(@project.namespace, @project),
|
|
|
|
notice: 'Label was removed')
|
|
|
|
end
|
2014-09-01 09:09:07 +00:00
|
|
|
format.js
|
2014-08-13 16:47:03 +00:00
|
|
|
end
|
2014-07-30 12:15:39 +00:00
|
|
|
end
|
|
|
|
|
2012-08-24 10:05:40 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def module_enabled
|
2014-04-15 01:12:07 +00:00
|
|
|
unless @project.issues_enabled || @project.merge_requests_enabled
|
|
|
|
return render_404
|
|
|
|
end
|
2012-08-24 10:05:40 +00:00
|
|
|
end
|
2014-07-30 10:12:11 +00:00
|
|
|
|
|
|
|
def label_params
|
2016-02-17 13:52:12 +00:00
|
|
|
params.require(:label).permit(:title, :description, :color)
|
2014-07-30 10:12:11 +00:00
|
|
|
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
|
2012-08-24 10:05:40 +00:00
|
|
|
end
|