Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
feat(account.contacts): prevent contact change for in debt services
Browse files Browse the repository at this point in the history
MBE-269
  • Loading branch information
marie-j committed Aug 23, 2019
1 parent 9f1604a commit 5860de2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
18 changes: 13 additions & 5 deletions client/app/account/contacts/service/contacts-service.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import BillingService from '../../../models/BillingService.class';

import { AVAILABLE_SERVICES } from './user-contacts.constants';

Expand All @@ -13,7 +14,11 @@ export default class {
getServiceInfos(service) {
return this.OvhHttp.get(`${service.path}/${service.serviceName}/serviceInfos`, {
rootPath: 'apiv6',
});
})
.then(serviceInfos => new BillingService({
...service,
...serviceInfos,
}));
}

changeContact(service) {
Expand All @@ -29,10 +34,13 @@ export default class {

getServices() {
return this.OvhApiOvhProduct.Aapi().query().$promise
.then(services => _.filter(
services,
service => AVAILABLE_SERVICES.includes(service.category),
));
.then((services) => {
const availableServices = _.filter(
services,
service => AVAILABLE_SERVICES.includes(service.category),
);
return availableServices.map(service => new BillingService(service));
});
}

static getAvailableCategories(services) {
Expand Down
1 change: 1 addition & 0 deletions client/app/account/contacts/service/edit/edit.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import template from './edit.html';
export default {
bindings: {
changeContact: '<',
currentUser: '<',
goBack: '<',
service: '<',
},
Expand Down
7 changes: 6 additions & 1 deletion client/app/account/contacts/service/edit/edit.controller.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import _ from 'lodash';
import BillingService from '../../../../models/BillingService.class';

export default class {
/* @ngInject */
constructor($translate) {
this.$translate = $translate;
}

$onInit() {
this.editedService = new BillingService(this.service);
}

updateContacts() {
this.isUpdating = true;

return this.changeContact(this.service)
return this.changeContact(this.editedService)
.then(() => this.goBack(
this.$translate.instant('account_contacts_service_edit_success'),
))
Expand Down
22 changes: 18 additions & 4 deletions client/app/account/contacts/service/edit/edit.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<form data-ng-submit="$ctrl.updateContacts()">
<form
name="$ctrl.contactsEditForm"
novalidate
data-ng-submit="$ctrl.updateContacts()">
<oui-modal
data-heading="{{:: 'account_contacts_service_edit' | translate }}"
data-primary-label="{{:: 'account_contacts_service_edit_confirm' | translate }}"
Expand All @@ -12,14 +15,24 @@
service: $ctrl.service.serviceName
}">
</p>
<oui-message
data-ng-if="$ctrl.service.hasDebt() && $ctrl.service.hasBillingRights($ctrl.currentUser.nichandle)"
data-type="warning">
<span data-translate="account_contacts_service_edit_warn_debt"></span>
</oui-message>
<oui-message
data-ng-if="$ctrl.service.hasDebt() && $ctrl.service.hasAdminRights($ctrl.currentUser.nichandle) && !$ctrl.service.hasBillingRights($ctrl.currentUser.nichandle)"
data-type="warning">
<span data-translate="account_contacts_service_edit_warn_contact_billing"></span>
</oui-message>
<oui-field
data-label="{{:: 'account_contacts_service_edit_contact_admin' | translate }}">
<input
class="oui-input"
type="text"
id="contactAdmin"
name="contactAdmin"
data-ng-model="$ctrl.service.contactAdmin"
data-ng-model="$ctrl.editedService.contactAdmin"
required>
</oui-field>
<oui-field
Expand All @@ -29,7 +42,7 @@
type="text"
id="contactTech"
name="contactTech"
data-ng-model="$ctrl.service.contactTech"
data-ng-model="$ctrl.editedService.contactTech"
required>
</oui-field>
<oui-field
Expand All @@ -39,7 +52,8 @@
type="text"
id="contactBilling"
name="contactBilling"
data-ng-model="$ctrl.service.contactBilling"
data-ng-model="$ctrl.editedService.contactBilling"
data-ng-disabled="$ctrl.Service.hasDebt()"
required>
</oui-field>
</oui-modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"account_contacts_service_edit_cancel": "Annuler",
"account_contacts_service_edit_confirm": "Valider",
"account_contacts_service_edit_error": "Une erreur est survenue lors de la demande de changement de contact : {{ message }}",
"account_contacts_service_edit_success": "La demande de changement de contact a été efféctuée avec succès. Les contacts concernés par la demande recevront un email contenant la procédure de validation."
"account_contacts_service_edit_success": "La demande de changement de contact a été effectuée avec succès. Les contacts concernés par la demande recevront un email contenant la procédure de validation.",
"account_contacts_service_edit_warn_debt": "Le contact facturation n'est pas modifiable car il y a une facture à régler pour ce service. Pour pouvoir modifier le contact facturation, veuillez régler votre facture.",
"account_contacts_service_edit_warn_contact_billing": "Le contact facturation n'est pas modifiable car il y a une facture à régler pour ce service. Merci de contacter le contact facturation pour qu'il procède au changement."
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export default /* @ngInject */ ($stateProvider) => {
resolve: {
editContacts: /* @ngInject */ $state => service => $state.go('app.account.useraccount.contacts.services.edit', { service: service.serviceName }),
getServiceInfos: /* @ngInject */
AccountContactsService => service => AccountContactsService.getServiceInfos(service)
.then(serviceInfos => ({
...service,
...serviceInfos,
})),
AccountContactsService => service => AccountContactsService.getServiceInfos(service),
goToContacts: /* @ngInject */ ($state, $timeout, Alerter) => (message = false, type = 'success') => {
const reload = message && type === 'success';

Expand Down

0 comments on commit 5860de2

Please sign in to comment.