summaryrefslogtreecommitdiff
path: root/app/workers/update_highest_role_worker.rb
blob: 1e2c974b6e5d5744be8ed8444743850a97f8a6af (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
# frozen_string_literal: true

class UpdateHighestRoleWorker
  include ApplicationWorker

  feature_category :authentication_and_authorization
  urgency :high
  weight 2

  idempotent!

  # rubocop: disable CodeReuse/ActiveRecord
  def perform(user_id)
    user = User.find_by(id: user_id)

    return unless user.present?

    if user.active? && user.user_type.nil? && !user.internal?
      Users::UpdateHighestMemberRoleService.new(user).execute
    else
      UserHighestRole.where(user_id: user_id).delete_all
    end
  end
  # rubocop: enable CodeReuse/ActiveRecord
end