fix(portal): preserve device name (#9393) (#9401)

When upserting a client, the device name would overwrite any name
changes performed by the admin. To prevent this, we don't allow changing
a device's name on upsert conflicts, only on initial insert and updates.

Fixes #8536

Co-authored-by: Antoine <antoinelabarussias@gmail.com>
This commit is contained in:
Jamil
2025-06-04 12:41:48 -07:00
committed by GitHub
parent 0e630932a9
commit 443e6d2891
2 changed files with 1 additions and 2 deletions

View File

@@ -19,7 +19,6 @@ defmodule Domain.Clients.Client.Changeset do
Clients.Client.Query.all()
|> update([clients: clients],
set: [
name: fragment("EXCLUDED.name"),
public_key: fragment("EXCLUDED.public_key"),
last_used_token_id: fragment("EXCLUDED.last_used_token_id"),
last_seen_user_agent: fragment("EXCLUDED.last_seen_user_agent"),

View File

@@ -497,7 +497,7 @@ defmodule Domain.ClientsTest do
assert Repo.aggregate(Clients.Client, :count, :id) == 1
assert updated_client.name != client.name
assert updated_client.name == client.name
assert updated_client.last_seen_remote_ip.address == subject.context.remote_ip
assert updated_client.last_seen_remote_ip != client.last_seen_remote_ip
assert updated_client.last_seen_user_agent == subject.context.user_agent