Add delete flag in configuration (#707)

Adds a `delete` flag to collections in `config.yml`; fixes
#593. Defaults to false. This is mostly for use with files to restrict
users from deleting settings files etc that available via the CMS.
This commit is contained in:
Richard Pullinger
2017-10-30 20:07:54 +00:00
committed by Benaiah Mischenko
parent 1bb2b56366
commit a14f25355e
4 changed files with 20 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import TestRepoBackend from "./test-repo/implementation";
import GitHubBackend from "./github/implementation";
import GitGatewayBackend from "./git-gateway/implementation";
import { resolveFormat } from "../formats/formats";
import { selectListMethod, selectEntrySlug, selectEntryPath, selectAllowNewEntries, selectFolderEntryExtension } from "../reducers/collections";
import { selectListMethod, selectEntrySlug, selectEntryPath, selectAllowNewEntries, selectAllowDeletion, selectFolderEntryExtension } from "../reducers/collections";
import { createEntry } from "../valueObjects/Entry";
import { sanitizeSlug } from "../lib/urlHelper";
@ -246,6 +246,11 @@ class Backend {
deleteEntry(config, collection, slug) {
const path = selectEntryPath(collection, slug);
if (!selectAllowDeletion(collection)) {
throw (new Error("Not allowed to delete entries in this collection"));
}
const commitMessage = `Delete ${ collection.get('label') }${ slug }`;
return this.implementation.deleteFile(path, commitMessage);
}