2020-03-26 09:07:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UpdateHighestRoleWorker
|
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-04-14 09:09:14 +00:00
|
|
|
feature_category :utilization
|
2020-03-26 09:07:52 +00:00
|
|
|
urgency :high
|
|
|
|
weight 2
|
|
|
|
|
|
|
|
idempotent!
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def perform(user_id)
|
2020-04-01 15:07:45 +00:00
|
|
|
user = User.find_by(id: user_id)
|
2020-03-26 09:07:52 +00:00
|
|
|
|
2020-04-01 15:07:45 +00:00
|
|
|
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
|
2020-03-26 09:07:52 +00:00
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
end
|