2013-06-23 12:47:22 -04:00
|
|
|
class Projects::LabelsController < Projects::ApplicationController
|
2016-03-15 12:18:47 -04:00
|
|
|
include ToggleSubscriptionAction
|
|
|
|
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :module_enabled
|
2016-03-15 12:18:47 -04:00
|
|
|
before_action :label, only: [:edit, :update, :destroy]
|
2015-06-17 10:33:51 -04:00
|
|
|
before_action :authorize_read_label!
|
2016-03-15 12:18:47 -04:00
|
|
|
before_action :authorize_admin_labels!, only: [
|
2016-06-03 02:13:15 -04:00
|
|
|
:new, :create, :edit, :update, :generate, :destroy, :remove_priority, :set_priorities
|
2016-03-15 12:18:47 -04:00
|
|
|
]
|
2012-08-24 06:05:40 -04:00
|
|
|
|
|
|
|
respond_to :js, :html
|
|
|
|
|
|
|
|
def index
|
2016-06-02 15:57:31 -04:00
|
|
|
@labels = @project.labels.unprioritized.page(params[:page])
|
|
|
|
@prioritized_labels = @project.labels.prioritized
|
2016-03-16 14:08:35 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2016-03-16 14:37:25 -04:00
|
|
|
render json: @project.labels
|
2016-03-16 14:08:35 -04:00
|
|
|
end
|
|
|
|
end
|
2012-08-24 06:05:40 -04:00
|
|
|
end
|
|
|
|
|
2014-07-30 06:12:11 -04:00
|
|
|
def new
|
|
|
|
@label = @project.labels.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@label = @project.labels.create(label_params)
|
|
|
|
|
|
|
|
if @label.valid?
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_labels_path(@project.namespace, @project)
|
2014-07-30 06:12:11 -04:00
|
|
|
else
|
|
|
|
render 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @label.update_attributes(label_params)
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_labels_path(@project.namespace, @project)
|
2014-07-30 06:12:11 -04:00
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-07 10:57:29 -04:00
|
|
|
def generate
|
2013-05-07 12:26:41 -04:00
|
|
|
Gitlab::IssuesLabels.generate(@project)
|
2013-05-07 10:57:29 -04:00
|
|
|
|
2014-04-14 21:12:07 -04:00
|
|
|
if params[:redirect] == 'issues'
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_issues_path(@project.namespace, @project)
|
2014-04-14 21:12:07 -04:00
|
|
|
elsif params[:redirect] == 'merge_requests'
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_merge_requests_path(@project.namespace,
|
|
|
|
@project)
|
2014-06-04 04:08:21 -04:00
|
|
|
else
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_labels_path(@project.namespace, @project)
|
2014-04-14 21:12:07 -04:00
|
|
|
end
|
2013-05-07 10:57:29 -04:00
|
|
|
end
|
|
|
|
|
2014-07-30 08:15:39 -04:00
|
|
|
def destroy
|
|
|
|
@label.destroy
|
|
|
|
|
2014-08-13 12:47:03 -04:00
|
|
|
respond_to do |format|
|
2015-01-24 13:02:58 -05:00
|
|
|
format.html do
|
|
|
|
redirect_to(namespace_project_labels_path(@project.namespace, @project),
|
|
|
|
notice: 'Label was removed')
|
|
|
|
end
|
2014-09-01 05:09:07 -04:00
|
|
|
format.js
|
2014-08-13 12:47:03 -04:00
|
|
|
end
|
2014-07-30 08:15:39 -04:00
|
|
|
end
|
|
|
|
|
2016-05-13 11:26:18 -04:00
|
|
|
def remove_priority
|
2016-05-02 19:19:46 -04:00
|
|
|
respond_to do |format|
|
2016-05-13 11:26:18 -04:00
|
|
|
if label.update_attribute(:priority, nil)
|
2016-05-02 19:19:46 -04:00
|
|
|
format.json { render json: label }
|
|
|
|
else
|
|
|
|
message = label.errors.full_messages.uniq.join('. ')
|
|
|
|
format.json { render json: { message: message }, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 16:21:15 -04:00
|
|
|
def set_priorities
|
2016-05-13 11:26:18 -04:00
|
|
|
Label.transaction do
|
|
|
|
params[:label_ids].each_with_index do |label_id, index|
|
|
|
|
label = @project.labels.find_by_id(label_id)
|
|
|
|
label.update_attribute(:priority, index) if label
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-02 19:19:46 -04:00
|
|
|
respond_to do |format|
|
2016-05-13 11:26:18 -04:00
|
|
|
format.json { render json: { message: 'success' } }
|
2016-05-02 19:19:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-24 06:05:40 -04:00
|
|
|
protected
|
|
|
|
|
|
|
|
def module_enabled
|
2014-04-14 21:12:07 -04:00
|
|
|
unless @project.issues_enabled || @project.merge_requests_enabled
|
|
|
|
return render_404
|
|
|
|
end
|
2012-08-24 06:05:40 -04:00
|
|
|
end
|
2014-07-30 06:12:11 -04:00
|
|
|
|
|
|
|
def label_params
|
2016-06-02 17:33:53 -04:00
|
|
|
params.require(:label).permit(:title, :description, :color)
|
2014-07-30 06:12:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def label
|
2016-03-15 12:18:47 -04:00
|
|
|
@label ||= @project.labels.find(params[:id])
|
2014-07-30 06:12:11 -04:00
|
|
|
end
|
2016-03-15 12:18:47 -04:00
|
|
|
alias_method :subscribable_resource, :label
|
2014-07-30 06:12:11 -04:00
|
|
|
|
|
|
|
def authorize_admin_labels!
|
|
|
|
return render_404 unless can?(current_user, :admin_label, @project)
|
|
|
|
end
|
2012-08-24 06:05:40 -04:00
|
|
|
end
|