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

fix: display and edit the b2b user's active status #397

Merged
merged 3 commits into from
Oct 8, 2020
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 @@ -19,9 +19,13 @@
required: 'account.user.new.lastname.error.required'
}"
></ish-input>
<div class="offset-md-4 col-md-8">
<ish-checkbox [form]="form" controlName="active" label="account.user.active.label"></ish-checkbox>
</div>
</fieldset>
<fieldset *ngIf="form.value.email !== undefined">
<fieldset>
<ish-input
*ngIf="form.value.email !== undefined"
[form]="form"
controlName="email"
label="account.user.email.label"
Expand All @@ -30,8 +34,6 @@
email: 'account.update_email.email.error.email'
}"
></ish-input>
</fieldset>
<fieldset>
<ish-input [form]="form" controlName="phone" label="account.profile.phone.label"></ish-input>
</fieldset>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { instance, mock, when } from 'ts-mockito';
import { AppFacade } from 'ish-core/facades/app.facade';
import { Locale } from 'ish-core/models/locale/locale.model';
import { ErrorMessageComponent } from 'ish-shared/components/common/error-message/error-message.component';
import { CheckboxComponent } from 'ish-shared/forms/components/checkbox/checkbox.component';
import { InputComponent } from 'ish-shared/forms/components/input/input.component';
import { SelectTitleComponent } from 'ish-shared/forms/components/select-title/select-title.component';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';
Expand All @@ -28,6 +29,7 @@ describe('User Profile Form Component', () => {
await TestBed.configureTestingModule({
imports: [ReactiveFormsModule, RouterTestingModule, TranslateModule.forRoot()],
declarations: [
MockComponent(CheckboxComponent),
MockComponent(ErrorMessageComponent),
MockComponent(InputComponent),
MockComponent(SelectTitleComponent),
Expand Down Expand Up @@ -61,5 +63,6 @@ describe('User Profile Form Component', () => {
expect(element.querySelector('[controlname=firstName]')).toBeTruthy();
expect(element.querySelector('[controlname=lastName]')).toBeTruthy();
expect(element.querySelector('[controlname=phone]')).toBeTruthy();
expect(element.querySelector('[controlname=active]')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Attribute } from 'ish-core/models/attribute/attribute.model';
import { Link } from 'ish-core/models/link/link.model';
import { UserData } from 'ish-core/models/user/user.interface';

export interface B2bUserData {
login: string;
attributes: Attribute[];
}
export type B2bUserData = UserData & { active: boolean };

export type B2bUserDataLink = Link & { login: string };
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Address } from 'ish-core/models/address/address.model';
import { PaymentInstrument } from 'ish-core/models/payment-instrument/payment-instrument.model';
import { UserData } from 'ish-core/models/user/user.interface';
import { BasketMockData } from 'ish-core/utils/dev/basket-mock-data';

import { B2bUserData } from './b2b-user.interface';
import { B2bUserData, B2bUserDataLink } from './b2b-user.interface';
import { B2bUserMapper } from './b2b-user.mapper';

describe('B2b User Mapper', () => {
Expand All @@ -15,11 +14,13 @@ describe('B2b User Mapper', () => {
preferredInvoiceToAddress: BasketMockData.getAddress(),
preferredShipToAddress: { urn: 'urn:1234' } as Address,
preferredPaymentInstrument: { id: '1234' } as PaymentInstrument,
} as UserData;
active: true,
} as B2bUserData;
const user = B2bUserMapper.fromData(userData);

expect(user).toMatchInlineSnapshot(`
Object {
"active": true,
"birthday": undefined,
"businessPartnerNo": undefined,
"department": undefined,
Expand Down Expand Up @@ -54,7 +55,7 @@ describe('B2b User Mapper', () => {
{ name: 'firstName', value: 'Patricia' },
{ name: 'lastName', value: 'Miller' },
],
} as B2bUserData,
} as B2bUserDataLink,
];
const users = B2bUserMapper.fromListData(userListData);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { AttributeHelper } from 'ish-core/models/attribute/attribute.helper';
import { UserData } from 'ish-core/models/user/user.interface';
import { UserMapper } from 'ish-core/models/user/user.mapper';

import { B2bUserData } from './b2b-user.interface';
import { B2bUserData, B2bUserDataLink } from './b2b-user.interface';
import { B2bUser } from './b2b-user.model';

export class B2bUserMapper {
static fromData(user: UserData): B2bUser {
return UserMapper.fromData(user);
static fromData(user: B2bUserData): B2bUser {
return { ...UserMapper.fromData(user), active: user.active };
}

static fromListData(data: B2bUserData[]): B2bUser[] {
static fromListData(data: B2bUserDataLink[]): B2bUser[] {
if (data) {
return data.map(e => ({
login: e.login,
firstName: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'firstName'),
lastName: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'lastName'),
roleIDs: AttributeHelper.getAttributeValueByAttributeName(e.attributes, 'roleIDs'),
// ToDo: #IS-31051: map the active flag
dhhyi marked this conversation as resolved.
Show resolved Hide resolved
}));
} else {
throw new Error('data is required');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { User } from 'ish-core/models/user/user.model';

export interface B2bUser extends Partial<User> {
roleIDs?: string[];
active?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('User Create Page Component', () => {
lastName: ['Boldner', [Validators.required]],
email: ['test@gmail.com', [Validators.required, SpecialValidators.email]],
preferredLanguage: ['en_US', [Validators.required]],
active: [true],
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class UserCreatePageComponent implements OnInit {
firstName: ['', [Validators.required]],
lastName: ['', [Validators.required]],
email: ['', [Validators.required, SpecialValidators.email]],
active: [true],
phone: [''],
birthday: [''],
preferredLanguage: ['en_US', [Validators.required]],
Expand Down Expand Up @@ -59,6 +60,7 @@ export class UserCreatePageComponent implements OnInit {
firstName: formValue.profile.firstName,
lastName: formValue.profile.lastName,
email: formValue.profile.email,
active: formValue.profile.active,
phoneHome: formValue.profile.phone,
birthday: formValue.profile.birthday === '' ? undefined : formValue.birthday, // TODO: see IS-22276
preferredLanguage: formValue.profile.preferredLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ <h3>{{ 'account.user.details.profile.heading' | translate }}</h3>
<dt class="col-md-4">{{ 'account.user.details.profile.name' | translate }}</dt>
<dd data-testing-id="name-field" class="col-md-8">
<ng-container *ngIf="user.title">{{ user.title }} </ng-container> {{ user.firstName }} {{ user.lastName }}
<span *ngIf="user.active === false" class="input-help">{{
'account.user.list.status.inactive' | translate
}}</span>
</dd>
<dt class="col-md-4">{{ 'account.user.details.profile.email' | translate }}</dt>
<dd data-testing-id="email-field" class="col-md-8">{{ user.email }}</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('User Edit Profile Page Component', () => {
title: [component.user.title, [Validators.required]],
firstName: [component.user.firstName, [Validators.required]],
lastName: [component.user.lastName, [Validators.required]],
active: [true],
preferredLanguage: [component.user.preferredLanguage, [Validators.required]],
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class UserEditProfilePageComponent implements OnInit, OnDestroy {
title: [userProfile.title ? userProfile.title : ''],
firstName: [userProfile.firstName, [Validators.required]],
lastName: [userProfile.lastName, [Validators.required]],
active: [userProfile.active],
phone: [userProfile.phoneHome],
});
}
Expand All @@ -67,6 +68,7 @@ export class UserEditProfilePageComponent implements OnInit, OnDestroy {
title: formValue.title,
firstName: formValue.firstName,
lastName: formValue.lastName,
active: formValue.active,
phoneHome: formValue.phone,
};
this.organizationManagementFacade.updateUser(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ <h1>
<ng-container *ngFor="let user of users$ | async">
<div *ngIf="user" class="list-item-row row mx-0">
<div class="col-3 list-item">
<a [routerLink]="[user.login]">{{ user.firstName }} {{ user.lastName }}</a>
<a [routerLink]="[user.login]" class="d-block">{{ user.firstName }} {{ user.lastName }}</a>
<span *ngIf="user.active === false" class="input-help">{{
'account.user.list.status.inactive' | translate
}}</span>
</div>
<div class="col-6 list-item">
<dl [attr.data-testing-id]="'user-roles-' + user.login">
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
"account.update_profile.phone.error.maxlength": "Die Telefonnummer darf nicht länger als 20 Zeichen sein.",
"account.update_profile.phone.label": "Telefon",
"account.update_profile.text": "Sie können Ihr persönliches Profil im Folgenden aktualisieren.",
"account.user.active.label": "Aktiv",
"account.user.breadcrumbs.new_user.text": "Neuer Benutzer",
"account.user.delete_user.confirmation": "Der Benutzer wurde gelöscht.",
"account.user.delete_user_dialog.are_you_sure_paragraph": "Wollen Sie diesen Benutzer wirklich entfernen?",
Expand All @@ -425,6 +426,7 @@
"account.user.email.invalid.error": "Bitte geben Sie eine gültige E-Mail-Adresse an.",
"account.user.email.label": "E-Mail",
"account.user.list.link.add_user": "Benutzer hinzufügen",
"account.user.list.status.inactive": "(Inaktiv)",
"account.user.login.error.required": "Bitte geben Sie einen Anmeldenamen an.",
"account.user.login.invalid.error": "Bitte geben Sie einen gültigen Anmeldenamen an.",
"account.user.new.Budget.error.valid": "Geben Sie einen gültigen Geldbetrag ein (Budget).",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
"account.update_profile.phone.error.maxlength": "The phone number must not exceed 20 characters.",
"account.update_profile.phone.label": "Phone",
"account.update_profile.text": "You can update your personal profile information below.",
"account.user.active.label": "Active",
"account.user.breadcrumbs.new_user.text": "New User",
"account.user.delete_user.confirmation": "The user has been deleted.",
"account.user.delete_user_dialog.are_you_sure_paragraph": "Do you really want to delete this user?",
Expand All @@ -425,6 +426,7 @@
"account.user.email.invalid.error": "Please enter a valid e-mail address.",
"account.user.email.label": "E-mail",
"account.user.list.link.add_user": "Add User",
"account.user.list.status.inactive": "(Inactive)",
"account.user.login.error.required": "Please enter a login.",
"account.user.login.invalid.error": "Please enter a valid login.",
"account.user.new.Budget.error.valid": "Please enter a valid money value (budget).",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
"account.update_profile.phone.error.maxlength": "Le numéro de téléphone ne doit pas dépasser 20 caractères.",
"account.update_profile.phone.label": "Téléphone",
"account.update_profile.text": "Vous pouvez mettre à jour les informations de votre profil personnel ci-dessous.",
"account.user.active.label": "Actif",
"account.user.breadcrumbs.new_user.text": "Nouvel utilisateur",
"account.user.delete_user.confirmation": "L’utilisateur a été supprimé.",
"account.user.delete_user_dialog.are_you_sure_paragraph": "Voulez-vous vraiment supprimer cet utilisateur?",
Expand All @@ -425,6 +426,7 @@
"account.user.email.invalid.error": "Veuillez entrer une adresse courriel valide.",
"account.user.email.label": "Courriel",
"account.user.list.link.add_user": "Ajouter un utilisateur",
"account.user.list.status.inactive": "(Inactif)",
"account.user.login.error.required": "Veuillez entrer un nom d’utilisateur.",
"account.user.login.invalid.error": "Veuillez entrer un nom d’utilisateur valide.",
"account.user.new.Budget.error.valid": "Veuillez entrer une valeur monétaire valide (budget).",
Expand Down