2019-01-08 09:56:07 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type Abuse.
|
|
|
|
# Typical action is an user reporting an abuse on a project
|
2023-02-24 17:26:55 +01:00
|
|
|
class API::AbusesController < API::APIController
|
2016-03-23 18:39:41 +01:00
|
|
|
before_action :authenticate_user!, except: :create
|
2019-05-09 18:27:19 +02:00
|
|
|
before_action :set_abuse, only: %i[destroy]
|
|
|
|
|
|
|
|
def index
|
|
|
|
authorize Abuse
|
|
|
|
@abuses = Abuse.all
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
|
|
|
|
def create
|
|
|
|
@abuse = Abuse.new(abuse_params)
|
|
|
|
if @abuse.save
|
|
|
|
render status: :created
|
|
|
|
else
|
|
|
|
render json: @abuse.errors.full_messages, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-09 18:27:19 +02:00
|
|
|
def destroy
|
|
|
|
authorize Abuse
|
|
|
|
@abuse.destroy
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
private
|
|
|
|
|
2019-05-09 18:27:19 +02:00
|
|
|
def set_abuse
|
|
|
|
@abuse = Abuse.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
def abuse_params
|
|
|
|
params.require(:abuse).permit(:signaled_type, :signaled_id, :first_name, :last_name, :email, :message)
|
|
|
|
end
|
|
|
|
end
|