Skip to content
Snippets Groups Projects
Commit 40faaa75 authored by Douglas AC's avatar Douglas AC
Browse files

Blocking and banishing (according to the "option" parameter) users by complaint acceptance.

parent 6135156e
No related branches found
No related tags found
No related merge requests found
......@@ -41,14 +41,12 @@ class V1::ComplaintsController < ApplicationController
# POST v1/complaints
# POST v1/complaints.json
def create
params = complaint_params
@complaint = Complaint.new(params)
@complaint = Complaint.new(complaint_creation_params)
if @complaint.save
ComplaintsMailer.new_complaint_received(@complaint, @current_user).deliver_now
@complaint.complainable.treat_complaitment
@complaint.complainable.treat_complaintment
render json: @complaint, status: :created
else
......@@ -59,9 +57,8 @@ class V1::ComplaintsController < ApplicationController
# POST v1/complaints/1/reject
# POST v1/complaints/1/reject.json
def reject
@lo = LearningObject.find(@complaint.complainable_id)
@complaint.rejected!
@lo.published!
@complaint.complainable.complaint_reject(complaint_answer_params)
response = { 'status': 'complaint rejected' }
render status: :ok, json: response
end
......@@ -69,9 +66,8 @@ class V1::ComplaintsController < ApplicationController
# POST v1/complaints/1/accept
# POST v1/complaints/1/accept.json
def accept
@lo = LearningObject.find(@complaint.complainable_id)
@complaint.accepted!
@lo.destroy
@complaint.complainable.complaint_accept(complaint_answer_params)
response = { 'status': 'complaint accepted' }
render status: :ok, json: response
end
......@@ -82,10 +78,14 @@ class V1::ComplaintsController < ApplicationController
Complaint
end
def complaint_params
def complaint_creation_params
params.require(:complaint).permit(:user_id, :description,:complainable_id, :complaint_reason_id, :complainable_type)
end
def complaint_answer_params
params.require(:complaint).permit(:id, :option)
end
def set_complaint
@complaint ||= Complaint.find(params[:id])
end
......
......@@ -32,4 +32,12 @@ module Complainable
raise NotImplementedError
end
def complaint_accept(params)
raise NotImplementedError
end
def complaint_reject
raise NotImplementedError
end
end
......@@ -207,4 +207,12 @@ class LearningObject < ApplicationRecord
# if (Complaint.where(complainable_id: @complaint.complainable_id).count < 5)
self.suspended!
end
def complaint_accept(params)
self.destroy
end
def complaint_reject
self.published!
end
end
......@@ -328,4 +328,24 @@ class User < ApplicationRecord
# Change request.remote_ip to request.env["HTTP_X_REAL_IP"] in production
self.current_sign_in_ip = request.remote_ip
end
def treat_complaintment
end
def complaint_accept(params)
if params[:option] == "blocked"
self.suspended_at = Time.current
self.reactivated_at = self.suspended_at + 7.day
self.blocked!
elsif params[:option] == "banished"
self.suspended_at = Time.current
self.reactivated_at = nil
self.banished!
elsif
raise ArgumentError.new(I18n.t("error.wrong_arguments"))
end
end
def complaint_reject
end
end
......@@ -120,3 +120,6 @@ pt-BR:
plurk: Plurk
pinterest: Pinterest
email: Email
error:
wrong_arguments: "Argumentos incompatíveis."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment