mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
@@ -44,6 +44,11 @@ export default async function runAST(ast: AST, query = ast.query) {
|
||||
|
||||
// Query defaults
|
||||
query.limit = query.limit || 100;
|
||||
|
||||
if (query.limit === -1) {
|
||||
delete query.limit;
|
||||
}
|
||||
|
||||
query.sort = query.sort || [{ column: primaryKeyField, order: 'asc' }];
|
||||
|
||||
await applyQuery(ast.name, dbQuery, query);
|
||||
@@ -116,7 +121,7 @@ export default async function runAST(ast: AST, query = ast.query) {
|
||||
*/
|
||||
if (batchQuery.limit) {
|
||||
tempLimit = batchQuery.limit;
|
||||
delete batchQuery.limit;
|
||||
batchQuery.limit = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,10 @@ export default class FieldsService {
|
||||
if (collection) {
|
||||
fields = (await nonAuthorizedItemsService.readByQuery({
|
||||
filter: { collection: { _eq: collection } },
|
||||
limit: -1
|
||||
})) as FieldMeta[];
|
||||
} else {
|
||||
fields = (await nonAuthorizedItemsService.readByQuery({})) as FieldMeta[];
|
||||
fields = (await nonAuthorizedItemsService.readByQuery({ limit: -1 })) as FieldMeta[];
|
||||
}
|
||||
|
||||
fields = (await this.payloadService.processValues('read', fields)) as FieldMeta[];
|
||||
|
||||
@@ -17,7 +17,7 @@ import env from '../env';
|
||||
type Action = 'create' | 'read' | 'update';
|
||||
|
||||
type Transformers = {
|
||||
[type: string]: (action: Action, value: any, payload: Partial<Item>) => Promise<any>;
|
||||
[type: string]: (action: Action, value: any, payload: Partial<Item>, accountability: Accountability | null) => Promise<any>;
|
||||
};
|
||||
|
||||
export default class PayloadService {
|
||||
@@ -93,6 +93,30 @@ export default class PayloadService {
|
||||
async conceal(action, value) {
|
||||
if (action === 'read') return value ? '**********' : null;
|
||||
return value;
|
||||
},
|
||||
async 'user-created'(action, value, payload, accountability) {
|
||||
if (action === 'create') return accountability?.user || null;
|
||||
return value;
|
||||
},
|
||||
async 'user-updated'(action, value, payload, accountability) {
|
||||
if (action === 'update') return accountability?.user || null;
|
||||
return value;
|
||||
},
|
||||
async 'role-created'(action, value, payload, accountability) {
|
||||
if (action === 'create') return accountability?.role || null;
|
||||
return value;
|
||||
},
|
||||
async 'role-updated'(action, value, payload, accountability) {
|
||||
if (action === 'update') return accountability?.role || null;
|
||||
return value;
|
||||
},
|
||||
async 'date-created'(action, value) {
|
||||
if (action === 'create') return new Date();
|
||||
return value;
|
||||
},
|
||||
async 'date-updated'(action, value) {
|
||||
if (action === 'update') return new Date();
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -124,7 +148,7 @@ export default class PayloadService {
|
||||
processedPayload.map(async (record: any) => {
|
||||
await Promise.all(
|
||||
specialFieldsInCollection.map(async (field) => {
|
||||
const newValue = await this.processField(field, record, action);
|
||||
const newValue = await this.processField(field, record, action, this.accountability);
|
||||
if (newValue !== undefined) record[field.field] = newValue;
|
||||
})
|
||||
);
|
||||
@@ -151,7 +175,8 @@ export default class PayloadService {
|
||||
async processField(
|
||||
field: Pick<FieldMeta, 'field' | 'special'>,
|
||||
payload: Partial<Item>,
|
||||
action: Action
|
||||
action: Action,
|
||||
accountability: Accountability | null
|
||||
) {
|
||||
if (!field.special) return payload[field.field];
|
||||
|
||||
@@ -162,7 +187,7 @@ export default class PayloadService {
|
||||
|
||||
for (const special of fieldSpecials) {
|
||||
if (this.transformers.hasOwnProperty(special)) {
|
||||
value = await this.transformers[special](action, value, payload);
|
||||
value = await this.transformers[special](action, value, payload, accountability);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ const localTypeMap: Record<string, { type: typeof types[number]; useTimezone?: b
|
||||
|
||||
// Postgres
|
||||
json: { type: 'json' },
|
||||
uuid: { type: 'string' },
|
||||
uuid: { type: 'uuid' },
|
||||
int2: { type: 'integer' },
|
||||
serial4: { type: 'integer' },
|
||||
int4: { type: 'integer' },
|
||||
|
||||
Reference in New Issue
Block a user