debian-mirror-gitlab/app/controllers/projects/labels_controller.rb

83 lines
1.9 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::LabelsController < Projects::ApplicationController
before_filter :module_enabled
before_filter :label, only: [:edit, :update, :destroy]
before_filter :authorize_labels!
before_filter :authorize_admin_labels!, except: [:index]
respond_to :js, :html
def index
2015-04-26 12:48:37 +05:30
@labels = @project.labels.page(params[:page]).per(PER_PAGE)
2014-09-02 18:07:02 +05:30
end
def new
@label = @project.labels.new
end
def create
@label = @project.labels.create(label_params)
if @label.valid?
2015-04-26 12:48:37 +05:30
redirect_to namespace_project_labels_path(@project.namespace, @project)
2014-09-02 18:07:02 +05:30
else
render 'new'
end
end
def edit
end
def update
if @label.update_attributes(label_params)
2015-04-26 12:48:37 +05:30
redirect_to namespace_project_labels_path(@project.namespace, @project)
2014-09-02 18:07:02 +05:30
else
render 'edit'
end
end
def generate
Gitlab::IssuesLabels.generate(@project)
if params[:redirect] == 'issues'
2015-04-26 12:48:37 +05:30
redirect_to namespace_project_issues_path(@project.namespace, @project)
2014-09-02 18:07:02 +05:30
elsif params[:redirect] == 'merge_requests'
2015-04-26 12:48:37 +05:30
redirect_to namespace_project_merge_requests_path(@project.namespace,
@project)
2014-09-02 18:07:02 +05:30
else
2015-04-26 12:48:37 +05:30
redirect_to namespace_project_labels_path(@project.namespace, @project)
2014-09-02 18:07:02 +05:30
end
end
def destroy
@label.destroy
respond_to do |format|
2015-04-26 12:48:37 +05:30
format.html do
redirect_to(namespace_project_labels_path(@project.namespace, @project),
notice: 'Label was removed')
end
format.js
2014-09-02 18:07:02 +05:30
end
end
protected
def module_enabled
unless @project.issues_enabled || @project.merge_requests_enabled
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