refs #5468 corregidas condiciones de autorización
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-04-26 09:48:02 +02:00
parent af0523a155
commit d6ff61b768
6 changed files with 16 additions and 15 deletions

View File

@ -15,9 +15,8 @@
</vn-item-section>
<vn-item-section side>
<vn-icon-button
ng-if="!$ctrl.isSubordinate"
ng-if="$ctrl.isAuthorized"
icon="delete"
label="$ctrl.isSubordinate"
translate-attr="{title: 'Unsubscribe'}"
ng-click="removeConfirm.show(row)">
</vn-icon-button>
@ -28,6 +27,7 @@
</vn-card>
</vn-data-viewer>
<vn-float-button
ng-if="$ctrl.isAuthorized"
icon="add"
translate-attr="{title: 'Add'}"
vn-bind="+"

View File

@ -5,12 +5,13 @@ export default class Controller extends Section {
$onInit() {
this.refresh();
this.getIsSubordinate();
console.log(this.isSubordinate);
}
getIsSubordinate() {
this.$http.get(`Workers/${this.$params.id}/isSubordinate`)
.then(res => this.isSubordinate = res.data);
this.$http.get(`Workers/${this.$params.id}/isAuthorized`)
.then(res => {
this.isAuthorized = res.data;
});
}
refresh() {

View File

@ -8,11 +8,10 @@ export default class Controller extends Section {
}
getIsAuthorized() {
this.$http.get(`Workers/${this.$params.id}/authorizeSelfOrSuperior`)
this.$http.get(`Workers/${this.$params.id}/isSubordinate`)
.then(res => {
this.isAuthorized = res.data;
if (!this.isAuthorized) throw new UserError(`You don't have enough privileges`);
this.isSubordinate = res.data;
if (!this.isSubordinate) throw new UserError(`You don't have enough privileges`);
this.$.watcher.submit();
});
}

View File

@ -4,3 +4,4 @@ Enable mail forwarding: Habilitar redirección de correo
All emails will be forwarded to the specified address.: >
Todos los correos serán reenviados a la dirección especificada, no se
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 @@
module.exports = Self => {
Self.remoteMethod('authorizeSelfOrSuperior', {
description: 'Return true if is himself or a superior',
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',
@ -18,12 +18,12 @@ module.exports = Self => {
root: true
},
http: {
path: `/:id/authorizeSelfOrSuperior`,
path: `/:id/isAuthorized`,
verb: 'GET'
}
});
Self.authorizeSelfOrSuperior = async(ctx, id, options) => {
Self.isAuthorized = async(ctx, id, options) => {
const models = Self.app.models;
const currentUserId = ctx.req.accessToken.userId;
const isHimself = currentUserId == id;
@ -36,7 +36,7 @@ module.exports = Self => {
const isSubordinate = await models.Worker.isSubordinate(ctx, id, myOptions);
const isTeamBoss = await models.VnUser.hasRole(currentUserId, 'teamBoss', myOptions);
if (!isSubordinate || (isSubordinate && !isHimself && !isTeamBoss))
if (!isSubordinate || (isSubordinate && isHimself && !isTeamBoss))
return false;
return true;

View File

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