Skip to content

Commit

Permalink
Create user from string with username generated in backend (#3219)
Browse files Browse the repository at this point in the history
  • Loading branch information
reiterl authored Feb 13, 2024
1 parent 52b09eb commit 3f57302
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { BehaviorSubject } from 'rxjs';
import { MatLegacySnackBar as MatSnackBar } from '@angular/material/legacy-snack-bar';
import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, filter, firstValueFrom } from 'rxjs';
import { Permission } from 'src/app/domain/definitions/permission';
import { ModelRequestService } from 'src/app/site/services/model-request.service';
import { BaseUiComponent } from 'src/app/ui/base/base-ui-component';
Expand Down Expand Up @@ -74,7 +76,9 @@ export class ParticipantSearchSelectorComponent extends BaseUiComponent implemen
private userSortService: ParticipantListSortService,
private modelRequestService: ModelRequestService,
private activeMeeting: ActiveMeetingService,
formBuilder: UntypedFormBuilder
formBuilder: UntypedFormBuilder,
private snackBar: MatSnackBar,
private translate: TranslateService
) {
super();

Expand Down Expand Up @@ -149,9 +153,19 @@ export class ParticipantSearchSelectorComponent extends BaseUiComponent implemen
}
}

public async createNewSelectedUser(username: string): Promise<void> {
const newUserObj = await this.userRepo.createFromString(username);
public async createNewSelectedUser(name: string): Promise<void> {
const newUserObj = await this.userRepo.createFromString(name);
this.emitSelectedUser({ userId: newUserObj.id, user: newUserObj });
const user = await firstValueFrom(
this.userRepo.getViewModelObservable(newUserObj.id).pipe(filter(user => !!user))
);
this.snackBar.open(
this.translate
.instant(`A user with the username '%username%' and the first name '%first_name%' was created.`)
.replace(`%username%`, user.username)
.replace(`%first_name%`, user.first_name),
this.translate.instant(`Ok`)
);
}

private emitSelectedUser(data: UserSelectionData): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,11 @@ export class ParticipantControllerService extends BaseMeetingControllerService<V
*/
public async createFromString(name: string): Promise<RawUser> {
const newUser = this.parseStringIntoUser(name);
// we want to generate the username in the backend
newUser.username = ``;
const newUserPayload: any = {
...newUser,
is_active: true,
is_active: false,
group_ids: [this.activeMeeting?.default_group_id]
};
const identifiable = (await this.create(newUserPayload))[0];
Expand Down

0 comments on commit 3f57302

Please sign in to comment.