Skip to content

Commit e9153a3

Browse files
committed
enable editorial workflow for test backend
1 parent 5e040ee commit e9153a3

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

example/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ backend:
44
display_url: https://example.com
55
media_folder: "assets/uploads"
66

7+
publish_mode: editorial_workflow # optional, enables publishing workflow
8+
79
collections: # A list of collections the CMS should be able to edit
810
- name: "posts" # Used in routes, ie.: /admin/collections/:slug/edit
911
label: "Posts" # Used in the UI

src/backends/test-repo/implementation.js

+77-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { remove, attempt, isError } from 'lodash';
22
import uuid from 'uuid/v4';
3+
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';
4+
import { EditorialWorkflowError } from 'ValueObjects/errors';
35
import AuthenticationPage from './AuthenticationPage';
46

57
window.repoFiles = window.repoFiles || {};
8+
window.repoFilesUnpublished = window.repoFilesUnpublished || [];
69

710
function getFile(path) {
811
const segments = path.split('/');
@@ -78,20 +81,89 @@ export default class TestRepo {
7881
});
7982
}
8083

81-
persistEntry(entry, mediaFiles = [], options) {
84+
unpublishedEntries() {
85+
return Promise.resolve(window.repoFilesUnpublished);
86+
}
87+
88+
unpublishedEntry(collection, slug) {
89+
const entry = window.repoFilesUnpublished.find(e => (
90+
e.metaData.collection === collection.get('name') && e.slug === slug
91+
));
92+
if (!entry) {
93+
return Promise.reject(new EditorialWorkflowError('content is not under editorial workflow', true));
94+
}
95+
return Promise.resolve(entry);
96+
}
97+
98+
deleteUnpublishedEntry(collection, slug) {
99+
const unpubStore = window.repoFilesUnpublished;
100+
const existingEntryIndex = unpubStore.findIndex(e => (
101+
e.metaData.collection === collection && e.slug === slug
102+
));
103+
unpubStore.splice(existingEntryIndex, 1);
104+
return Promise.resolve()
105+
}
106+
107+
persistEntry({ path, raw, slug }, mediaFiles = [], options = {}) {
108+
if (options.mode === EDITORIAL_WORKFLOW) {
109+
const unpubStore = window.repoFilesUnpublished;
110+
const existingEntryIndex = unpubStore.findIndex(e => e.file.path === path);
111+
if (existingEntryIndex >= 0) {
112+
const unpubEntry = { ...unpubStore[existingEntryIndex], data: raw };
113+
unpubEntry.title = options.parsedData && options.parsedData.title;
114+
unpubEntry.description = options.parsedData && options.parsedData.description;
115+
unpubStore.splice(existingEntryIndex, 1, unpubEntry);
116+
} else {
117+
const unpubEntry = {
118+
data: raw,
119+
file: {
120+
path,
121+
},
122+
metaData: {
123+
collection: options.collectionName,
124+
status: status.first(),
125+
title: options.parsedData && options.parsedData.title,
126+
description: options.parsedData && options.parsedData.description,
127+
},
128+
slug,
129+
};
130+
unpubStore.push(unpubEntry);
131+
}
132+
return Promise.resolve();
133+
}
134+
82135
const newEntry = options.newEntry || false;
83-
const folder = entry.path.substring(0, entry.path.lastIndexOf('/'));
84-
const fileName = entry.path.substring(entry.path.lastIndexOf('/') + 1);
136+
const folder = path.substring(0, path.lastIndexOf('/'));
137+
const fileName = path.substring(path.lastIndexOf('/') + 1);
85138
window.repoFiles[folder] = window.repoFiles[folder] || {};
86139
window.repoFiles[folder][fileName] = window.repoFiles[folder][fileName] || {};
87140
if (newEntry) {
88-
window.repoFiles[folder][fileName] = { content: entry.raw };
141+
window.repoFiles[folder][fileName] = { content: raw };
89142
} else {
90-
window.repoFiles[folder][fileName].content = entry.raw;
143+
window.repoFiles[folder][fileName].content = raw;
91144
}
92145
return Promise.resolve();
93146
}
94147

148+
updateUnpublishedEntryStatus(collection, slug, newStatus) {
149+
const unpubStore = window.repoFilesUnpublished;
150+
const entryIndex = unpubStore.findIndex(e => (
151+
e.metaData.collection === collection && e.slug === slug
152+
));
153+
unpubStore[entryIndex].metaData.status = newStatus;
154+
return Promise.resolve();
155+
}
156+
157+
publishUnpublishedEntry(collection, slug) {
158+
const unpubStore = window.repoFilesUnpublished;
159+
const unpubEntryIndex = unpubStore.findIndex(e => (
160+
e.metaData.collection === collection && e.slug === slug
161+
));
162+
const unpubEntry = unpubStore[unpubEntryIndex];
163+
const entry = { raw: unpubEntry.data, slug: unpubEntry.slug, path: unpubEntry.file.path };
164+
unpubStore.splice(unpubEntryIndex, 1);
165+
return this.persistEntry(entry);
166+
}
95167
getMedia() {
96168
return Promise.resolve(this.assets);
97169
}

0 commit comments

Comments
 (0)