Skip to content

Commit d5ce770

Browse files
committed
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 <opensource@fthiessen.de>
1 parent a4c60f1 commit d5ce770

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

lib/Controller/UsersController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public function create(string $email, string $displayName, string $language, arr
173173
'message' => $this->l10n->t(
174174
'User successfully created'
175175
),
176+
'username' => $username,
176177
],
177178
Http::STATUS_CREATED
178179
);

src/views/GuestForm.vue

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,7 @@ export default {
171171
172172
watch: {
173173
'guest.email': function() {
174-
if (this.guest.email) {
175-
this.guest.username = this.guest.email
176-
} else {
177-
this.guest.username = ''
178-
}
179-
180-
this.$nextTick(() => {
181-
this.resetErrors()
182-
})
174+
this.resetErrors()
183175
},
184176
},
185177
@@ -233,13 +225,16 @@ export default {
233225
234226
this.loading = true
235227
try {
236-
await axios.put(generateOcsUrl('/apps/guests/api/v1/users'), {
228+
const { data } = await axios.put(generateOcsUrl('/apps/guests/api/v1/users'), {
237229
displayName: this.guest.fullName,
238230
email: this.guest.email,
239231
language: this.guest.language,
240232
groups: this.guest.groups,
241233
})
242234
235+
// ensure the username is set - we do not know it in advance as it is generated by the backend
236+
this.guest.username = data.ocs.data.username
237+
243238
if (this.integrationApp === 'files') {
244239
await this.setupGuestShare()
245240
return

tests/unit/Controller/UsersControllerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,10 @@ public function testCreateSuccessWithGroupsAsSubadmin(): void {
707707

708708
$response = $this->controller->create('new@example.com', 'Test User', 'en', ['group1', 'group2']);
709709
$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
710-
$this->assertEquals(['message' => 'User successfully created'], $response->getData());
710+
$this->assertEquals([
711+
'message' => 'User successfully created',
712+
'username' => 'new@example.com',
713+
], $response->getData());
711714
}
712715

713716
/**

0 commit comments

Comments
 (0)