Welcome to mirror list, hosted at ThFree Co, Russian Federation.

spam_abuse_events_worker.rb « abuse « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d86e994ae47d8e8614b42caeffa496a6ba75b7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true

module Abuse
  class SpamAbuseEventsWorker
    include ApplicationWorker

    data_consistency :delayed

    idempotent!
    feature_category :instance_resiliency
    urgency :low

    def perform(params)
      params = params.with_indifferent_access

      @user = User.find_by_id(params[:user_id])
      unless @user
        logger.info(structured_payload(message: "User not found.", user_id: params[:user_id]))
        return
      end

      report_user(params)
    end

    private

    attr_reader :user

    def report_user(params)
      category = 'spam'
      reporter = Users::Internal.security_bot
      report_params = { user_id: params[:user_id],
                        reporter: reporter,
                        category: category,
                        message: 'User reported for abuse based on spam verdict' }

      abuse_report = AbuseReport.by_category(category).by_reporter_id(reporter.id).by_user_id(params[:user_id]).first

      abuse_report = AbuseReport.create!(report_params) if abuse_report.nil?

      create_abuse_event(abuse_report.id, params)
    end

    # Associate the abuse report with an abuse event
    def create_abuse_event(abuse_report_id, params)
      Abuse::Event.create!(
        abuse_report_id: abuse_report_id,
        category: :spam,
        metadata: { noteable_type: params[:noteable_type],
                    title: params[:title],
                    description: params[:description],
                    source_ip: params[:source_ip],
                    user_agent: params[:user_agent],
                    verdict: params[:verdict] },
        source: :spamcheck,
        user: user
      )
    end
  end
end