summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/issuable_actions.rb
blob: f40b62446e5ecbd223e5c7b282e25a4d9c64d31e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module IssuableActions
  extend ActiveSupport::Concern

  included do
    before_action :authorize_destroy_issuable!, only: :destroy
  end

  def destroy
    issuable.destroy

    name = issuable.class.name.titleize.downcase
    flash[:notice] = "The #{name} was successfully deleted."
    redirect_to polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable.class])
  end

  private

  def authorize_destroy_issuable!
    unless current_user.can?(:"destroy_#{issuable.to_ability_name}", issuable)
      return access_denied!
    end
  end
end