diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js
index efaa1b93c..5597c6e5a 100644
--- a/modules/client/back/methods/client/specs/updateAddress.spec.js
+++ b/modules/client/back/methods/client/specs/updateAddress.spec.js
@@ -6,6 +6,12 @@ describe('Address updateAddress', () => {
const provinceId = 5;
const incotermsId = 'FAS';
const customAgentOneId = 1;
+ const employeeId = 1;
+ const ctx = {
+ req: {
+ accessToken: {userId: employeeId}
+ }
+ };
it('should throw the non uee member error if no incoterms is defined', async() => {
const tx = await models.Client.beginTransaction({});
@@ -14,11 +20,9 @@ describe('Address updateAddress', () => {
try {
const options = {transaction: tx};
- const ctx = {
- args: {
- provinceFk: provinceId,
- customsAgentFk: customAgentOneId
- }
+ ctx.args = {
+ provinceFk: provinceId,
+ customsAgentFk: customAgentOneId
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
@@ -40,11 +44,9 @@ describe('Address updateAddress', () => {
try {
const options = {transaction: tx};
- const ctx = {
- args: {
- provinceFk: provinceId,
- incotermsFk: incotermsId
- }
+ ctx.args = {
+ provinceFk: provinceId,
+ incotermsFk: incotermsId
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
@@ -66,13 +68,11 @@ describe('Address updateAddress', () => {
const options = {transaction: tx};
const expectedResult = 'My edited address';
- const ctx = {
- args: {
- provinceFk: provinceId,
- nickname: expectedResult,
- incotermsFk: incotermsId,
- customsAgentFk: customAgentOneId
- }
+ ctx.args = {
+ provinceFk: provinceId,
+ nickname: expectedResult,
+ incotermsFk: incotermsId,
+ customsAgentFk: customAgentOneId
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
@@ -88,6 +88,48 @@ describe('Address updateAddress', () => {
}
});
+ it('should return an error for a user without enough privileges', async() => {
+ const tx = await models.Client.beginTransaction({});
+
+ try {
+ const options = {transaction: tx};
+ ctx.args = {
+ isLogifloraAllowed: true
+ };
+
+ await models.Client.updateAddress(ctx, clientId, addressId, options);
+ await tx.rollback();
+ } catch (e) {
+ await tx.rollback();
+ error = e;
+ }
+
+ expect(error.message).toEqual(`You don't have enough privileges`);
+ });
+
+ it('should update isLogifloraAllowed', async() => {
+ const tx = await models.Client.beginTransaction({});
+ const salesAssistantId = 21;
+
+ try {
+ const options = {transaction: tx};
+ ctx.req.accessToken.userId = salesAssistantId;
+ ctx.args = {
+ isLogifloraAllowed: true
+ };
+
+ await models.Client.updateAddress(ctx, clientId, addressId, options);
+ const address = await models.Address.findById(addressId, null, options);
+
+ expect(address.isLogifloraAllowed).toEqual(true);
+
+ await tx.rollback();
+ } catch (e) {
+ await tx.rollback();
+ throw e;
+ }
+ });
+
it('should update the address', async() => {
const tx = await models.Client.beginTransaction({});
@@ -95,10 +137,8 @@ describe('Address updateAddress', () => {
const options = {transaction: tx};
const expectedResult = 'My second time edited address';
- const ctx = {
- args: {
- nickname: expectedResult
- }
+ ctx.args = {
+ nickname: expectedResult
};
await models.Client.updateAddress(ctx, clientId, addressId, options);
diff --git a/modules/client/back/methods/client/updateAddress.js b/modules/client/back/methods/client/updateAddress.js
index d1a498fe7..d7e20b876 100644
--- a/modules/client/back/methods/client/updateAddress.js
+++ b/modules/client/back/methods/client/updateAddress.js
@@ -68,6 +68,10 @@ module.exports = function(Self) {
{
arg: 'isEqualizated',
type: 'boolean'
+ },
+ {
+ arg: 'isLogifloraAllowed',
+ type: 'boolean'
}
],
returns: {
@@ -83,11 +87,16 @@ module.exports = function(Self) {
Self.updateAddress = async(ctx, clientId, addressId, options) => {
const models = Self.app.models;
const args = ctx.args;
+ const userId = ctx.req.accessToken.userId;
const myOptions = {};
+ const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
if (typeof options == 'object')
Object.assign(myOptions, options);
+ if (args.isLogifloraAllowed && !isSalesAssistant)
+ throw new UserError(`You don't have enough privileges`);
+
const address = await models.Address.findOne({
where: {
id: addressId,
diff --git a/modules/client/back/models/address.json b/modules/client/back/models/address.json
index 8daac0466..dd533cb32 100644
--- a/modules/client/back/models/address.json
+++ b/modules/client/back/models/address.json
@@ -50,6 +50,9 @@
},
"isEqualizated": {
"type": "boolean"
+ },
+ "isLogifloraAllowed": {
+ "type": "boolean"
}
},
"validations": [],
diff --git a/modules/client/front/address/edit/index.html b/modules/client/front/address/edit/index.html
index 83f251de5..1f0b7d30a 100644
--- a/modules/client/front/address/edit/index.html
+++ b/modules/client/front/address/edit/index.html
@@ -38,7 +38,13 @@
label="Is equalizated"
ng-model="$ctrl.address.isEqualizated"
vn-acl="administrative, salesAssistant">
-
+
+
+
+
+