From d5ce770d720e2705feffc0df7c7cca58890e88c9 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 19 May 2026 17:34:50 +0200 Subject: [PATCH] fix: apply username from backend instead of guessing The username (userId) is generated on the backend, sometimes it is the email, but sometimes it is hashed. So we need to return the created userId and then use this one for the setting up following shares. Signed-off-by: Ferdinand Thiessen --- lib/Controller/UsersController.php | 1 + src/views/GuestForm.vue | 15 +++++---------- tests/unit/Controller/UsersControllerTest.php | 5 ++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/Controller/UsersController.php b/lib/Controller/UsersController.php index e3a3a0c8..441eab21 100644 --- a/lib/Controller/UsersController.php +++ b/lib/Controller/UsersController.php @@ -173,6 +173,7 @@ public function create(string $email, string $displayName, string $language, arr 'message' => $this->l10n->t( 'User successfully created' ), + 'username' => $username, ], Http::STATUS_CREATED ); diff --git a/src/views/GuestForm.vue b/src/views/GuestForm.vue index 666b2c0f..e3d4aba3 100644 --- a/src/views/GuestForm.vue +++ b/src/views/GuestForm.vue @@ -171,15 +171,7 @@ export default { watch: { 'guest.email': function() { - if (this.guest.email) { - this.guest.username = this.guest.email - } else { - this.guest.username = '' - } - - this.$nextTick(() => { - this.resetErrors() - }) + this.resetErrors() }, }, @@ -233,13 +225,16 @@ export default { this.loading = true try { - await axios.put(generateOcsUrl('/apps/guests/api/v1/users'), { + const { data } = await axios.put(generateOcsUrl('/apps/guests/api/v1/users'), { displayName: this.guest.fullName, email: this.guest.email, language: this.guest.language, groups: this.guest.groups, }) + // ensure the username is set - we do not know it in advance as it is generated by the backend + this.guest.username = data.ocs.data.username + if (this.integrationApp === 'files') { await this.setupGuestShare() return diff --git a/tests/unit/Controller/UsersControllerTest.php b/tests/unit/Controller/UsersControllerTest.php index 67cdc4f7..e47ada89 100644 --- a/tests/unit/Controller/UsersControllerTest.php +++ b/tests/unit/Controller/UsersControllerTest.php @@ -707,7 +707,10 @@ public function testCreateSuccessWithGroupsAsSubadmin(): void { $response = $this->controller->create('new@example.com', 'Test User', 'en', ['group1', 'group2']); $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); - $this->assertEquals(['message' => 'User successfully created'], $response->getData()); + $this->assertEquals([ + 'message' => 'User successfully created', + 'username' => 'new@example.com', + ], $response->getData()); } /**