fixes #4074 Descargar ACL del usuario actual #1255

Open
pau wants to merge 40 commits from 4074-download-user-ACL into dev
4 changed files with 48 additions and 68 deletions
Showing only changes of commit 83434219ac - Show all commits

View File

@ -0,0 +1,43 @@
import FormInput from '../components/form-input';
export default function getAcls(acls, aclService, $element, $attrs, user) {
const attrsVnAcl = user ? $attrs.vnUserAcl : $attrs.vnAcl;
acls = attrsVnAcl.split(',').map(i => i.trim());
if (acls[0] == '') return;
if (user) {
const splitAcl = acls[0].split('.');
const splitSlash = splitAcl[1].split('/');
const model = splitAcl[0];
const property = splitSlash[0];
let accessType = splitSlash[1];
if (accessType === 'w') accessType = 'WRITE';
else if (accessType === 'r') accessType = 'READ';
if (aclService.hasAnyACL(model, property, accessType)) return;
} else if (aclService.hasAny(acls)) return;
disableElement($attrs, $element);
}
function disableElement($attrs, $element) {
const action = $attrs.vnAclAction || 'disable';
if (action === 'disable') {
let element = $element[0];
let elementToDisable = element.$ctrl;
if (!(elementToDisable instanceof FormInput)) {
const selector = 'input, textarea, button, submit';
if (!element.matches(selector))
element = element.querySelector(selector);
elementToDisable = element;
}
if (elementToDisable)
elementToDisable.disabled = true;
} else
$element.remove();
}

View File

@ -1,6 +1,5 @@
import ngModule from '../module'; import ngModule from '../module';
import FormInput from '../components/form-input'; import getAcls from './acl-common';
function vnAcl(aclService) { function vnAcl(aclService) {
let acls = []; let acls = [];
@ -8,30 +7,7 @@ function vnAcl(aclService) {
restrict: 'A', restrict: 'A',
priority: -1, priority: -1,
link: function(_, $element, $attrs) { link: function(_, $element, $attrs) {
acls = $attrs.vnAcl.split(',').map(i => i.trim()); getAcls(acls, aclService, $element, $attrs, false);
if (acls[0] == '') return;
let action = $attrs.vnAclAction || 'disable';
if (aclService.hasAny(acls)) return;
if (action === 'disable') {
let element = $element[0];
let elementToDisable = element.$ctrl;
if (!(elementToDisable instanceof FormInput)) {
let selector = 'input, textarea, button, submit';
if (!element.matches(selector))
element = element.querySelector(selector);
elementToDisable = element;
}
if (elementToDisable)
elementToDisable.disabled = true;
} else
$element.remove();
} }
}; };
} }

View File

@ -5,6 +5,7 @@ import './popover';
import './click-stop'; import './click-stop';
import './rule'; import './rule';
import './acl'; import './acl';
import './acl-common';
import './user-acl'; import './user-acl';
import './on-error-src'; import './on-error-src';
import './zoom-image'; import './zoom-image';

View File

@ -1,5 +1,5 @@
import ngModule from '../module'; import ngModule from '../module';
import FormInput from '../components/form-input'; import getAcls from './acl-common';
function vnUserAcl(aclService) { function vnUserAcl(aclService) {
let acls = []; let acls = [];
@ -8,47 +8,7 @@ function vnUserAcl(aclService) {
restrict: 'A', restrict: 'A',
priority: -1, priority: -1,
link: function(_, $element, $attrs) { link: function(_, $element, $attrs) {
acls = $attrs.vnUserAcl.split(',').map(i => i.trim()); getAcls(acls, aclService, $element, $attrs, true);
if (acls[0] == '') return;
const action = $attrs.vnAclAction || 'disable';
// The acls always come formatted as "Model.property/accessType"
// Example: "Client.create/w"
const splitAcl = acls[0].split('.');
const splitSlash = splitAcl[1].split('/');
const model = splitAcl[0];
const property = splitSlash[0];
let accessType = splitSlash[1];
// There can be 3 cases for the acessType: Write(w), Read(r) or All(*)
if (accessType === 'w') accessType = 'WRITE';
else if (accessType === 'r') accessType = 'READ';
const hasAny = aclService.hasAnyACL(model, property, accessType);
if (hasAny) return;
if (action === 'disable') {
let element = $element[0];
let elementToDisable = element.$ctrl;
if (!(elementToDisable instanceof FormInput)) {
const selector = 'input, textarea, button, submit';
if (!element.matches(selector))
element = element.querySelector(selector);
elementToDisable = element;
}
if (elementToDisable)
elementToDisable.disabled = true;
} else
$element.remove();
} }
}; };
} }