Repository navigation
fix(activity): display fallback for discord display name and sync identity username #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
504150b
1625f15
08c133a
10898b0
86a99c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,9 +11,15 @@ | |||||||||
|
|
||||||||||
| final class ResolveExternalIdentity | ||||||||||
| { | ||||||||||
| /** | ||||||||||
| * Resolve ou cria uma identidade externa e sincroniza o username caso esteja ausente ou alterado. | ||||||||||
| * | ||||||||||
| * @param ResolveUserProviderDTO $dto | ||||||||||
| * @return ExternalIdentity | ||||||||||
| */ | ||||||||||
| public function handle(ResolveUserProviderDTO $dto): ExternalIdentity | ||||||||||
| { | ||||||||||
| return ExternalIdentity::query()->firstOrCreate( | ||||||||||
| $identity = ExternalIdentity::query()->firstOrCreate( | ||||||||||
| [ | ||||||||||
| 'provider' => $dto->provider, | ||||||||||
| 'external_account_id' => $dto->externalAccountId, | ||||||||||
|
|
@@ -30,5 +36,14 @@ public function handle(ResolveUserProviderDTO $dto): ExternalIdentity | |||||||||
| ]), | ||||||||||
| ] | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| $trimmedUsername = is_string($dto->username) ? trim($dto->username) : null; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,115p' app-modules/identity/src/ExternalIdentity/Actions/ResolveExternalIdentity.php
rg -n 'ResolveExternalIdentity|ExternalIdentityDTO|username' app-modules/identity/src/ExternalIdentity | head -100Repository: he4rt/heartdevs.com Length of output: 5766 🏁 Script executed: set -e
rg -n -F -- 'ResolveUserProviderDTO' app-modules
rg -n -F -- 'new ResolveUserProviderDTO' app-modules
rg -n -F -- 'metadata' app-modules/identity/src/ExternalIdentity
rg -n -F -- 'username' app-modules/identity/src/ExternalIdentity/DTOs app-modules/identity/src/ExternalIdentity/Actions app-modules/identity/src/ExternalIdentity/Models app-modules/identity/src/ExternalIdentity/CastsRepository: he4rt/heartdevs.com Length of output: 3260 🏁 Script executed: set -u
printf '%s\n' '--- DTO ---'
sed -n '1,120p' app-modules/identity/src/ExternalIdentity/DTOs/ResolveUserProviderDTO.php
printf '%s\n' '--- external identity model candidates ---'
rg -n --glob '*.php' 'class ExternalIdentity|protected .*casts|metadata' app-modules/identity/src/ExternalIdentity
printf '%s\n' '--- production DTO call sites ---'
rg -n -C 12 --glob '*.php' -F -- 'ResolveUserProviderDTO::make' app-modules/activity/src app-modules/bot-discord/src app-modules/identity/src
printf '%s\n' '--- user context ---'
sed -n '1,120p' app-modules/identity/src/User/Actions/ResolveUserContext.phpRepository: he4rt/heartdevs.com Length of output: 18350 🏁 Script executed: set -u
printf '%s\n' '--- username inputs and DTO declarations ---'
rg -n -C 8 --glob '*.php' 'providerUsername|public .*username|username.*provider|class (NewMessageDTO|NewVoiceMessageDTO|RecordVoicePresenceDTO)|function .*username' app-modules/activity/src app-modules/bot-discord/src app-modules/identity/src
printf '%s\n' '--- Discord source mappings ---'
rg -n -C 10 --glob '*.php' 'username|display_name|global_name|ResolveUserProviderDTO' app-modules/bot-discord/src
printf '%s\n' '--- model cast ---'
sed -n '130,160p' app-modules/identity/src/ExternalIdentity/Models/ExternalIdentity.php
printf '%s\n' '--- synchronization tests ---'
sed -n '1,130p' app-modules/identity/tests/Feature/ExternalIdentity/ResolveExternalIdentityTest.phpRepository: he4rt/heartdevs.com Length of output: 41588 Reject Unicode-only whitespace usernames.
🐛 Suggested fix--- "a/app-modules/identity/src/ExternalIdentity/Actions/ResolveExternalIdentity.php"
+++ "b/app-modules/identity/src/ExternalIdentity/Actions/ResolveExternalIdentity.php"
@@ -37,7 +37,9 @@
]
);
- $trimmedUsername = is_string($dto->username) ? trim($dto->username) : null;
+ $trimmedUsername = is_string($dto->username)
+ ? preg_replace('/^[\s\p{Z}]+|[\s\p{Z}]+$/u', '', $dto->username)
+ : null;
if ($trimmedUsername !== null && $trimmedUsername !== '' && ($identity->metadata['username'] ?? null) !== $trimmedUsername) {
$metadata = $identity->metadata ?? [];
$metadata['username'] = $trimmedUsername;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| if ($trimmedUsername !== null && $trimmedUsername !== '' && ($identity->metadata['username'] ?? null) !== $trimmedUsername) { | ||||||||||
| $metadata = $identity->metadata ?? []; | ||||||||||
| $metadata['username'] = $trimmedUsername; | ||||||||||
| $identity->update(['metadata' => $metadata]); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return $identity; | ||||||||||
| } | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '815,870p' app-modules/activity/src/Retrospective/DiscordSource.phpRepository: he4rt/heartdevs.com
Length of output: 1837
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 42413
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 38225
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 31181
🏁 Script executed:
Repository: he4rt/heartdevs.com
Length of output: 30955
Use Unicode-aware trimming for display-name candidates.
trim()does not remove NBSP. A metadata username containing only NBSP therefore passes the check, becomes the selected invisible name, and prevents the linked user's valid name from being used. Updating identity ingestion does not repair existing metadata rows.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents