mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Reuse already calculated values (#19479)
* Reuse already calculated values * Add changeset --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
5
.changeset/few-chairs-cough.md
Normal file
5
.changeset/few-chairs-cough.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@directus/app": patch
|
||||
---
|
||||
|
||||
Optimized code for permisson check by reusing already calculated values
|
||||
@@ -1,10 +1,10 @@
|
||||
import { usePermissionsStore } from '@/stores/permissions';
|
||||
import { useUserStore } from '@/stores/user';
|
||||
import { Field } from '@directus/types';
|
||||
import { computed, ComputedRef, Ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { isAllowed } from '../utils/is-allowed';
|
||||
import { useCollection } from '@directus/composables';
|
||||
import { Field } from '@directus/types';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { computed, ComputedRef, Ref } from 'vue';
|
||||
import { isAllowed } from '../utils/is-allowed';
|
||||
|
||||
type UsablePermissions = {
|
||||
createAllowed: ComputedRef<boolean>;
|
||||
@@ -27,18 +27,18 @@ export function usePermissions(collection: Ref<string>, item: Ref<any>, isNew: R
|
||||
|
||||
const deleteAllowed = computed(() => isAllowed(collection.value, 'delete', item.value));
|
||||
|
||||
const saveAllowed = computed(() => {
|
||||
if (isNew.value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isAllowed(collection.value, 'update', item.value);
|
||||
});
|
||||
|
||||
const updateAllowed = computed(() => isAllowed(collection.value, 'update', item.value));
|
||||
|
||||
const shareAllowed = computed(() => isAllowed(collection.value, 'share', item.value));
|
||||
|
||||
const saveAllowed = computed(() => {
|
||||
if (isNew.value) {
|
||||
return createAllowed.value;
|
||||
}
|
||||
|
||||
return updateAllowed.value;
|
||||
});
|
||||
|
||||
const archiveAllowed = computed(() => {
|
||||
if (!collectionInfo.value?.meta?.archive_field) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user