From 60e4ca132a66b04807bd098887f0cb1f24ddeb4a Mon Sep 17 00:00:00 2001
From: Carlos Jimenez <=>
Date: Wed, 7 Mar 2018 12:24:47 +0100
Subject: [PATCH] #155 web access functionality completed
---
client/client/src/web-access/web-access.html | 4 +-
client/client/src/web-access/web-access.js | 11 ++++
.../common/methods/client/isValidClient.js | 50 +++++++++++++++++++
services/loopback/common/models/client.js | 1 +
4 files changed, 65 insertions(+), 1 deletion(-)
create mode 100644 services/loopback/common/methods/client/isValidClient.js
diff --git a/client/client/src/web-access/web-access.html b/client/client/src/web-access/web-access.html
index aaeffa5ba..cd615720c 100644
--- a/client/client/src/web-access/web-access.html
+++ b/client/client/src/web-access/web-access.html
@@ -12,7 +12,9 @@
+ field="$ctrl.account.active"
+ vn-acl="employee"
+ acl-conditional-to-employee="{{$ctrl.canEnableCheckBox}}">
diff --git a/client/client/src/web-access/web-access.js b/client/client/src/web-access/web-access.js
index 41aefc0bf..00595bff4 100644
--- a/client/client/src/web-access/web-access.js
+++ b/client/client/src/web-access/web-access.js
@@ -6,11 +6,14 @@ export default class Controller {
this.$http = $http;
this.vnApp = vnApp;
this.canChangePassword = false;
+ this.canEnableCheckBox = true;
}
+
$onChanges() {
if (this.client) {
this.account = this.client.account;
this.isCustomer();
+ this.checkConditions();
}
}
@@ -24,6 +27,14 @@ export default class Controller {
}
}
+ checkConditions() {
+ if (this.client && this.client.id) {
+ this.$http.get(`/client/api/Clients/${this.client.id}/isValidClient`).then(res => {
+ this.canEnableCheckBox = res.data;
+ });
+ }
+ }
+
onPassOpen() {
this.newPassword = '';
this.repeatPassword = '';
diff --git a/services/loopback/common/methods/client/isValidClient.js b/services/loopback/common/methods/client/isValidClient.js
new file mode 100644
index 000000000..583efa299
--- /dev/null
+++ b/services/loopback/common/methods/client/isValidClient.js
@@ -0,0 +1,50 @@
+module.exports = Self => {
+ Self.remoteMethod('isValidClient', {
+ description: 'Checks if the user havent got the role employee, is active and has verified data',
+ accessType: 'READ',
+ accepts: [
+ {
+ arg: 'id',
+ type: 'string',
+ required: true,
+ description: 'The user id',
+ http: {source: 'path'}
+ }, {
+ arg: 'context',
+ type: 'object',
+ required: true,
+ description: 'Filter defining where',
+ http: function(context) {
+ return context.req.query;
+ }
+ }
+ ],
+ returns: {
+ type: 'boolean',
+ root: true
+ },
+ http: {
+ path: `/:id/isValidClient`,
+ verb: 'GET'
+ }
+ });
+
+ Self.isValidClient = async function(id) {
+ let query =
+ `SELECT r.name
+ FROM salix.Account A
+ JOIN vn.client C ON A.id = C.id
+ JOIN salix.RoleMapping rm ON rm.principalId = A.id
+ JOIN salix.Role r ON r.id = rm.roleId
+ WHERE A.id = ? AND C.isActive AND C.isTaxDataChecked`;
+
+ let roleNames = await Self.rawSql(query, [id]);
+ if (!roleNames.length) return false;
+
+ roleNames.forEach(role => {
+ if (role.name === 'employee')
+ return false;
+ });
+ return true;
+ };
+};
diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js
index 7a26ce6ff..e5202c5bf 100644
--- a/services/loopback/common/models/client.js
+++ b/services/loopback/common/models/client.js
@@ -12,6 +12,7 @@ module.exports = function(Self) {
require('../methods/client/listWorkers')(Self);
require('../methods/client/filter')(Self);
require('../methods/client/hasCustomerRole')(Self);
+ require('../methods/client/isValidClient')(Self);
require('../methods/client/activeSalesPerson')(Self);
require('../methods/client/addressesPropagateRe')(Self);