summaryrefslogtreecommitdiff
path: root/app/controllers/projects/triggers_controller.rb
blob: 782ebd01b055dc7298ee3fb6a0ddcee81a801529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Projects::TriggersController < Projects::ApplicationController
  before_action :ci_project
  before_action :authorize_admin_project!

  layout 'project_settings'

  def index
    @triggers = @ci_project.triggers
    @trigger = Ci::Trigger.new
  end

  def create
    @trigger = @ci_project.triggers.new
    @trigger.save

    if @trigger.valid?
      redirect_to namespace_project_triggers_path(@project.namespace, @project)
    else
      @triggers = @ci_project.triggers.select(&:persisted?)
      render :index
    end
  end

  def destroy
    trigger.destroy

    redirect_to namespace_project_triggers_path(@project.namespace, @project)
  end

  private

  def trigger
    @trigger ||= @ci_project.triggers.find(params[:id])
  end
end