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()); } /**