Refactor authentication token for new study-group-based authorization

This commit is contained in:
Sebastian Serth
2022-09-20 16:24:42 +02:00
committed by Sebastian Serth
parent cb1b163b30
commit 936c11e31f
7 changed files with 30 additions and 12 deletions

View File

@ -6,6 +6,13 @@ FactoryBot.define do
shared_secret { SecureRandom.hex(32) }
expire_at { 7.days.from_now }
after(:create) do |auth_token|
# Do not change anything if a study group was provided explicitly or user has no study groups
next if auth_token.study_group_id.present? || auth_token.user.study_groups.blank?
auth_token.update!(study_group_id: auth_token.user.study_groups.first.id)
end
trait :invalid do
expire_at { 8.days.ago }
end