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

66 lines
1.7 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
2023-07-07 10:43:13 +05:30
before_action :set_user, only: [:add_category]
2017-09-10 17:25:29 +05:30
2023-03-04 22:38:38 +05:30
feature_category :insider_threat
2021-01-03 14:25:43 +05:30
2023-03-17 16:20:25 +05:30
def add_category
@abuse_report = AbuseReport.new(
user_id: @user.id,
category: report_params[:category],
reported_from_url: report_params[:reported_from_url]
)
2023-04-23 21:23:45 +05:30
Gitlab::Tracking.event(
'ReportAbuse',
'select_abuse_category',
property: report_params[:category],
user: @user
)
2023-03-17 16:20:25 +05:30
render :new
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
2023-04-23 21:23:45 +05:30
Gitlab::Tracking.event(
'ReportAbuse',
'submit_form',
property: @abuse_report.category,
user: @abuse_report.user
)
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
2023-06-20 00:43:36 +05:30
params.require(:abuse_report).permit(:message, :user_id, :category, :reported_from_url, :screenshot, links_to_spam: [])
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