Make sure collection meta exists before setting permission

Fixes #523
This commit is contained in:
rijkvanzanten
2020-10-12 18:36:28 -04:00
parent 3c1b78f7e8
commit 9e3ad30457
3 changed files with 26 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ import SettingsNotFound from './routes/not-found.vue';
import api from '@/api';
import { useCollection } from '@/composables/use-collection';
import { ref } from '@vue/composition-api';
import { useCollectionsStore, useFieldsStore } from '@/stores';
export default defineModule(({ i18n }) => ({
id: 'settings',
@@ -37,6 +38,11 @@ export default defineModule(({ i18n }) => ({
name: 'settings-collections',
path: '/data-model',
component: SettingsCollections,
beforeEnter(to, from, next) {
const collectionsStore = useCollectionsStore();
collectionsStore.hydrate();
next();
},
children: [
{
path: '+',
@@ -53,11 +59,14 @@ export default defineModule(({ i18n }) => ({
component: SettingsFields,
async beforeEnter(to, from, next) {
const { info } = useCollection(ref(to.params.collection));
const fieldsStore = useFieldsStore();
if (!info.value?.meta) {
await api.patch(`/collections/${to.params.collection}`, { meta: {} });
}
fieldsStore.hydrate();
next();
},
props: (route) => ({

View File

@@ -102,6 +102,14 @@ export default defineComponent({
async function setFullAccess() {
saving.value = true;
// If this collection isn't "managed" yet, make sure to add it to directus_collections first
// before trying to associate any permissions with it
if (props.collection.meta === null) {
await api.patch(`/collections/${props.collection.collection}`, {
meta: {},
});
}
if (props.permission) {
try {
await api.patch(`/permissions/${props.permission.id}`, {
@@ -148,6 +156,14 @@ export default defineComponent({
}
async function openPermissions() {
// If this collection isn't "managed" yet, make sure to add it to directus_collections first
// before trying to associate any permissions with it
if (props.collection.meta === null) {
await api.patch(`/collections/${props.collection.collection}`, {
meta: {},
});
}
if (props.permission) {
router.push(`/settings/roles/${props.role || 'public'}/${props.permission.id}`);
} else {