Skip to content

Commit

Permalink
Change user name fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel committed Mar 27, 2024
1 parent 78321d0 commit 61e7282
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface AssignMeetingsPayload {
}

export interface NameInformation {
username: string;
id: Id;
first_name?: string;
last_name?: string;
}
Expand Down Expand Up @@ -271,8 +271,8 @@ export class UserRepositoryService extends BaseRepository<ViewUser, User> {
private getName(user: NameInformation): string {
const firstName = user.first_name?.trim() || ``;
const lastName = user.last_name?.trim() || ``;
const userName = user.username?.trim() || ``;
const name = firstName || lastName ? `${firstName} ${lastName}` : userName;
const name =
firstName || lastName ? `${firstName} ${lastName}` : this.translate.instant(`User`) + ` ${user.id}`;
return name?.trim() || ``;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Id } from 'src/app/domain/definitions/key-types';
import { User } from 'src/app/domain/models/users/user';
import { FullNameInformation } from 'src/app/gateways/repositories/users';
import { ImportModel } from 'src/app/infrastructure/utils/import/import-model';
import { ViewUser } from 'src/app/site/pages/meetings/view-models/view-user';
import { CreateUserNameInformation } from 'src/app/site/services/user-controller.service';

import { BaseBeforeImportHandler } from '../base-before-import-handler';
import { BeforeFindAction, CsvMapping, ImportResolveInformation } from '../import-utils';
Expand All @@ -14,7 +14,7 @@ export interface UserSearchService {
}

interface UserImportHelperService {
parseStringIntoUser(toParse: string): FullNameInformation;
parseStringIntoUser(toParse: string): CreateUserNameInformation;
getViewModelList(): ViewUser[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { ViewMeeting } from 'src/app/site/pages/meetings/view-models/view-meetin
import { ViewMeetingUser } from 'src/app/site/pages/meetings/view-models/view-meeting-user';
import { ViewUser } from 'src/app/site/pages/meetings/view-models/view-user';
import { UserService } from 'src/app/site/services/user.service';
import { UserControllerService } from 'src/app/site/services/user-controller.service';
import { CreateUserNameInformation, UserControllerService } from 'src/app/site/services/user-controller.service';
import { BackendImportRawPreview } from 'src/app/ui/modules/import-list/definitions/backend-import-preview';

import { ParticipantCommonServiceModule } from '../participant-common-service.module';
Expand Down Expand Up @@ -299,7 +299,7 @@ export class ParticipantControllerService extends BaseMeetingControllerService<V
return this.userController.getRandomPassword();
}

public parseStringIntoUser(name: string): FullNameInformation {
public parseStringIntoUser(name: string): CreateUserNameInformation {
return this.userController.parseStringIntoUser(name);
}

Expand All @@ -319,12 +319,14 @@ export class ParticipantControllerService extends BaseMeetingControllerService<V
group_ids: [this.activeMeeting?.default_group_id]
};
const identifiable = (await this.create(newUserPayload))[0];
const getNameFn = () => this.userController.getShortName(newUser);
const getNameFn = (): string => this.userController.getShortName({ id: identifiable.id, ...newUser });
return {
id: identifiable.id,
meeting_user_id: identifiable.meeting_user_id,
...newUser,
fqid: `${User.COLLECTION}/${identifiable.id}`,
number: () => ``,
structureLevels: () => ``,
getTitle: getNameFn,
getListTitle: getNameFn
};
Expand Down
24 changes: 16 additions & 8 deletions client/src/app/site/services/user-controller.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
AssignMeetingsResult,
EmailSentResult,
ExtendedUserPatchFn,
FullNameInformation,
ShortNameInformation,
UserPatchFn,
UserRepositoryService
Expand All @@ -28,6 +27,14 @@ import { ControllerServiceCollectorService } from './controller-service-collecto
*/
type StringNamingSchema = 'lastCommaFirst' | 'firstSpaceLast';

export interface CreateUserNameInformation {
username: string;
first_name?: string;
last_name?: string;
pronoun?: string;
title?: string;
}

@Injectable({
providedIn: `root`
})
Expand Down Expand Up @@ -136,7 +143,7 @@ export class UserControllerService extends BaseController<ViewUser, User> {
}

/**
* Tries to convert a given string into an user (representated by a `FullNameInformation`-object).
* Tries to convert a given string into an user (representated by a `CreateUserNameInformation`-object).
* Names that don't fit the scheme given will be entered into the first_name field.
*
* Naming schemes are:
Expand All @@ -147,17 +154,18 @@ export class UserControllerService extends BaseController<ViewUser, User> {
*
* @param inputUser A raw user string
* @param schema optional hint on how to handle the strings.
* @returns A `FullNameInformation`-object.
* @returns A `CreateUserNameInformation`-object.
*/
public parseStringIntoUser(inputUser: string, schema: StringNamingSchema = `firstSpaceLast`): FullNameInformation {
const newUser: FullNameInformation = {
public parseStringIntoUser(
inputUser: string,
schema: StringNamingSchema = `firstSpaceLast`
): CreateUserNameInformation {
const newUser: CreateUserNameInformation = {
username: ``,
number: () => ``,
structureLevels: () => ``,
first_name: ``,
last_name: ``
};
const assignName = (nameParts: string[]) => {
const assignName = (nameParts: string[]): void => {
switch (nameParts.length) {
case 1:
newUser.first_name = nameParts[0];
Expand Down

0 comments on commit 61e7282

Please sign in to comment.