debian-mirror-gitlab/app/controllers/abuse_reports_controller.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
class AbuseReportsController < ApplicationController
2017-09-10 17:25:29 +05:30
before_action :set_user, only: [:new]
2015-09-11 14:41:01 +05:30
def new
@abuse_report = AbuseReport.new
2017-09-10 17:25:29 +05:30
@abuse_report.user_id = @user.id
@ref_url = params.fetch(:ref_url, '')
2015-09-11 14:41:01 +05:30
end
def create
@abuse_report = AbuseReport.new(report_params)
@abuse_report.reporter = current_user
if @abuse_report.save
@abuse_report.notify
2015-10-24 18:46:33 +05:30
2015-09-11 14:41:01 +05:30
message = "Thank you for your report. A GitLab administrator will look into it shortly."
redirect_to @abuse_report.user, notice: message
2015-09-11 14:41:01 +05:30
else
render :new
end
end
private
def report_params
params.require(:abuse_report).permit(%i(
message
user_id
))
2015-09-11 14:41:01 +05:30
end
2017-09-10 17:25:29 +05:30
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-09-10 17:25:29 +05:30
def set_user
@user = User.find_by(id: params[:user_id])
if @user.nil?
redirect_to root_path, alert: "Cannot create the abuse report. The user has been deleted."
elsif @user.blocked?
redirect_to @user, alert: "Cannot create the abuse report. This user has been blocked."
end
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2015-09-11 14:41:01 +05:30
end