#155 web access functionality completed

This commit is contained in:
Carlos Jimenez 2018-03-07 12:24:47 +01:00
parent 7de0db5902
commit 60e4ca132a
4 changed files with 65 additions and 1 deletions

View File

@ -12,7 +12,9 @@
<vn-check
vn-one
label="Enable web access"
field="$ctrl.account.active">
field="$ctrl.account.active"
vn-acl="employee"
acl-conditional-to-employee="{{$ctrl.canEnableCheckBox}}">
</vn-check>
</vn-horizontal>
<vn-horizontal>

View File

@ -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 = '';

View File

@ -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;
};
};

View File

@ -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);