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

View File

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

View File

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