labels_controller.rb 1.43 KB
Newer Older
1
class Projects::LabelsController < Projects::ApplicationController
randx's avatar
randx committed
2
  before_filter :module_enabled
3
  before_filter :label, only: [:edit, :update]
4
  before_filter :authorize_labels!
5
  before_filter :authorize_admin_labels!, only: [:edit, :update, :new, :create, :destroy]
randx's avatar
randx committed
6 7 8 9

  respond_to :js, :html

  def index
10
    @labels = @project.labels
randx's avatar
randx committed
11 12
  end

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  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

39
  def generate
40
    Gitlab::IssuesLabels.generate(@project)
41

42 43 44 45
    if params[:redirect] == 'issues'
      redirect_to project_issues_path(@project)
    elsif params[:redirect] == 'merge_requests'
      redirect_to project_merge_requests_path(@project)
46 47
    else
      redirect_to project_labels_path(@project)
48
    end
49 50
  end

randx's avatar
randx committed
51 52 53
  protected

  def module_enabled
54 55 56
    unless @project.issues_enabled || @project.merge_requests_enabled
      return render_404
    end
randx's avatar
randx committed
57
  end
58 59 60 61 62 63 64 65 66 67 68 69

  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
randx's avatar
randx committed
70
end