2016-03-21 13:12:52 +00:00
|
|
|
module IssuableActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
before_action :authorize_destroy_issuable!, only: :destroy
|
2016-09-06 12:49:49 +00:00
|
|
|
before_action :authorize_admin_issuable!, only: :bulk_update
|
2016-03-21 13:12:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
issuable.destroy
|
2016-09-01 22:12:05 +00:00
|
|
|
destroy_method = "destroy_#{issuable.class.name.underscore}".to_sym
|
|
|
|
TodoService.new.public_send(destroy_method, issuable, current_user)
|
2016-03-21 13:12:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-09-06 12:49:49 +00:00
|
|
|
def bulk_update
|
|
|
|
result = Issuable::BulkUpdateService.new(project, current_user, bulk_update_params).execute(resource_name)
|
|
|
|
quantity = result[:count]
|
|
|
|
|
|
|
|
render json: { notice: "#{quantity} #{resource_name.pluralize(quantity)} updated" }
|
|
|
|
end
|
|
|
|
|
2016-03-21 13:12:52 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def authorize_destroy_issuable!
|
2016-09-08 12:33:53 +00:00
|
|
|
unless can?(current_user, :"destroy_#{issuable.to_ability_name}", issuable)
|
2016-03-21 13:12:52 +00:00
|
|
|
return access_denied!
|
|
|
|
end
|
|
|
|
end
|
2016-09-06 12:49:49 +00:00
|
|
|
|
|
|
|
def authorize_admin_issuable!
|
2016-09-08 12:33:53 +00:00
|
|
|
unless can?(current_user, :"admin_#{resource_name}", @project)
|
2016-09-06 12:49:49 +00:00
|
|
|
return access_denied!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bulk_update_params
|
|
|
|
params.require(:update).permit(
|
|
|
|
:issuable_ids,
|
|
|
|
:assignee_id,
|
|
|
|
:milestone_id,
|
|
|
|
:state_event,
|
|
|
|
:subscription_event,
|
|
|
|
label_ids: [],
|
|
|
|
add_label_ids: [],
|
|
|
|
remove_label_ids: []
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def resource_name
|
|
|
|
@resource_name ||= controller_name.singularize
|
|
|
|
end
|
2016-03-21 13:12:52 +00:00
|
|
|
end
|