Merge pull request '5468-account_privileges' (!1552) from 5468-account_privileges into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1552
Reviewed-by: Juan Ferrer <juan@verdnatura.es>
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Vicent Llopis 2023-06-20 12:48:34 +00:00
commit 56917fbfc4
32 changed files with 215 additions and 99 deletions

View File

@ -12,6 +12,8 @@ module.exports = function(Self) {
require('../methods/vn-user/privileges')(Self); require('../methods/vn-user/privileges')(Self);
require('../methods/vn-user/renew-token')(Self); require('../methods/vn-user/renew-token')(Self);
Self.definition.settings.acls = Self.definition.settings.acls.filter(acl => acl.property !== 'create');
// Validations // Validations
Self.validatesFormatOf('email', { Self.validatesFormatOf('email', {

View File

@ -118,5 +118,24 @@
"principalId": "$authenticated", "principalId": "$authenticated",
"permission": "ALLOW" "permission": "ALLOW"
} }
] ],
"scopes": {
"preview": {
"fields": [
"id",
"name",
"username",
"roleFk",
"nickname",
"lang",
"active",
"created",
"updated",
"image",
"hasGrant",
"realm",
"email"
]
}
}
} }

View File

@ -1,6 +1,5 @@
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
VALUES VALUES
('VnUser', '*', '*', 'ALLOW', 'ROLE', 'employee'),
('VnUser','acl','READ','ALLOW','ROLE','account'), ('VnUser','acl','READ','ALLOW','ROLE','account'),
('VnUser','getCurrentUserData','READ','ALLOW','ROLE','account'), ('VnUser','getCurrentUserData','READ','ALLOW','ROLE','account'),
('VnUser','changePassword', 'WRITE', 'ALLOW', 'ROLE', 'account'), ('VnUser','changePassword', 'WRITE', 'ALLOW', 'ROLE', 'account'),

View File

@ -0,0 +1,8 @@
DELETE
FROM `salix`.`ACL`
WHERE model='Account' AND property='*' AND accessType='*';
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
VALUES
('Account', '*', 'WRITE', 'ALLOW', 'ROLE', 'sysadmin'),
('Account', '*', 'READ', 'ALLOW', 'ROLE', 'employee');

View File

@ -0,0 +1,5 @@
DELETE FROM `salix`.`ACL` WHERE model = 'MailAliasAccount';
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('MailAliasAccount', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
('MailAliasAccount', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');

View File

@ -0,0 +1,5 @@
DELETE FROM `salix`.`ACL` WHERE model = 'MailForward';
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('MailForward', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
('MailForward', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');

View File

@ -0,0 +1,5 @@
DELETE FROM `salix`.`ACL` WHERE model = 'Role';
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('Role', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Role', '*', 'WRITE', 'ALLOW', 'ROLE', 'it');

View File

@ -0,0 +1,10 @@
DELETE
FROM `salix`.`ACL`
WHERE model = 'VnUser' AND property = '*' AND principalId = 'employee';
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
VALUES
('VnUser', '*', '*', 'ALLOW', 'ROLE', 'itManagement'),
('VnUser', '__get__preview', 'READ', 'ALLOW', 'ROLE', 'employee'),
('VnUser', 'preview', '*', 'ALLOW', 'ROLE', 'employee'),
('VnUser', 'create', '*', 'ALLOW', 'ROLE', 'itManagement');

View File

@ -53,7 +53,7 @@ describe('Worker create path', () => {
expect(message.text).toContain('Data saved!'); expect(message.text).toContain('Data saved!');
// 'rollback' // 'rollback'
await page.loginAndModule('sysadmin', 'account'); await page.loginAndModule('itManagement', 'account');
await page.accessToSearchResult(newWorker); await page.accessToSearchResult(newWorker);
await page.waitToClick(selectors.accountDescriptor.menuButton); await page.waitToClick(selectors.accountDescriptor.menuButton);

View File

@ -8,7 +8,7 @@ describe('Account create and basic data path', () => {
beforeAll(async() => { beforeAll(async() => {
browser = await getBrowser(); browser = await getBrowser();
page = browser.page; page = browser.page;
await page.loginAndModule('developer', 'account'); await page.loginAndModule('itManagement', 'account');
}); });
afterAll(async() => { afterAll(async() => {

View File

@ -17,7 +17,9 @@
<vn-icon-button <vn-icon-button
icon="delete" icon="delete"
translate-attr="{title: 'Unsubscribe'}" translate-attr="{title: 'Unsubscribe'}"
ng-click="removeConfirm.show(row)"> ng-click="removeConfirm.show(row)"
vn-acl="itManagement"
vn-acl-action="remove">
</vn-icon-button> </vn-icon-button>
</vn-item-section> </vn-item-section>
</vn-item> </vn-item>
@ -30,9 +32,11 @@
translate-attr="{title: 'Add'}" translate-attr="{title: 'Add'}"
vn-bind="+" vn-bind="+"
ng-click="$ctrl.onAddClick()" ng-click="$ctrl.onAddClick()"
fixed-bottom-right> fixed-bottom-right
vn-acl="itManagement"
vn-acl-action="remove">
</vn-float-button> </vn-float-button>
<vn-dialog <vn-dialog
vn-id="dialog" vn-id="dialog"
on-accept="$ctrl.onAddSave()"> on-accept="$ctrl.onAddSave()">
<tpl-body> <tpl-body>
@ -49,7 +53,7 @@
<button response="accept" translate>Save</button> <button response="accept" translate>Save</button>
</tpl-buttons> </tpl-buttons>
</vn-dialog> </vn-dialog>
<vn-confirm <vn-confirm
vn-id="removeConfirm" vn-id="removeConfirm"
message="User will be removed from alias" message="User will be removed from alias"
question="Are you sure you want to continue?" question="Are you sure you want to continue?"

View File

@ -5,6 +5,7 @@ import './style.scss';
class Controller extends ModuleCard { class Controller extends ModuleCard {
reload() { reload() {
const filter = { const filter = {
where: {id: this.$params.id},
include: { include: {
relation: 'role', relation: 'role',
scope: { scope: {
@ -14,8 +15,11 @@ class Controller extends ModuleCard {
}; };
return Promise.all([ return Promise.all([
this.$http.get(`VnUsers/${this.$params.id}`, {filter}) this.$http.get(`VnUsers/preview`, {filter})
.then(res => this.user = res.data), .then(res => {
const [user] = res.data;
this.user = user;
}),
this.$http.get(`Accounts/${this.$params.id}/exists`) this.$http.get(`Accounts/${this.$params.id}/exists`)
.then(res => this.hasAccount = res.data.exists) .then(res => this.hasAccount = res.data.exists)
]); ]);

View File

@ -15,12 +15,12 @@ describe('component vnUserCard', () => {
it('should reload the controller data', () => { it('should reload the controller data', () => {
controller.$params.id = 1; controller.$params.id = 1;
$httpBackend.expectGET('VnUsers/1').respond('foo'); $httpBackend.expectGET('VnUsers/preview').respond('foo');
$httpBackend.expectGET('Accounts/1/exists').respond({exists: true}); $httpBackend.expectGET('Accounts/1/exists').respond({exists: true});
controller.reload(); controller.reload();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.user).toBe('foo'); expect(controller.user).toBe('f');
expect(controller.hasAccount).toBeTruthy(); expect(controller.hasAccount).toBeTruthy();
}); });
}); });

View File

@ -12,18 +12,18 @@
<vn-card class="vn-pa-lg"> <vn-card class="vn-pa-lg">
<vn-vertical> <vn-vertical>
<vn-textfield <vn-textfield
label="Name" label="Name"
ng-model="$ctrl.user.name" ng-model="$ctrl.user.name"
rule="VnUser" rule="VnUser"
vn-focus> vn-focus>
</vn-textfield> </vn-textfield>
<vn-textfield <vn-textfield
label="Nickname" label="Nickname"
ng-model="$ctrl.user.nickname" ng-model="$ctrl.user.nickname"
rule="VnUser"> rule="VnUser">
</vn-textfield> </vn-textfield>
<vn-textfield <vn-textfield
label="Email" label="Email"
ng-model="$ctrl.user.email" ng-model="$ctrl.user.email"
rule="VnUser"> rule="VnUser">
</vn-textfield> </vn-textfield>
@ -39,7 +39,7 @@
type="password"> type="password">
</vn-textfield> </vn-textfield>
<vn-check <vn-check
label="Active" label="Active"
ng-model="$ctrl.user.active"> ng-model="$ctrl.user.active">
</vn-check> </vn-check>
</vn-vertical> </vn-vertical>

View File

@ -2,6 +2,11 @@ import ngModule from '../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
export default class Controller extends Section { export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.user = {active: true};
}
onSubmit() { onSubmit() {
return this.$.watcher.submit().then(res => { return this.$.watcher.submit().then(res => {
this.$state.go('account.card.basicData', {id: res.data.id}); this.$state.go('account.card.basicData', {id: res.data.id});

View File

@ -6,7 +6,7 @@
<vn-item <vn-item
ng-click="deleteUser.show()" ng-click="deleteUser.show()"
name="deleteUser" name="deleteUser"
vn-acl="it" vn-acl="itManagement"
vn-acl-action="remove" vn-acl-action="remove"
translate> translate>
Delete Delete
@ -15,7 +15,7 @@
ng-if="::$root.user.id == $ctrl.id" ng-if="::$root.user.id == $ctrl.id"
ng-click="$ctrl.onChangePassClick(true)" ng-click="$ctrl.onChangePassClick(true)"
name="changePassword" name="changePassword"
vn-acl="hr" vn-acl="sysadmin"
vn-acl-action="remove" vn-acl-action="remove"
translate> translate>
Change password Change password
@ -23,7 +23,7 @@
<vn-item <vn-item
ng-click="$ctrl.onChangePassClick(false)" ng-click="$ctrl.onChangePassClick(false)"
name="setPassword" name="setPassword"
vn-acl="hr" vn-acl="sysadmin"
vn-acl-action="remove" vn-acl-action="remove"
translate> translate>
Set password Set password
@ -32,7 +32,7 @@
ng-if="!$ctrl.hasAccount" ng-if="!$ctrl.hasAccount"
ng-click="enableAccount.show()" ng-click="enableAccount.show()"
name="enableAccount" name="enableAccount"
vn-acl="it" vn-acl="sysadmin"
vn-acl-action="remove" vn-acl-action="remove"
translate> translate>
Enable account Enable account
@ -41,7 +41,7 @@
ng-if="$ctrl.hasAccount" ng-if="$ctrl.hasAccount"
ng-click="disableAccount.show()" ng-click="disableAccount.show()"
name="disableAccount" name="disableAccount"
vn-acl="it" vn-acl="sysadmin"
vn-acl-action="remove" vn-acl-action="remove"
translate> translate>
Disable account Disable account
@ -50,7 +50,7 @@
ng-if="!$ctrl.user.active" ng-if="!$ctrl.user.active"
ng-click="activateUser.show()" ng-click="activateUser.show()"
name="activateUser" name="activateUser"
vn-acl="hr" vn-acl="itManagement"
vn-acl-action="remove" vn-acl-action="remove"
translate> translate>
Activate user Activate user
@ -59,7 +59,7 @@
ng-if="$ctrl.user.active" ng-if="$ctrl.user.active"
ng-click="deactivateUser.show()" ng-click="deactivateUser.show()"
name="deactivateUser" name="deactivateUser"
vn-acl="hr" vn-acl="itManagement"
vn-acl-action="remove" vn-acl-action="remove"
translate> translate>
Deactivate user Deactivate user

View File

@ -14,11 +14,11 @@
<vn-item-section> <vn-item-section>
<h6>{{::user.nickname}}</h6> <h6>{{::user.nickname}}</h6>
<vn-label-value <vn-label-value
label="Id" label="Id"
value="{{::user.id}}"> value="{{::user.id}}">
</vn-label-value> </vn-label-value>
<vn-label-value <vn-label-value
label="User" label="User"
value="{{::user.name}}"> value="{{::user.name}}">
</vn-label-value> </vn-label-value>
</vn-item-section> </vn-item-section>
@ -36,12 +36,12 @@
<vn-popup vn-id="summary"> <vn-popup vn-id="summary">
<vn-user-summary user="$ctrl.selectedUser"></vn-user-summary> <vn-user-summary user="$ctrl.selectedUser"></vn-user-summary>
</vn-popup> </vn-popup>
<a <a
fixed-bottom-right fixed-bottom-right
ui-sref="account.create" ui-sref="account.create"
vn-tooltip="New user" vn-tooltip="New user"
vn-bind="+" vn-bind="+"
vn-acl="it" vn-acl="itManagement"
vn-acl-action="remove"> vn-acl-action="remove">
<vn-float-button icon="add"></vn-float-button> <vn-float-button icon="add"></vn-float-button>
</a> </a>

View File

@ -14,12 +14,12 @@
<vn-card class="vn-pa-lg"> <vn-card class="vn-pa-lg">
<vn-vertical> <vn-vertical>
<vn-check <vn-check
label="Enable mail forwarding" label="Enable mail forwarding"
ng-model="watcher.hasData"> ng-model="watcher.hasData">
</vn-check> </vn-check>
<vn-textfield <vn-textfield
ng-if="watcher.hasData" ng-if="watcher.hasData"
label="Forward email" label="Forward email"
ng-model="data.forwardTo" ng-model="data.forwardTo"
info="All emails will be forwarded to the specified address." info="All emails will be forwarded to the specified address."
rule="MailForward" rule="MailForward"

View File

@ -4,3 +4,4 @@ Enable mail forwarding: Habilitar redirección de correo
All emails will be forwarded to the specified address.: > All emails will be forwarded to the specified address.: >
Todos los correos serán reenviados a la dirección especificada, no se Todos los correos serán reenviados a la dirección especificada, no se
mantendrá copia de los mismos en el buzón del usuario. mantendrá copia de los mismos en el buzón del usuario.
You don't have enough privileges: No tienes suficientes permisos

View File

@ -1,6 +1,6 @@
<vn-crud-model <vn-crud-model
vn-id="model" vn-id="model"
url="VnUsers" url="VnUsers/preview"
filter="::$ctrl.filter" filter="::$ctrl.filter"
limit="20"> limit="20">
</vn-crud-model> </vn-crud-model>

View File

@ -1,9 +1,7 @@
<mg-ajax path="VnUsers/{{post.params.id}}/privileges" options="vnPost"></mg-ajax> <mg-ajax path="VnUsers/{{post.params.id}}/privileges" options="vnPost"></mg-ajax>
<vn-watcher <vn-watcher
vn-id="watcher" vn-id="watcher"
url="VnUsers"
data="$ctrl.user" data="$ctrl.user"
id-value="$ctrl.$params.id"
form="form" form="form"
save="post"> save="post">
</vn-watcher> </vn-watcher>
@ -11,15 +9,16 @@
name="form" name="form"
ng-submit="watcher.submit()" ng-submit="watcher.submit()"
class="vn-w-md"> class="vn-w-md">
<vn-card class="vn-pa-lg" vn-focus> <vn-card class="vn-pa-lg">
<vn-vertical> <vn-vertical>
<vn-check <vn-check
label="Has grant" label="Has grant"
ng-model="$ctrl.user.hasGrant"> ng-model="$ctrl.user.hasGrant">
</vn-check> </vn-check>
</vn-vertical> </vn-vertical>
<vn-vertical </vn-card>
class="vn-mt-md"> <vn-card class="vn-pa-lg vn-mt-md">
<vn-vertical>
<vn-autocomplete <vn-autocomplete
label="Role" label="Role"
ng-model="$ctrl.user.roleFk" ng-model="$ctrl.user.roleFk"

View File

@ -1,9 +1,21 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
export default class Controller extends Section {} export default class Controller extends Section {
get user() {
return this._user;
}
set user(value) {
this._user = value;
if (!value) return;
}
}
ngModule.component('vnUserPrivileges', { ngModule.component('vnUserPrivileges', {
template: require('./index.html'), template: require('./index.html'),
controller: Controller controller: Controller,
bindings: {
user: '<'
}
}); });

View File

@ -49,15 +49,13 @@
"url": "/index?q", "url": "/index?q",
"state": "account.index", "state": "account.index",
"component": "vn-user-index", "component": "vn-user-index",
"description": "Users", "description": "Users"
"acl": ["marketing", "hr"]
}, },
{ {
"url": "/create", "url": "/create",
"state": "account.create", "state": "account.create",
"component": "vn-user-create", "component": "vn-user-create",
"description": "New user", "description": "New user"
"acl": ["it"]
}, },
{ {
"url": "/:id", "url": "/:id",
@ -80,7 +78,7 @@
"state": "account.card.basicData", "state": "account.card.basicData",
"component": "vn-user-basic-data", "component": "vn-user-basic-data",
"description": "Basic data", "description": "Basic data",
"acl": ["hr"] "acl": ["itManagement"]
}, },
{ {
"url" : "/log", "url" : "/log",
@ -98,8 +96,7 @@
"url": "/roles", "url": "/roles",
"state": "account.card.roles", "state": "account.card.roles",
"component": "vn-user-roles", "component": "vn-user-roles",
"description": "Inherited roles", "description": "Inherited roles"
"acl": ["it"]
}, },
{ {
"url": "/mail-forwarding", "url": "/mail-forwarding",
@ -111,15 +108,16 @@
"url": "/aliases", "url": "/aliases",
"state": "account.card.aliases", "state": "account.card.aliases",
"component": "vn-user-aliases", "component": "vn-user-aliases",
"description": "Mail aliases", "description": "Mail aliases"
"acl": ["marketing", "hr"]
}, },
{ {
"url": "/privileges", "url": "/privileges",
"state": "account.card.privileges", "state": "account.card.privileges",
"component": "vn-user-privileges", "component": "vn-user-privileges",
"description": "Privileges", "description": "Privileges",
"acl": ["hr"] "params": {
"user": "$ctrl.user"
}
}, },
{ {
"url": "/role?q", "url": "/role?q",
@ -180,8 +178,7 @@
"url": "/alias?q", "url": "/alias?q",
"state": "account.alias", "state": "account.alias",
"component": "vn-alias", "component": "vn-alias",
"description": "Mail aliases", "description": "Mail aliases"
"acl": ["marketing"]
}, },
{ {
"url": "/create", "url": "/create",

View File

@ -8,6 +8,7 @@ class Controller extends Summary {
if (!value) return; if (!value) return;
const filter = { const filter = {
where: {id: value.id},
include: { include: {
relation: 'role', relation: 'role',
scope: { scope: {
@ -15,8 +16,11 @@ class Controller extends Summary {
} }
} }
}; };
this.$http.get(`VnUsers/${value.id}`, {filter}) this.$http.get(`VnUsers/preview`, {filter})
.then(res => this.$.summary = res.data); .then(res => {
const [summary] = res.data;
this.$.summary = summary;
});
} }
get isHr() { get isHr() {
return this.aclService.hasAny(['hr']); return this.aclService.hasAny(['hr']);

View File

@ -1,7 +1,5 @@
<vn-watcher <vn-watcher
vn-id="watcher" vn-id="watcher"
url="VnUsers"
id-field="id"
data="$ctrl.account" data="$ctrl.account"
form="form"> form="form">
</vn-watcher> </vn-watcher>
@ -51,9 +49,9 @@
label="Save"> label="Save">
</vn-submit> </vn-submit>
<vn-button <vn-button
ng-if="$ctrl.canChangePassword" ng-if="$ctrl.canChangePassword"
label="Change password" label="Change password"
vn-dialog="change-pass"> vn-dialog="change-pass">
</vn-button> </vn-button>
<vn-button <vn-button
class="cancel" class="cancel"

View File

@ -8,6 +8,22 @@ export default class Controller extends Section {
this.canEnableCheckBox = true; this.canEnableCheckBox = true;
} }
set client(value) {
this._client = value;
if (!value) return;
const filter = {where: {id: value.id}};
this.$http.get(`VnUsers/preview`, {filter})
.then(res => {
const [user] = res.data;
this.account = user;
});
}
get client() {
return this._client;
}
$onChanges() { $onChanges() {
if (this.client) { if (this.client) {
this.account = this.client.account; this.account = this.client.account;

View File

@ -5,12 +5,14 @@ describe('Component VnClientWebAccess', () => {
let $scope; let $scope;
let vnApp; let vnApp;
let controller; let controller;
let $httpParamSerializer;
beforeEach(ngModule('client')); beforeEach(ngModule('client'));
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => { beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_, _vnApp_) => {
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
vnApp = _vnApp_; vnApp = _vnApp_;
jest.spyOn(vnApp, 'showError'); jest.spyOn(vnApp, 'showError');
const $element = angular.element('<vn-client-web-access></vn-client-web-access>'); const $element = angular.element('<vn-client-web-access></vn-client-web-access>');
@ -32,7 +34,10 @@ describe('Component VnClientWebAccess', () => {
describe('isCustomer()', () => { describe('isCustomer()', () => {
it('should return true if the password can be modified', () => { it('should return true if the password can be modified', () => {
controller.client = {id: '1234'}; controller.client = {id: '1234'};
const filter = {where: {id: controller.client.id}};
const serializedParams = $httpParamSerializer({filter});
$httpBackend.expectGET(`VnUsers/preview?${serializedParams}`).respond('foo');
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond(true); $httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond(true);
controller.isCustomer(); controller.isCustomer();
$httpBackend.flush(); $httpBackend.flush();
@ -42,7 +47,10 @@ describe('Component VnClientWebAccess', () => {
it(`should return a false if the password can't be modified`, () => { it(`should return a false if the password can't be modified`, () => {
controller.client = {id: '1234'}; controller.client = {id: '1234'};
const filter = {where: {id: controller.client.id}};
const serializedParams = $httpParamSerializer({filter});
$httpBackend.expectGET(`VnUsers/preview?${serializedParams}`).respond('foo');
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond(false); $httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond(false);
controller.isCustomer(); controller.isCustomer();
$httpBackend.flush(); $httpBackend.flush();
@ -54,9 +62,12 @@ describe('Component VnClientWebAccess', () => {
describe('checkConditions()', () => { describe('checkConditions()', () => {
it('should perform a query to check if the client is valid', () => { it('should perform a query to check if the client is valid', () => {
controller.client = {id: '1234'}; controller.client = {id: '1234'};
const filter = {where: {id: controller.client.id}};
const serializedParams = $httpParamSerializer({filter});
expect(controller.canEnableCheckBox).toBeTruthy(); expect(controller.canEnableCheckBox).toBeTruthy();
$httpBackend.expectGET(`VnUsers/preview?${serializedParams}`).respond('foo');
$httpBackend.expectGET(`Clients/${controller.client.id}/isValidClient`).respond(false); $httpBackend.expectGET(`Clients/${controller.client.id}/isValidClient`).respond(false);
controller.checkConditions(); controller.checkConditions();
$httpBackend.flush(); $httpBackend.flush();
@ -82,7 +93,10 @@ describe('Component VnClientWebAccess', () => {
controller.newPassword = 'm24x8'; controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8'; controller.repeatPassword = 'm24x8';
controller.canChangePassword = true; controller.canChangePassword = true;
const filter = {where: {id: controller.client.id}};
const serializedParams = $httpParamSerializer({filter});
$httpBackend.expectGET(`VnUsers/preview?${serializedParams}`).respond('foo');
const query = `Clients/${controller.client.id}/setPassword`; const query = `Clients/${controller.client.id}/setPassword`;
$httpBackend.expectPATCH(query, {newPassword: controller.newPassword}).respond('done'); $httpBackend.expectPATCH(query, {newPassword: controller.newPassword}).respond('done');
controller.onPassChange(); controller.onPassChange();

View File

@ -0,0 +1,44 @@
module.exports = Self => {
Self.remoteMethod('isAuthorized', {
description: 'Return true if the current user is a superior of the worker that is passed by parameter',
accessType: 'READ',
accepts: [{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
}, {
arg: 'id',
type: 'number',
required: true,
description: 'The worker id',
http: {source: 'path'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/isAuthorized`,
verb: 'GET'
}
});
Self.isAuthorized = async(ctx, id, options) => {
const models = Self.app.models;
const currentUserId = ctx.req.accessToken.userId;
const isHimself = currentUserId == id;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const isSubordinate = await models.Worker.isSubordinate(ctx, id, myOptions);
const isTeamBoss = await models.VnUser.hasRole(currentUserId, 'teamBoss', myOptions);
if (!isSubordinate || (isSubordinate && isHimself && !isTeamBoss))
return false;
return true;
};
};

View File

@ -16,6 +16,7 @@ module.exports = Self => {
require('../methods/worker/new')(Self); require('../methods/worker/new')(Self);
require('../methods/worker/deallocatePDA')(Self); require('../methods/worker/deallocatePDA')(Self);
require('../methods/worker/allocatePDA')(Self); require('../methods/worker/allocatePDA')(Self);
require('../methods/worker/isAuthorized')(Self);
Self.validatesUniquenessOf('locker', { Self.validatesUniquenessOf('locker', {
message: 'This locker has already been assigned' message: 'This locker has already been assigned'

View File

@ -1,33 +0,0 @@
<mg-ajax
path="VnUsers/{{$ctrl.worker.userFk}}"
actions="user = edit.model"
options="mgEdit">
</mg-ajax>
<vn-watcher
vn-id="watcher"
url="VnUsers"
id-field="id"
data="user"
form="form">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-vertical>
<vn-horizontal>
<vn-field
vn-one
label="Nickname"
ng-model="user.nickname">
</vn-field>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button
label="Undo changes"
ng-if="watcher.dataChanged()"
ng-click="watcher.loadOriginalData()">
</vn-button>
</vn-button-bar>
</form>

View File

@ -63,6 +63,7 @@
ng-model="$ctrl.businessId" ng-model="$ctrl.businessId"
search-function="{businessFk: $search}" search-function="{businessFk: $search}"
value-field="businessFk" value-field="businessFk"
show-field="businessFk"
order="businessFk DESC" order="businessFk DESC"
limit="5"> limit="5">
<tpl-item> <tpl-item>

View File

@ -71,10 +71,6 @@ class Controller extends Section {
} }
} }
get payedHolidays() {
return this._businessId;
}
buildYearFilter() { buildYearFilter() {
const now = Date.vnNew(); const now = Date.vnNew();
now.setFullYear(now.getFullYear() + 1); now.setFullYear(now.getFullYear() + 1);
@ -95,10 +91,10 @@ class Controller extends Section {
} }
getActiveContract() { getActiveContract() {
this.$http.get(`Workers/${this.worker.id}/activeContract`).then(res => { this.$http.get(`Workers/${this.worker.id}/activeContract`)
if (res.data) .then(res => {
this.businessId = res.data.businessFk; if (res.data) this.businessId = res.data.businessFk;
}); });
} }
getContractHolidays() { getContractHolidays() {