#155 web access functionality completed
This commit is contained in:
parent
7de0db5902
commit
60e4ca132a
|
@ -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>
|
||||
|
|
|
@ -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 = '';
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
};
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue