chore: Removing duplicate callback to create auth token (#2624)
Removed after create callback in user model to create a new access token. This is already being taken care of by AccessTokenable module. Fixes #2620
This commit is contained in:
parent
b56512eb56
commit
e0535168a0
4 changed files with 21 additions and 2 deletions
|
@ -88,7 +88,6 @@ class User < ApplicationRecord
|
|||
|
||||
before_validation :set_password_and_uid, on: :create
|
||||
|
||||
after_create_commit :create_access_token
|
||||
after_save :update_presence_in_redis, if: :saved_change_to_availability?
|
||||
|
||||
scope :order_by_full_name, -> { order('lower(name) ASC') }
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
class RemoveDuplicateAccessTokensForExistingUsers < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
# find all models and group them on owner
|
||||
grouped_tokens = AccessToken.all.group_by(&:owner)
|
||||
grouped_tokens.each_value do |duplicates|
|
||||
# we want to keep the latest token as it is being used in all requests
|
||||
duplicates.pop
|
||||
# Remaining ones are duplicates, delete them all
|
||||
duplicates.each { |duplicate| AccessToken.find_by(id: duplicate).destroy }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_07_08_140842) do
|
||||
ActiveRecord::Schema.define(version: 2021_07_14_110714) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
|
|
|
@ -72,4 +72,12 @@ RSpec.describe User do
|
|||
expect(user.valid_sso_auth_token?(sso_auth_token)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'access token' do
|
||||
it 'creates a single access token upon user creation' do
|
||||
new_user = create(:user)
|
||||
token_count = AccessToken.where(owner: new_user).count
|
||||
expect(token_count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue