Compare commits

..

No commits in common. "7822-checkAcl" and "dev" have entirely different histories.

4 changed files with 11 additions and 37 deletions

View File

@ -1,14 +0,0 @@
import { useAcl } from 'src/composables/useAcl';
export default {
mounted(el, binding) {
if (!binding.value) return;
const allowed = useAcl().hasAcl(
binding.value.model,
binding.value.prop,
binding.value.accessType || 'READ',
);
el.disabled = !allowed;
},
};

View File

@ -2,7 +2,6 @@ import axios from 'axios';
import { boot } from 'quasar/wrappers';
import qFormMixin from './qformMixin';
import keyShortcut from './keyShortcut';
import checkAcl from './checkAcl';
import { QForm } from 'quasar';
import { QLayout } from 'quasar';
import mainShortcutMixin from './mainShortcutMixin';
@ -13,7 +12,6 @@ export default boot(({ app }) => {
QLayout.mixins = [mainShortcutMixin];
app.directive('shortcut', keyShortcut);
app.directive('acl', checkAcl);
app.config.errorHandler = async (error) => {
let message;
const response = error.response;

View File

@ -150,10 +150,6 @@ const $props = defineProps({
type: String,
default: 'vnTable',
},
checkCreateAcl: {
type: Object,
default: undefined,
},
});
const { t } = useI18n();
@ -1088,7 +1084,6 @@ const handleHeaderSelection = (evt, data) => {
fab
icon="add"
v-shortcut="'+'"
v-acl="checkCreateAcl"
data-cy="vnTableCreateBtn"
/>
<QTooltip self="top right">

View File

@ -8,37 +8,32 @@ export function useAcl() {
const { data } = await axios.get('VnUsers/acls');
const acls = {};
data.forEach((acl) => {
const model = acl.model?.toLowerCase();
const property = acl.property?.toLowerCase();
acls[model] = acls[model] || {};
acls[model][property] = acls[model][property] || {};
acls[model][property][acl.accessType?.toLowerCase()] = true;
acls[acl.model] = acls[acl.model] || {};
acls[acl.model][acl.property] = acls[acl.model][acl.property] || {};
acls[acl.model][acl.property][acl.accessType] = true;
});
state.setAcls(acls);
}
function hasAny(acls) {
let result = false;
for (const acl of acls) {
let { model, props, accessType } = acl;
const modelAcls = state.getAcls().value[model.toLowerCase()];
const modelAcls = state.getAcls().value[model];
Array.isArray(props) || (props = [props]);
if (modelAcls) {
result = ['*', ...props].some((key) => {
const acl = modelAcls[key.toLowerCase()];
if (modelAcls)
return ['*', ...props].some((key) => {
const acl = modelAcls[key];
return acl && (acl['*'] || acl[accessType]);
});
}
if (result) return result;
}
return result;
return false;
}
function hasAcl(model, prop, accessType) {
const modelAcl = state.getAcls().value[model?.toLowerCase()];
const propAcl = modelAcl?.[prop?.toLowerCase()] || modelAcl?.['*'];
return !!(propAcl?.[accessType?.toLowerCase()] || propAcl?.['*']);
const modelAcl = state.getAcls().value[model];
const propAcl = modelAcl?.[prop] || modelAcl?.['*'];
return !!(propAcl?.[accessType] || propAcl?.['*']);
}
return {