2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-06 08:03:27 -04:00
|
|
|
class AbuseReportsController < ApplicationController
|
2017-06-27 16:43:02 -04:00
|
|
|
before_action :set_user, only: [:new]
|
|
|
|
|
2020-10-05 17:08:47 -04:00
|
|
|
feature_category :users
|
|
|
|
|
2015-08-06 08:03:27 -04:00
|
|
|
def new
|
|
|
|
@abuse_report = AbuseReport.new
|
2017-06-27 16:43:02 -04:00
|
|
|
@abuse_report.user_id = @user.id
|
2016-01-12 12:36:28 -05:00
|
|
|
@ref_url = params.fetch(:ref_url, '')
|
2015-08-06 08:03:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@abuse_report = AbuseReport.new(report_params)
|
|
|
|
@abuse_report.reporter = current_user
|
|
|
|
|
|
|
|
if @abuse_report.save
|
2016-01-04 18:59:42 -05:00
|
|
|
@abuse_report.notify
|
2015-10-18 05:58:45 -04:00
|
|
|
|
2019-04-08 10:17:45 -04:00
|
|
|
message = _("Thank you for your report. A GitLab administrator will look into it shortly.")
|
2016-01-04 18:46:43 -05:00
|
|
|
redirect_to @abuse_report.user, notice: message
|
2015-08-06 08:03:27 -04:00
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def report_params
|
2016-01-04 18:46:43 -05:00
|
|
|
params.require(:abuse_report).permit(%i(
|
|
|
|
message
|
|
|
|
user_id
|
|
|
|
))
|
2015-08-06 08:03:27 -04:00
|
|
|
end
|
2017-06-27 16:43:02 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-06-27 16:43:02 -04:00
|
|
|
def set_user
|
|
|
|
@user = User.find_by(id: params[:user_id])
|
|
|
|
|
|
|
|
if @user.nil?
|
2019-04-08 10:17:45 -04:00
|
|
|
redirect_to root_path, alert: _("Cannot create the abuse report. The user has been deleted.")
|
2017-06-27 16:43:02 -04:00
|
|
|
elsif @user.blocked?
|
2019-04-08 10:17:45 -04:00
|
|
|
redirect_to @user, alert: _("Cannot create the abuse report. This user has been blocked.")
|
2017-06-27 16:43:02 -04:00
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-08-06 08:03:27 -04:00
|
|
|
end
|