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

trust_score.rb « abuse « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e8b7ed66861c64887414df138a269a40e431766 (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
# frozen_string_literal: true

module Abuse
  class TrustScore < ApplicationRecord
    self.table_name = 'abuse_trust_scores'

    enum source: Enums::Abuse::Source.sources

    belongs_to :user

    validates :user, presence: true
    validates :score, presence: true
    validates :source, presence: true

    scope :order_created_at_asc, -> { order(created_at: :asc) }
    scope :order_created_at_desc, -> { order(created_at: :desc) }

    before_create :assign_correlation_id
    after_commit :remove_old_scores

    private

    def assign_correlation_id
      self.correlation_id_value ||= (Labkit::Correlation::CorrelationId.current_id || '')
    end

    def remove_old_scores
      Abuse::UserTrustScore.new(user).remove_old_scores(source)
    end
  end
end