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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.3 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]
2021-01-03 14:25:43 +05:30
feature_category :users
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
2019-07-31 22:56:46 +05:30
message = _("Thank you for your report. A GitLab administrator will look into it shortly.")
2021-09-04 01:27:46 +05:30
redirect_to root_path, notice: message
2022-04-04 11:22:00 +05:30
elsif report_params[:user_id].present?
2015-09-11 14:41:01 +05:30
render :new
2022-04-04 11:22:00 +05:30
else
redirect_to root_path, alert: _("Cannot create the abuse report. The reported user was invalid. Please try again or contact support.")
2015-09-11 14:41:01 +05:30
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?
2019-07-31 22:56:46 +05:30
redirect_to root_path, alert: _("Cannot create the abuse report. The user has been deleted.")
2017-09-10 17:25:29 +05:30
elsif @user.blocked?
2019-07-31 22:56:46 +05:30
redirect_to @user, alert: _("Cannot create the abuse report. This user has been blocked.")
2017-09-10 17:25:29 +05:30
end
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2015-09-11 14:41:01 +05:30
end