fix(core): ensure against slug overwrite (#2139)
This commit is contained in:
committed by
Shawn Erquhart
parent
14b6292eab
commit
0ce995d78c
@ -1,4 +1,5 @@
|
||||
import { Map, List, fromJS } from 'immutable';
|
||||
import { startsWith } from 'lodash';
|
||||
import { EDITORIAL_WORKFLOW } from 'Constants/publishModes';
|
||||
import {
|
||||
UNPUBLISHED_ENTRY_REQUEST,
|
||||
@ -140,4 +141,13 @@ export const selectUnpublishedEntriesByStatus = (state, status) => {
|
||||
.valueSeq();
|
||||
};
|
||||
|
||||
export const selectUnpublishedSlugs = (state, collection) => {
|
||||
if (!state.get('entities')) return null;
|
||||
return state
|
||||
.get('entities')
|
||||
.filter((v, k) => startsWith(k, `${collection}.`))
|
||||
.map(entry => entry.get('slug'))
|
||||
.valueSeq();
|
||||
};
|
||||
|
||||
export default unpublishedEntries;
|
||||
|
@ -104,8 +104,11 @@ const entries = (state = Map({ entities: Map(), pages: Map() }), action) => {
|
||||
export const selectEntry = (state, collection, slug) =>
|
||||
state.getIn(['entities', `${collection}.${slug}`]);
|
||||
|
||||
export const selectPublishedSlugs = (state, collection) =>
|
||||
state.getIn(['pages', collection, 'ids'], List());
|
||||
|
||||
export const selectEntries = (state, collection) => {
|
||||
const slugs = state.getIn(['pages', collection, 'ids']);
|
||||
const slugs = selectPublishedSlugs(state, collection);
|
||||
return slugs && slugs.map(slug => selectEntry(state, collection, slug));
|
||||
};
|
||||
|
||||
|
@ -39,6 +39,9 @@ export const selectEntry = (state, collection, slug) =>
|
||||
export const selectEntries = (state, collection) =>
|
||||
fromEntries.selectEntries(state.entries, collection);
|
||||
|
||||
export const selectPublishedSlugs = (state, collection) =>
|
||||
fromEntries.selectPublishedSlugs(state.entries, collection);
|
||||
|
||||
export const selectSearchedEntries = state => {
|
||||
const searchItems = state.search.get('entryIds');
|
||||
return (
|
||||
@ -58,6 +61,9 @@ export const selectUnpublishedEntry = (state, collection, slug) =>
|
||||
export const selectUnpublishedEntriesByStatus = (state, status) =>
|
||||
fromEditorialWorkflow.selectUnpublishedEntriesByStatus(state.editorialWorkflow, status);
|
||||
|
||||
export const selectUnpublishedSlugs = (state, collection) =>
|
||||
fromEditorialWorkflow.selectUnpublishedSlugs(state.editorialWorkflow, collection);
|
||||
|
||||
export const selectIntegration = (state, collection, hook) =>
|
||||
fromIntegrations.selectIntegration(state.integrations, collection, hook);
|
||||
|
||||
|
Reference in New Issue
Block a user