refs #4074 @2h new directive for the acls
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
521586caed
commit
baa7aa45b2
|
@ -13,12 +13,6 @@ function vnAcl(aclService) {
|
|||
|
||||
let action = $attrs.vnAclAction || 'disable';
|
||||
|
||||
if ($attrs.vnAclModel) {
|
||||
console.log($attrs.vnAclModel, $attrs.vnAclProperty, $attrs.vnAclAccessType);
|
||||
let hasAcl = aclService.hasAnyACL($attrs.vnAclModel, $attrs.vnAclProperty, $attrs.vnAclAccessType);
|
||||
if (hasAcl) return;
|
||||
}
|
||||
|
||||
if (aclService.hasAny(acls)) return;
|
||||
|
||||
if (action === 'disable') {
|
||||
|
|
|
@ -5,6 +5,7 @@ import './popover';
|
|||
import './click-stop';
|
||||
import './rule';
|
||||
import './acl';
|
||||
import './user-acl';
|
||||
import './on-error-src';
|
||||
import './zoom-image';
|
||||
import './visible-by';
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
import ngModule from '../module';
|
||||
import FormInput from '../components/form-input';
|
||||
|
||||
function vnUserAcl(aclService) {
|
||||
let acls = [];
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
priority: -1,
|
||||
link: function(_, $element, $attrs) {
|
||||
acls = $attrs.vnUserAcl.split(',').map(i => i.trim());
|
||||
if (acls[0] == '') return;
|
||||
|
||||
let action = $attrs.vnAclAction || 'disable';
|
||||
|
||||
// The acls always come formatted as "Model.property/accessType"
|
||||
// Example: "Client.create/w"
|
||||
|
||||
let model = acls[0].split('.')[0];
|
||||
let property = acls[0].split('.')[1].split('/')[0];
|
||||
let accessType = acls[0].split('.')[1].split('/')[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)) {
|
||||
let selector = 'input, textarea, button, submit';
|
||||
|
||||
if (!element.matches(selector))
|
||||
element = element.querySelector(selector);
|
||||
|
||||
elementToDisable = element;
|
||||
}
|
||||
|
||||
if (elementToDisable)
|
||||
elementToDisable.disabled = true;
|
||||
} else
|
||||
$element.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
vnUserAcl.$inject = ['aclService'];
|
||||
|
||||
ngModule.directive('vnUserAcl', vnUserAcl);
|
Loading…
Reference in New Issue