Skip to content
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

Create user from string with username generated in backend #3219

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.`)
jsangmeister marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading