Move ban invalidation to `User#unban` method

This commit is contained in:
Karina Kwiatek 2022-06-26 11:09:55 +02:00 committed by Karina Kwiatek
parent 0c6d79ce0b
commit 3247d1c746
2 changed files with 9 additions and 5 deletions

View File

@ -234,7 +234,10 @@ class User < ApplicationRecord
end
def unban
UseCase::User::Unban.call(id)
UserBan.current.where(user_id: self.id).update_all(
# -1s to account for flakyness with timings in tests
expires_at: DateTime.now - 1.second
)
end
# Bans a user.

View File

@ -8,10 +8,11 @@ module UseCase
param :target_user_id, type: Types::Coercible::Integer
def call
UserBan.current.where(user_id: target_user_id).update_all(
# -1s to account for flakyness with timings in tests
expires_at: DateTime.now - 1.second
)
target_user.unban
end
def target_user
@target_user ||= ::User.find(target_user_id)
end
end
end