salix/front/core/directives/acl-common.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-06-16 06:56:38 +00:00
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();
}