Fix admin having duplicate user after import
This commit is contained in:
committed by
Mike Dalessio
parent
f5305b2fe6
commit
d915bff326
@@ -0,0 +1,5 @@
|
||||
class EnsureAnIdentitCanOnlyHaveOneUserInAnAccount < ActiveRecord::Migration[8.2]
|
||||
def change
|
||||
add_index :users, [:account_id, :identity_id], unique: true
|
||||
end
|
||||
end
|
||||
Generated
+2
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.2].define(version: 2025_11_14_084325) do
|
||||
ActiveRecord::Schema[8.2].define(version: 2025_11_14_183203) do
|
||||
create_table "accesses", id: :uuid, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||
t.datetime "accessed_at"
|
||||
t.uuid "account_id", null: false
|
||||
@@ -692,6 +692,7 @@ ActiveRecord::Schema[8.2].define(version: 2025_11_14_084325) do
|
||||
t.string "name", null: false
|
||||
t.string "role", default: "member", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id", "identity_id"], name: "index_users_on_account_id_and_identity_id", unique: true
|
||||
t.index ["account_id", "role"], name: "index_users_on_account_id_and_role"
|
||||
t.index ["identity_id"], name: "index_users_on_identity_id"
|
||||
end
|
||||
|
||||
@@ -128,6 +128,7 @@ class Import
|
||||
}
|
||||
)
|
||||
@tenant = @account.external_account_id
|
||||
@admin = @account.users.find_by(role: :admin)
|
||||
end
|
||||
|
||||
old_join_code = import.account_join_codes.sole
|
||||
@@ -153,13 +154,17 @@ class Import
|
||||
new_identity = Identity.find_or_create_by!(email_address: membership.identity.email_address)
|
||||
end
|
||||
|
||||
new_user = User.create!(
|
||||
account: account,
|
||||
identity: new_identity,
|
||||
name: old_user.name,
|
||||
role: old_user.role,
|
||||
active: old_user.active,
|
||||
)
|
||||
new_user = if new_identity == @admin.identity
|
||||
@admin
|
||||
else
|
||||
User.create!(
|
||||
account: account,
|
||||
identity: new_identity,
|
||||
name: old_user.name,
|
||||
role: old_user.role,
|
||||
active: old_user.active,
|
||||
)
|
||||
end
|
||||
|
||||
old_settings = old_user.settings
|
||||
if old_settings
|
||||
|
||||
Reference in New Issue
Block a user