mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
Allow disabling activity/revisions (#5112)
* Add accountability column * Add field info for accountability * Add accountability to collection type * Fetch accountability info from collection meta * Add field name translation for accountability field * Hide revisions drawer detail if revisions aren't available * Only save activity where accountability flag matches * Disable revisions for directus_presets Fixes #3767 * Tweak field option naming
This commit is contained in:
@@ -129,7 +129,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
await payloadService.processO2M(payloads, key);
|
||||
}
|
||||
|
||||
if (this.accountability) {
|
||||
if (this.accountability && this.schema.collections[this.collection].accountability !== null) {
|
||||
const activityRecords = primaryKeys.map((key) => ({
|
||||
action: Action.CREATE,
|
||||
user: this.accountability!.user,
|
||||
@@ -153,16 +153,18 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
activityPrimaryKeys.push(primaryKey);
|
||||
}
|
||||
|
||||
const revisionRecords = activityPrimaryKeys.map((key, index) => ({
|
||||
activity: key,
|
||||
collection: this.collection,
|
||||
item: primaryKeys[index],
|
||||
data: JSON.stringify(payloads[index]),
|
||||
delta: JSON.stringify(payloads[index]),
|
||||
}));
|
||||
if (this.schema.collections[this.collection].accountability === 'all') {
|
||||
const revisionRecords = activityPrimaryKeys.map((key, index) => ({
|
||||
activity: key,
|
||||
collection: this.collection,
|
||||
item: primaryKeys[index],
|
||||
data: JSON.stringify(payloads[index]),
|
||||
delta: JSON.stringify(payloads[index]),
|
||||
}));
|
||||
|
||||
if (revisionRecords.length > 0) {
|
||||
await trx.insert(revisionRecords).into('directus_revisions');
|
||||
if (revisionRecords.length > 0) {
|
||||
await trx.insert(revisionRecords).into('directus_revisions');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +337,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
await payloadService.processO2M(payload, key);
|
||||
}
|
||||
|
||||
if (this.accountability) {
|
||||
if (this.accountability && this.schema.collections[this.collection].accountability !== null) {
|
||||
const activityRecords = keys.map((key) => ({
|
||||
action: Action.UPDATE,
|
||||
user: this.accountability!.user,
|
||||
@@ -357,24 +359,26 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
activityPrimaryKeys.push(primaryKey);
|
||||
}
|
||||
|
||||
const itemsService = new ItemsService(this.collection, {
|
||||
knex: trx,
|
||||
schema: this.schema,
|
||||
});
|
||||
if (this.schema.collections[this.collection].accountability === 'all') {
|
||||
const itemsService = new ItemsService(this.collection, {
|
||||
knex: trx,
|
||||
schema: this.schema,
|
||||
});
|
||||
|
||||
const snapshots = await itemsService.readByKey(keys);
|
||||
const snapshots = await itemsService.readByKey(keys);
|
||||
|
||||
const revisionRecords = activityPrimaryKeys.map((key, index) => ({
|
||||
activity: key,
|
||||
collection: this.collection,
|
||||
item: keys[index],
|
||||
data:
|
||||
snapshots && Array.isArray(snapshots) ? JSON.stringify(snapshots?.[index]) : JSON.stringify(snapshots),
|
||||
delta: JSON.stringify(payloadWithoutAliasAndPK),
|
||||
}));
|
||||
const revisionRecords = activityPrimaryKeys.map((key, index) => ({
|
||||
activity: key,
|
||||
collection: this.collection,
|
||||
item: keys[index],
|
||||
data:
|
||||
snapshots && Array.isArray(snapshots) ? JSON.stringify(snapshots?.[index]) : JSON.stringify(snapshots),
|
||||
delta: JSON.stringify(payloadWithoutAliasAndPK),
|
||||
}));
|
||||
|
||||
if (revisionRecords.length > 0) {
|
||||
await trx.insert(revisionRecords).into('directus_revisions');
|
||||
if (revisionRecords.length > 0) {
|
||||
await trx.insert(revisionRecords).into('directus_revisions');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -502,7 +506,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
await this.knex.transaction(async (trx) => {
|
||||
await trx(this.collection).whereIn(primaryKeyField, keys).delete();
|
||||
|
||||
if (this.accountability) {
|
||||
if (this.accountability && this.schema.collections[this.collection].accountability !== null) {
|
||||
const activityRecords = keys.map((key) => ({
|
||||
action: Action.DELETE,
|
||||
user: this.accountability!.user,
|
||||
|
||||
Reference in New Issue
Block a user