chore: separates revisions from drafts
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { Payload } from '../..';
|
||||
import { PayloadRequest } from '../../express/types';
|
||||
import { Permissions } from '../types';
|
||||
|
||||
@@ -7,7 +8,7 @@ type Arguments = {
|
||||
req: PayloadRequest
|
||||
}
|
||||
|
||||
async function accessOperation(args: Arguments): Promise<Permissions> {
|
||||
async function accessOperation(this: Payload, args: Arguments): Promise<Permissions> {
|
||||
const { config } = this;
|
||||
|
||||
const {
|
||||
@@ -102,7 +103,17 @@ async function accessOperation(args: Arguments): Promise<Permissions> {
|
||||
}
|
||||
|
||||
config.collections.forEach((collection) => {
|
||||
executeEntityPolicies(collection, allOperations, 'collections');
|
||||
const collectionOperations = [...allOperations];
|
||||
|
||||
if (collection.auth && (typeof collection.auth.maxLoginAttempts !== 'undefined' && collection.auth.maxLoginAttempts !== 0)) {
|
||||
collectionOperations.push('unlock');
|
||||
}
|
||||
|
||||
if (collection.revisions) {
|
||||
collectionOperations.push('readRevisions');
|
||||
}
|
||||
|
||||
executeEntityPolicies(collection, collectionOperations, 'collections');
|
||||
});
|
||||
|
||||
config.globals.forEach((global) => {
|
||||
|
||||
@@ -10,7 +10,6 @@ import getBaseUploadFields from '../../uploads/getBaseFields';
|
||||
import { formatLabels } from '../../utilities/formatLabels';
|
||||
import { defaults, authDefaults } from './defaults';
|
||||
import { Config } from '../../config/types';
|
||||
import { baseRevisionFields } from '../../revisions/baseFields';
|
||||
|
||||
const mergeBaseFields = (fields, baseFields) => {
|
||||
const mergedFields = [];
|
||||
@@ -67,15 +66,6 @@ const sanitizeCollection = (config: Config, collection: CollectionConfig): Sanit
|
||||
|
||||
if (sanitized.revisions) {
|
||||
if (sanitized.revisions === true) sanitized.revisions = {};
|
||||
|
||||
let revisionFields = baseRevisionFields;
|
||||
|
||||
revisionFields = mergeBaseFields(sanitized.fields, revisionFields);
|
||||
|
||||
sanitized.fields = [
|
||||
...revisionFields,
|
||||
...sanitized.fields,
|
||||
];
|
||||
}
|
||||
|
||||
if (sanitized.upload) {
|
||||
|
||||
@@ -134,8 +134,9 @@ export type CollectionConfig = {
|
||||
read?: Access;
|
||||
update?: Access;
|
||||
delete?: Access;
|
||||
admin?: Access;
|
||||
admin?: (args?: any) => boolean;
|
||||
unlock?: Access;
|
||||
readRevisions?: Access;
|
||||
};
|
||||
auth?: IncomingAuthType | boolean;
|
||||
upload?: IncomingUploadType | boolean;
|
||||
|
||||
@@ -14,7 +14,6 @@ import bindCollectionMiddleware from './bindCollection';
|
||||
import { CollectionModel, SanitizedCollectionConfig } from './config/types';
|
||||
import { Payload } from '../index';
|
||||
import { getCollectionRevisionsName } from '../revisions/createCollectionName';
|
||||
import { fieldAffectsData } from '../fields/config/types';
|
||||
|
||||
const LocalStrategy = Passport.Strategy;
|
||||
|
||||
@@ -72,10 +71,7 @@ export default function registerCollections(ctx: Payload): void {
|
||||
|
||||
const revisionSchema = buildSchema(
|
||||
ctx.config,
|
||||
buildRevisionFields({
|
||||
...collection,
|
||||
fields: collection.fields.filter((field) => !(fieldAffectsData(field) && field.name === '_status')),
|
||||
}),
|
||||
buildRevisionFields(collection),
|
||||
{
|
||||
options: {
|
||||
timestamps: true,
|
||||
|
||||
@@ -6,7 +6,7 @@ import { SanitizedCollectionConfig } from '../../collections/config/types';
|
||||
import { SanitizedGlobalConfig } from '../../globals/config/types';
|
||||
import { Field } from '../../fields/config/types';
|
||||
|
||||
type OperationType = 'create' | 'read' | 'update' | 'delete';
|
||||
type OperationType = 'create' | 'read' | 'update' | 'delete' | 'unlock' | 'readRevisions';
|
||||
|
||||
type ObjectTypeFields = {
|
||||
[key in OperationType | 'fields']?: { type: GraphQLObjectType };
|
||||
@@ -104,10 +104,20 @@ export default function buildPoliciesType(): GraphQLObjectType {
|
||||
};
|
||||
|
||||
Object.values(this.config.collections).forEach((collection: SanitizedCollectionConfig) => {
|
||||
const collectionOperations: OperationType[] = ['create', 'read', 'update', 'delete'];
|
||||
|
||||
if (collection.auth && (typeof collection.auth.maxLoginAttempts !== 'undefined' && collection.auth.maxLoginAttempts !== 0)) {
|
||||
collectionOperations.push('unlock');
|
||||
}
|
||||
|
||||
if (collection.revisions) {
|
||||
collectionOperations.push('readRevisions');
|
||||
}
|
||||
|
||||
fields[formatName(collection.slug)] = {
|
||||
type: new GraphQLObjectType({
|
||||
name: formatName(`${collection.labels.singular}Access`),
|
||||
fields: buildEntity(collection.labels.singular, collection.fields, ['create', 'read', 'update', 'delete']),
|
||||
fields: buildEntity(collection.labels.singular, collection.fields, collectionOperations),
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Field } from '../fields/config/types';
|
||||
|
||||
export const baseRevisionFields: Field[] = [
|
||||
{
|
||||
name: '_status',
|
||||
type: 'select',
|
||||
defaultValue: 'draft',
|
||||
access: {
|
||||
update: () => false,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
label: 'Published',
|
||||
value: 'published',
|
||||
},
|
||||
{
|
||||
label: 'Draft',
|
||||
value: 'draft',
|
||||
},
|
||||
],
|
||||
required: true,
|
||||
index: true,
|
||||
admin: {
|
||||
position: 'sidebar',
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -1,11 +1,4 @@
|
||||
import { Access } from '../config/types';
|
||||
import { FieldAccess } from '../fields/config/types';
|
||||
|
||||
export type IncomingRevisionsType = {
|
||||
max?: number
|
||||
retainDeleted?: boolean
|
||||
access?: {
|
||||
read?: Access
|
||||
modifyStatus?: FieldAccess
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user