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

Add participants via member number #4069

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -11,9 +11,27 @@ describe(`SearchUsersPresenterService`, () => {
let presenter: MockPresenterService;

const testUsers = [
{ id: 2, username: `johnDoe`, email: `[email protected]`, first_name: `John`, last_name: `Doe` },
{ id: 3, username: `jd`, email: `[email protected]`, first_name: `Joanna`, last_name: `Doe` },
{ id: 4, username: `johnsSecondAccount`, email: `[email protected]`, first_name: `John`, last_name: `Doe` },
{
id: 2,
username: `johnDoe`,
email: `[email protected]`,
first_name: `John`,
last_name: `Doe`
},
{
id: 3,
username: `jd`,
email: `[email protected]`,
first_name: `Joanna`,
last_name: `Doe`
},
{
id: 4,
username: `johnsSecondAccount`,
email: `[email protected]`,
first_name: `John`,
last_name: `Doe`
},
{ id: 5, username: `rando`, first_name: `Rando`, last_name: `Mized` }
];

Expand All @@ -37,7 +55,10 @@ describe(`SearchUsersPresenterService`, () => {
!search ||
typeof search !== `object` ||
Object.keys(search).some(
key => ![`username`, `saml_id`, `first_name`, `last_name`, `email`].includes(key)
key =>
![`username`, `saml_id`, `first_name`, `last_name`, `email`, `member_number`].includes(
key
)
)
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class SearchUsersPresenterService {
permissionScope,
permissionRelatedId,
searchCriteria: users.map(entry => ({
member_number: entry.member_number,
username: entry.username,
first_name: entry.first_name,
last_name: entry.last_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class UserRepositoryService extends BaseRepository<ViewUser, User> {
const data = usersToCreate.map(user => {
const meetingUsers = user.meeting_users as Partial<ViewMeetingUser>[];
return {
user: this.sanitizePayload(this.getBaseUserPayload(user)),
user: this.sanitizePayload(this.getBaseUserPayload(user), true),
...(meetingUsers && meetingUsers.length
? {
first_meeting_user: this.sanitizePayload(
Expand Down Expand Up @@ -516,9 +516,9 @@ export class UserRepositoryService extends BaseRepository<ViewUser, User> {
return this.createAction(UserAction.MERGE_TOGETHER, payload);
}

private sanitizePayload(payload: any): any {
private sanitizePayload(payload: any, create: boolean = false): any {
const temp = { ...payload };
for (const key of Object.keys(temp).filter(field => !this.isFieldAllowedToBeEmpty(field))) {
for (const key of Object.keys(temp).filter(field => !this.isFieldAllowedToBeEmpty(field, create))) {
if (typeof temp[key] === `string` && !temp[key].trim().length) {
payload[key] = undefined;
} else if (Array.isArray(temp[key])) {
Expand All @@ -533,7 +533,7 @@ export class UserRepositoryService extends BaseRepository<ViewUser, User> {
return { ...payload };
}

private isFieldAllowedToBeEmpty(field: string): boolean {
private isFieldAllowedToBeEmpty(field: string, create?: boolean): boolean {
const fields: string[] = [
`title`,
`email`,
Expand All @@ -542,9 +542,12 @@ export class UserRepositoryService extends BaseRepository<ViewUser, User> {
`comment`,
`about_me`,
`number`,
`structure_level`,
`member_number`
`structure_level`
];
if (!create) {
fields.push(`member_number`);
}

return fields.includes(field);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,26 @@ <h2>{{ 'Personal information' | translate }}</h2>
<input formControlName="last_name" matInput type="text" />
</mat-form-field>
</div>
<!-- E-Mail -->
<mat-form-field class="full-width">
<mat-label>{{ 'Email' | translate }}</mat-label>
<input autocomplete="off" formControlName="email" matInput name="email" type="email" />
<mat-error>{{ 'Please enter a valid email address!' | translate }}</mat-error>
</mat-form-field>
<div class="full-width first-line">
<!-- E-Mail -->
<mat-form-field>
<mat-label>{{ 'Email' | translate }}</mat-label>
<input
autocomplete="off"
formControlName="email"
matInput
name="email"
type="email"
/>
<mat-error>{{ 'Please enter a valid email address!' | translate }}</mat-error>
</mat-form-field>

<!-- Membership number -->
<mat-form-field>
<mat-label>{{ 'Membership number' | translate }}</mat-label>
<input formControlName="member_number" matInput type="text" />
</mat-form-field>
</div>
<!-- username -->
<mat-form-field class="full-width">
<mat-label>{{ 'Username' | translate }}</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class ParticipantCreateWizardComponent extends BaseMeetingComponent imple
username: [``],
first_name: [``],
last_name: [``],
member_number: [``],
email: [``, createEmailValidator()]
},
{
Expand Down