1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00

Cli,Desktop,Mobile: Resolves #9465: Log user actions (deletions) (#9585)

This commit is contained in:
Henry Heino
2024-03-09 02:33:05 -08:00
committed by GitHub
parent 3222b620b9
commit 75cb639ed2
36 changed files with 182 additions and 59 deletions

View File

@@ -4,6 +4,7 @@ import uuid from './uuid';
import time from './time';
import JoplinDatabase, { TableField } from './JoplinDatabase';
import { LoadOptions, SaveOptions } from './models/utils/types';
import ActionLogger, { ItemActionType as ItemActionType } from './utils/ActionLogger';
import { SqlQuery } from './services/database/types';
const Mutex = require('async-mutex').Mutex;
@@ -41,6 +42,9 @@ export interface DeleteOptions {
disableReadOnlyCheck?: boolean;
// Used for logging
sourceDescription?: string|ActionLogger;
// Tells whether the deleted item should be moved to the trash. By default
// it is permanently deleted.
toTrash?: boolean;
@@ -688,13 +692,17 @@ class BaseModel {
return output;
}
public static delete(id: string) {
public static delete(id: string, options?: DeleteOptions) {
if (!id) throw new Error('Cannot delete object without an ID');
ActionLogger.from(options?.sourceDescription).log(ItemActionType.Delete, id);
return this.db().exec(`DELETE FROM ${this.tableName()} WHERE id = ?`, [id]);
}
public static async batchDelete(ids: string[], options: DeleteOptions = null) {
public static async batchDelete(ids: string[], options?: DeleteOptions) {
if (!ids.length) return;
ActionLogger.from(options?.sourceDescription).log(ItemActionType.Delete, ids);
options = this.modOptions(options);
const idFieldName = options.idFieldName ? options.idFieldName : 'id';
const sql = `DELETE FROM ${this.tableName()} WHERE ${idFieldName} IN ("${ids.join('","')}")`;