@imenam/mcp-organizer 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -32
- package/dist/shared/logic/attachments.d.ts +28 -0
- package/dist/shared/logic/attachments.js +52 -0
- package/dist/shared/logic/documents.d.ts +20 -0
- package/dist/shared/logic/documents.js +33 -0
- package/dist/shared/logic/line-diff.d.ts +13 -0
- package/dist/shared/logic/line-diff.js +66 -0
- package/dist/shared/logic/notes.d.ts +12 -0
- package/dist/shared/logic/notes.js +23 -0
- package/dist/shared/logic/timer.d.ts +69 -0
- package/dist/shared/logic/timer.js +87 -0
- package/dist/shared/schemas/agent-api.schema.d.ts +10 -29
- package/dist/shared/schemas/agent-api.schema.js +4 -15
- package/dist/shared/schemas/agent-tools.schema.d.ts +648 -2
- package/dist/shared/schemas/agent-tools.schema.js +158 -8
- package/dist/shared/schemas/api.schema.d.ts +7 -0
- package/dist/shared/schemas/api.schema.js +6 -0
- package/dist/shared/schemas/documents-api.schema.d.ts +47 -0
- package/dist/shared/schemas/documents-api.schema.js +36 -0
- package/dist/shared/schemas/entities.schema.d.ts +107 -54
- package/dist/shared/schemas/entities.schema.js +81 -10
- package/dist/shared/schemas/enums.schema.d.ts +19 -3
- package/dist/shared/schemas/enums.schema.js +8 -2
- package/dist/shared/schemas/gui-api.schema.d.ts +1 -0
- package/dist/shared/schemas/gui-api.schema.js +2 -0
- package/dist/shared/schemas/history-api.schema.d.ts +961 -0
- package/dist/shared/schemas/history-api.schema.js +104 -0
- package/dist/shared/schemas/notes-api.schema.d.ts +54 -0
- package/dist/shared/schemas/notes-api.schema.js +38 -0
- package/dist/shared/schemas/notifications-api.schema.d.ts +12 -0
- package/dist/shared/schemas/notifications-api.schema.js +4 -1
- package/dist/shared/schemas/tasks-api.schema.d.ts +39 -0
- package/dist/shared/schemas/tasks-api.schema.js +5 -0
- package/dist/shared/schemas/timers-api.schema.d.ts +119 -0
- package/dist/shared/schemas/timers-api.schema.js +44 -0
- package/dist/shared/schemas/views-api.schema.d.ts +16 -0
- package/dist/shared/schemas/views-api.schema.js +4 -2
- package/dist/src/agent-api/attachments.d.ts +2 -0
- package/dist/src/agent-api/attachments.js +96 -0
- package/dist/src/agent-api/documents.d.ts +3 -0
- package/dist/src/agent-api/documents.js +42 -0
- package/dist/src/agent-api/files.d.ts +35 -0
- package/dist/src/agent-api/files.js +86 -0
- package/dist/src/agent-api/history.d.ts +3 -0
- package/dist/src/agent-api/history.js +103 -0
- package/dist/src/agent-api/notes.d.ts +3 -0
- package/dist/src/agent-api/notes.js +39 -0
- package/dist/src/agent-api/requests.js +2 -1
- package/dist/src/agent-api/router.d.ts +2 -2
- package/dist/src/agent-api/router.js +9 -4
- package/dist/src/agent-api/tasks.js +13 -5
- package/dist/src/agent-api/timers.d.ts +2 -0
- package/dist/src/agent-api/timers.js +170 -0
- package/dist/src/agent-api/types.d.ts +7 -2
- package/dist/src/agent-api/views.js +15 -30
- package/dist/src/cli/backup.js +3 -3
- package/dist/src/core/accounts.d.ts +12 -5
- package/dist/src/core/accounts.js +28 -10
- package/dist/src/core/agent-files.d.ts +41 -0
- package/dist/src/core/agent-files.js +102 -0
- package/dist/src/core/agent.d.ts +29 -3
- package/dist/src/core/agent.js +129 -1
- package/dist/src/core/attachments.d.ts +6 -3
- package/dist/src/core/attachments.js +9 -4
- package/dist/src/core/board-views.js +4 -4
- package/dist/src/core/document-text.d.ts +18 -0
- package/dist/src/core/document-text.js +119 -0
- package/dist/src/core/documents.d.ts +22 -0
- package/dist/src/core/documents.js +167 -0
- package/dist/src/core/history-events.d.ts +34 -0
- package/dist/src/core/history-events.js +236 -0
- package/dist/src/core/history.d.ts +3 -1
- package/dist/src/core/history.js +59 -12
- package/dist/src/core/migrations.js +153 -0
- package/dist/src/core/notes.d.ts +23 -0
- package/dist/src/core/notes.js +78 -0
- package/dist/src/core/notifications.d.ts +48 -5
- package/dist/src/core/notifications.js +209 -33
- package/dist/src/core/password-reset.d.ts +37 -0
- package/dist/src/core/password-reset.js +56 -0
- package/dist/src/core/requests.d.ts +13 -7
- package/dist/src/core/requests.js +26 -14
- package/dist/src/core/snapshots.d.ts +3 -3
- package/dist/src/core/snapshots.js +5 -1
- package/dist/src/core/space-history.d.ts +18 -0
- package/dist/src/core/space-history.js +86 -0
- package/dist/src/core/spaces.d.ts +1 -1
- package/dist/src/core/spaces.js +4 -4
- package/dist/src/core/store.d.ts +154 -11
- package/dist/src/core/store.js +479 -52
- package/dist/src/core/task-history.d.ts +9 -5
- package/dist/src/core/task-history.js +17 -25
- package/dist/src/core/tasks.d.ts +2 -2
- package/dist/src/core/tasks.js +13 -2
- package/dist/src/core/timers.d.ts +33 -0
- package/dist/src/core/timers.js +101 -0
- package/dist/src/core/versions.d.ts +22 -0
- package/dist/src/core/versions.js +106 -0
- package/dist/src/gui-api.d.ts +4 -1
- package/dist/src/gui-api.js +87 -8
- package/dist/src/mcp/client.d.ts +7 -4
- package/dist/src/mcp/client.js +31 -4
- package/dist/src/mcp/start.d.ts +1 -1
- package/dist/src/mcp/start.js +14 -9
- package/dist/src/mcp/tools.d.ts +11 -0
- package/dist/src/mcp/tools.js +182 -5
- package/dist/src/mcp/upload.d.ts +22 -0
- package/dist/src/mcp/upload.js +79 -0
- package/dist/src/server/app.d.ts +4 -2
- package/dist/src/server/app.js +58 -8
- package/dist/src/server/login-limiter.d.ts +27 -1
- package/dist/src/server/login-limiter.js +31 -1
- package/dist/src/server/start.js +1 -0
- package/gui/dist/assets/index-C1f7hOcM.js +104 -0
- package/gui/dist/assets/index-CfMiwPSL.css +1 -0
- package/gui/dist/index.html +2 -2
- package/package.json +3 -1
- package/gui/dist/assets/index-9c9BlfUi.js +0 -99
- package/gui/dist/assets/index-DH23A5aa.css +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { documentText } from "./document-text.js";
|
|
2
|
+
import { InvariantError, NotFoundError, OrganizerError } from "./errors.js";
|
|
3
|
+
import { newId } from "./ids.js";
|
|
4
|
+
import { requireMember } from "./spaces.js";
|
|
5
|
+
import { DOCUMENT_EXTENSIONS_LABEL, documentFormatOf } from "../../shared/logic/documents.js";
|
|
6
|
+
import { MAX_DOCUMENT_BYTES, MAX_SPACE_DOCUMENTS_BYTES, } from "../../shared/schemas/documents-api.schema.js";
|
|
7
|
+
/**
|
|
8
|
+
* Documents de référence d'un espace, pour ses membres : liste, dépôt,
|
|
9
|
+
* description, remplacement par une nouvelle version, téléchargement,
|
|
10
|
+
* suppression. Tous les membres lisent et gèrent les documents de leur
|
|
11
|
+
* espace ; un non-membre reçoit la même réponse qu'un document inexistant.
|
|
12
|
+
* Les fichiers sont rangés avec les pièces jointes, sous `<dataDir>/attachments/`.
|
|
13
|
+
*/
|
|
14
|
+
const asUser = (userId) => ({ type: "user", userId });
|
|
15
|
+
/** Taille lisible d'un nombre d'octets, en Mo. */
|
|
16
|
+
function megabytes(bytes) {
|
|
17
|
+
return `${(bytes / (1024 * 1024)).toFixed(1).replace(".", ",")} Mo`;
|
|
18
|
+
}
|
|
19
|
+
function userName(store, userId) {
|
|
20
|
+
const user = store.findUser(userId);
|
|
21
|
+
return user ? (user.displayName ?? user.email) : "Ancien membre";
|
|
22
|
+
}
|
|
23
|
+
/** Format d'un document enregistré ; un nom sans format connu est une incohérence de la base. */
|
|
24
|
+
function formatOfDocument(document) {
|
|
25
|
+
const format = documentFormatOf(document.filename);
|
|
26
|
+
if (!format)
|
|
27
|
+
throw new Error(`Document ${document.id} has an unsupported file name: ${document.filename}.`);
|
|
28
|
+
return format;
|
|
29
|
+
}
|
|
30
|
+
function documentView(store, document) {
|
|
31
|
+
const format = formatOfDocument(document);
|
|
32
|
+
return {
|
|
33
|
+
id: document.id,
|
|
34
|
+
spaceId: document.spaceId,
|
|
35
|
+
filename: document.filename,
|
|
36
|
+
description: document.description,
|
|
37
|
+
mime: document.mime,
|
|
38
|
+
format: format.label,
|
|
39
|
+
size: document.size,
|
|
40
|
+
version: document.version,
|
|
41
|
+
uploaderName: userName(store, document.uploaderId),
|
|
42
|
+
updatedByName: userName(store, document.updatedBy),
|
|
43
|
+
createdAt: document.createdAt,
|
|
44
|
+
updatedAt: document.updatedAt,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function requireDocument(store, documentId, userId) {
|
|
48
|
+
const document = store.findDocument(documentId);
|
|
49
|
+
if (!document || !store.isMember(document.spaceId, userId))
|
|
50
|
+
throw new NotFoundError("Document introuvable, ou vous n'êtes pas membre de son espace.");
|
|
51
|
+
return document;
|
|
52
|
+
}
|
|
53
|
+
/** Volume occupé par les documents d'un espace, sans compter `exceptId`. */
|
|
54
|
+
function usedBytes(store, spaceId, exceptId = null) {
|
|
55
|
+
return store
|
|
56
|
+
.listDocuments(spaceId)
|
|
57
|
+
.filter((document) => document.id !== exceptId)
|
|
58
|
+
.reduce((total, document) => total + document.size, 0);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Fichier envoyé, vérifié : nom, format accepté, taille, et texte lisible
|
|
62
|
+
* pour un format que l'agent lit (UTF-8 pour un texte, archive valide pour un
|
|
63
|
+
* fichier Word).
|
|
64
|
+
*/
|
|
65
|
+
function checkedFile(input) {
|
|
66
|
+
const filename = input.filename.trim();
|
|
67
|
+
const format = documentFormatOf(filename);
|
|
68
|
+
if (!format)
|
|
69
|
+
throw new OrganizerError(`Format refusé pour « ${filename} » : déposez un fichier ${DOCUMENT_EXTENSIONS_LABEL}.`);
|
|
70
|
+
const content = Buffer.from(input.contentBase64, "base64");
|
|
71
|
+
if (content.length > MAX_DOCUMENT_BYTES) {
|
|
72
|
+
throw new OrganizerError(`Fichier trop volumineux (${megabytes(content.length)}) : un document ne dépasse pas ${megabytes(MAX_DOCUMENT_BYTES)}.`);
|
|
73
|
+
}
|
|
74
|
+
documentText(filename, content);
|
|
75
|
+
return { filename, format, content };
|
|
76
|
+
}
|
|
77
|
+
function checkQuota(store, spaceId, size, exceptId) {
|
|
78
|
+
const used = usedBytes(store, spaceId, exceptId);
|
|
79
|
+
if (used + size > MAX_SPACE_DOCUMENTS_BYTES) {
|
|
80
|
+
throw new OrganizerError(`Espace de stockage plein : les documents de l'espace occupent ${megabytes(used)} sur ${megabytes(MAX_SPACE_DOCUMENTS_BYTES)}, ce fichier (${megabytes(size)}) n'y tient pas. Supprimez des documents devenus inutiles.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Refuse un nom déjà porté par un autre document de l'espace, sans tenir compte de la casse. */
|
|
84
|
+
function checkUniqueName(store, spaceId, filename, exceptId) {
|
|
85
|
+
const taken = store.listDocuments(spaceId).find((document) => document.id !== exceptId && document.filename.toLowerCase() === filename.toLowerCase());
|
|
86
|
+
if (taken)
|
|
87
|
+
throw new InvariantError(`Un document s'appelle déjà « ${taken.filename} » : utilisez « Remplacer » sur ce document pour en déposer une nouvelle version.`);
|
|
88
|
+
}
|
|
89
|
+
/** Documents de l'espace, du plus récemment modifié au plus ancien, avec le volume occupé. */
|
|
90
|
+
export function listDocuments(store, userId, spaceId) {
|
|
91
|
+
requireMember(store, spaceId, userId);
|
|
92
|
+
const documents = store.listDocuments(spaceId);
|
|
93
|
+
return {
|
|
94
|
+
documents: documents.map((document) => documentView(store, document)),
|
|
95
|
+
usedBytes: documents.reduce((total, document) => total + document.size, 0),
|
|
96
|
+
quotaBytes: MAX_SPACE_DOCUMENTS_BYTES,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Dépose un document : le fichier est écrit, puis le document est créé en
|
|
101
|
+
* base après vérification des droits, du nom et du quota dans la même
|
|
102
|
+
* transaction. Un refus efface le fichier écrit.
|
|
103
|
+
*/
|
|
104
|
+
export function uploadDocument(store, storage, userId, spaceId, input) {
|
|
105
|
+
requireMember(store, spaceId, userId);
|
|
106
|
+
const { filename, format, content } = checkedFile(input);
|
|
107
|
+
const id = newId();
|
|
108
|
+
const storagePath = storage.write(id, content);
|
|
109
|
+
try {
|
|
110
|
+
const document = store.mutate(asUser(userId), (tx) => {
|
|
111
|
+
requireMember(tx.store, spaceId, userId);
|
|
112
|
+
checkUniqueName(tx.store, spaceId, filename, null);
|
|
113
|
+
checkQuota(tx.store, spaceId, content.length, null);
|
|
114
|
+
return tx.createDocument({ id, spaceId, filename, description: "", mime: format.mime, size: content.length, storagePath });
|
|
115
|
+
});
|
|
116
|
+
return documentView(store, document);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
storage.remove([storagePath]);
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Remplace le fichier d'un document par une nouvelle version : sa description
|
|
125
|
+
* est gardée, sa version incrémentée, l'ancien fichier effacé.
|
|
126
|
+
*/
|
|
127
|
+
export function replaceDocument(store, storage, userId, documentId, input) {
|
|
128
|
+
requireDocument(store, documentId, userId);
|
|
129
|
+
const { filename, format, content } = checkedFile(input);
|
|
130
|
+
const storagePath = storage.write(newId(), content);
|
|
131
|
+
let previous;
|
|
132
|
+
let document;
|
|
133
|
+
try {
|
|
134
|
+
document = store.mutate(asUser(userId), (tx) => {
|
|
135
|
+
const current = requireDocument(tx.store, documentId, userId);
|
|
136
|
+
previous = current.storagePath;
|
|
137
|
+
checkUniqueName(tx.store, current.spaceId, filename, current.id);
|
|
138
|
+
checkQuota(tx.store, current.spaceId, content.length, current.id);
|
|
139
|
+
return tx.replaceDocumentFile(documentId, { filename, mime: format.mime, size: content.length, storagePath });
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
storage.remove([storagePath]);
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
storage.remove([previous]);
|
|
147
|
+
return documentView(store, document);
|
|
148
|
+
}
|
|
149
|
+
export function updateDocument(store, userId, documentId, patch) {
|
|
150
|
+
const document = store.mutate(asUser(userId), (tx) => {
|
|
151
|
+
requireDocument(tx.store, documentId, userId);
|
|
152
|
+
return tx.setDocumentDescription(documentId, patch.description);
|
|
153
|
+
});
|
|
154
|
+
return documentView(store, document);
|
|
155
|
+
}
|
|
156
|
+
/** Contenu d'un document, avec son type et son nom. */
|
|
157
|
+
export function downloadDocument(store, storage, userId, documentId) {
|
|
158
|
+
const document = requireDocument(store, documentId, userId);
|
|
159
|
+
return { contentBase64: storage.readPath(document.storagePath).toString("base64"), mime: document.mime, filename: document.filename };
|
|
160
|
+
}
|
|
161
|
+
export function deleteDocument(store, storage, userId, documentId) {
|
|
162
|
+
const removed = store.mutate(asUser(userId), (tx) => {
|
|
163
|
+
requireDocument(tx.store, documentId, userId);
|
|
164
|
+
return tx.deleteDocument(documentId);
|
|
165
|
+
});
|
|
166
|
+
storage.remove([removed.storagePath]);
|
|
167
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { HistoryRow, Store } from "./store.js";
|
|
2
|
+
import type { VersionedEntityType } from "../../shared/schemas/enums.schema.js";
|
|
3
|
+
import type { HistoryCategory, HistoryEvent, HistoryPerson, HistoryTaskRef } from "../../shared/schemas/history-api.schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Événements de l'historique, dérivés des versions : chaque version est
|
|
6
|
+
* comparée à la précédente de la même entité pour en tirer ses changements.
|
|
7
|
+
*/
|
|
8
|
+
/** Catégorie d'événement de chaque type d'entité versionnée. */
|
|
9
|
+
export declare const CATEGORY_OF: Record<VersionedEntityType, HistoryCategory>;
|
|
10
|
+
/** Types d'entités d'une catégorie d'événements. */
|
|
11
|
+
export declare function entityTypesOf(categories: readonly HistoryCategory[]): VersionedEntityType[];
|
|
12
|
+
/** Lectures mises en cache le temps de construire une liste d'événements. */
|
|
13
|
+
export declare class HistoryContext {
|
|
14
|
+
readonly store: Store;
|
|
15
|
+
private readonly spaces;
|
|
16
|
+
private readonly people;
|
|
17
|
+
private readonly tasks;
|
|
18
|
+
private readonly requests;
|
|
19
|
+
constructor(store: Store);
|
|
20
|
+
person(userId: string): HistoryPerson;
|
|
21
|
+
/** Tâche existante ou supprimée, d'après son dernier instantané ; null si elle est inconnue. */
|
|
22
|
+
task(taskId: string): HistoryTaskRef | null;
|
|
23
|
+
request(requestId: string): {
|
|
24
|
+
id: string;
|
|
25
|
+
text: string;
|
|
26
|
+
authorId: string;
|
|
27
|
+
} | null;
|
|
28
|
+
private space;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Événement d'une version, ou null quand elle ne change rien de lisible.
|
|
32
|
+
* `detail` joint le diff complet de la description.
|
|
33
|
+
*/
|
|
34
|
+
export declare function historyEvent(ctx: HistoryContext, row: HistoryRow, detail: boolean): HistoryEvent | null;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { membershipKey } from "./versions.js";
|
|
2
|
+
import { diffCounts, diffLines } from "../../shared/logic/line-diff.js";
|
|
3
|
+
import { ChecklistItemSchema, IdeaSchema, InvitationSchema, MembershipSchema, NoteSchema, SpaceDocumentSchema, TaskSnapshotSchema, TestCheckpointSchema, } from "../../shared/schemas/entities.schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Événements de l'historique, dérivés des versions : chaque version est
|
|
6
|
+
* comparée à la précédente de la même entité pour en tirer ses changements.
|
|
7
|
+
*/
|
|
8
|
+
/** Catégorie d'événement de chaque type d'entité versionnée. */
|
|
9
|
+
export const CATEGORY_OF = {
|
|
10
|
+
task: "task",
|
|
11
|
+
checklist_item: "task",
|
|
12
|
+
test_checkpoint: "task",
|
|
13
|
+
idea: "idea",
|
|
14
|
+
membership: "member",
|
|
15
|
+
invitation: "member",
|
|
16
|
+
note: "note",
|
|
17
|
+
document: "document",
|
|
18
|
+
};
|
|
19
|
+
/** Types d'entités d'une catégorie d'événements. */
|
|
20
|
+
export function entityTypesOf(categories) {
|
|
21
|
+
return Object.keys(CATEGORY_OF).filter((type) => categories.includes(CATEGORY_OF[type]));
|
|
22
|
+
}
|
|
23
|
+
const REQUEST_EXCERPT = 140;
|
|
24
|
+
/** Lectures mises en cache le temps de construire une liste d'événements. */
|
|
25
|
+
export class HistoryContext {
|
|
26
|
+
store;
|
|
27
|
+
spaces = new Map();
|
|
28
|
+
people = new Map();
|
|
29
|
+
tasks = new Map();
|
|
30
|
+
requests = new Map();
|
|
31
|
+
constructor(store) {
|
|
32
|
+
this.store = store;
|
|
33
|
+
}
|
|
34
|
+
person(userId) {
|
|
35
|
+
let person = this.people.get(userId);
|
|
36
|
+
if (!person) {
|
|
37
|
+
const user = this.store.findUser(userId);
|
|
38
|
+
person = { id: userId, name: user ? (user.displayName ?? user.email) : "Ancien membre" };
|
|
39
|
+
this.people.set(userId, person);
|
|
40
|
+
}
|
|
41
|
+
return person;
|
|
42
|
+
}
|
|
43
|
+
/** Tâche existante ou supprimée, d'après son dernier instantané ; null si elle est inconnue. */
|
|
44
|
+
task(taskId) {
|
|
45
|
+
if (!this.tasks.has(taskId)) {
|
|
46
|
+
const current = this.store.findTask(taskId);
|
|
47
|
+
const snapshot = current ?? this.store.lastTaskSnapshot(taskId);
|
|
48
|
+
const space = snapshot ? this.space(snapshot.spaceId) : null;
|
|
49
|
+
this.tasks.set(taskId, snapshot && space ? { id: taskId, key: `${space.keyPrefix}-${snapshot.number}`, title: snapshot.title, deleted: current === null } : null);
|
|
50
|
+
}
|
|
51
|
+
return this.tasks.get(taskId) ?? null;
|
|
52
|
+
}
|
|
53
|
+
request(requestId) {
|
|
54
|
+
if (!this.requests.has(requestId)) {
|
|
55
|
+
const request = this.store.findAgentRequest(requestId);
|
|
56
|
+
this.requests.set(requestId, request ? { id: request.id, text: excerpt(request.text, REQUEST_EXCERPT), authorId: request.authorId } : null);
|
|
57
|
+
}
|
|
58
|
+
return this.requests.get(requestId) ?? null;
|
|
59
|
+
}
|
|
60
|
+
space(spaceId) {
|
|
61
|
+
if (!this.spaces.has(spaceId))
|
|
62
|
+
this.spaces.set(spaceId, this.store.findSpace(spaceId));
|
|
63
|
+
return this.spaces.get(spaceId) ?? null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function excerpt(text, max) {
|
|
67
|
+
const line = text.trim().split(/\r?\n/)[0];
|
|
68
|
+
return line.length > max ? `${line.slice(0, max - 1)}…` : line;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Événement d'une version, ou null quand elle ne change rien de lisible.
|
|
72
|
+
* `detail` joint le diff complet de la description.
|
|
73
|
+
*/
|
|
74
|
+
export function historyEvent(ctx, row, detail) {
|
|
75
|
+
const { version } = row;
|
|
76
|
+
const changes = changesOf(ctx, row, detail);
|
|
77
|
+
if (changes.length === 0)
|
|
78
|
+
return null;
|
|
79
|
+
const request = version.actorType === "agent" && version.requestId !== null ? ctx.request(version.requestId) : null;
|
|
80
|
+
const actorId = request ? request.authorId : version.actorId;
|
|
81
|
+
const isTask = version.entityType === "task";
|
|
82
|
+
const restorable = isTask && version.snapshot === null && !ctx.store.findTask(version.entityId) && ctx.store.latestVersion("task", version.entityId)?.version === version.version;
|
|
83
|
+
return {
|
|
84
|
+
id: `${version.entityType}:${version.entityId}:${version.version}`,
|
|
85
|
+
seq: version.seq,
|
|
86
|
+
at: version.createdAt,
|
|
87
|
+
category: CATEGORY_OF[version.entityType],
|
|
88
|
+
actor: { type: version.actorType, ...ctx.person(actorId) },
|
|
89
|
+
request: request ? { id: request.id, text: request.text } : null,
|
|
90
|
+
task: version.taskId === null ? null : ctx.task(version.taskId),
|
|
91
|
+
version: isTask && version.snapshot !== null ? version.version : null,
|
|
92
|
+
restorable,
|
|
93
|
+
changes,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Création, restauration après suppression, suppression, ou null pour une modification. */
|
|
97
|
+
function lifecycle(row) {
|
|
98
|
+
if (!row.previousExists)
|
|
99
|
+
return "created";
|
|
100
|
+
if (row.previous === null)
|
|
101
|
+
return "restored";
|
|
102
|
+
if (row.version.snapshot === null)
|
|
103
|
+
return "deleted";
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
function changesOf(ctx, row, detail) {
|
|
107
|
+
const stage = lifecycle(row);
|
|
108
|
+
const { entityType, snapshot, actorId } = row.version;
|
|
109
|
+
switch (entityType) {
|
|
110
|
+
case "task":
|
|
111
|
+
if (stage !== null)
|
|
112
|
+
return [{ kind: stage }];
|
|
113
|
+
return taskChanges(ctx, TaskSnapshotSchema.parse(row.previous), TaskSnapshotSchema.parse(snapshot), detail);
|
|
114
|
+
case "checklist_item": {
|
|
115
|
+
if (stage !== null) {
|
|
116
|
+
const item = ChecklistItemSchema.parse(snapshot ?? row.previous);
|
|
117
|
+
return [{ kind: "checklist", action: stage === "deleted" ? "removed" : "added", text: item.text, previous: null }];
|
|
118
|
+
}
|
|
119
|
+
const [before, after] = [ChecklistItemSchema.parse(row.previous), ChecklistItemSchema.parse(snapshot)];
|
|
120
|
+
const changes = [];
|
|
121
|
+
if (before.text !== after.text)
|
|
122
|
+
changes.push({ kind: "checklist", action: "edited", text: after.text, previous: before.text });
|
|
123
|
+
if (before.done !== after.done)
|
|
124
|
+
changes.push({ kind: "checklist", action: after.done ? "checked" : "unchecked", text: after.text, previous: null });
|
|
125
|
+
return changes;
|
|
126
|
+
}
|
|
127
|
+
case "test_checkpoint": {
|
|
128
|
+
if (stage !== null) {
|
|
129
|
+
const checkpoint = TestCheckpointSchema.parse(snapshot ?? row.previous);
|
|
130
|
+
return [{ kind: "checkpoint", action: stage === "deleted" ? "removed" : "added", text: checkpoint.text, previous: null }];
|
|
131
|
+
}
|
|
132
|
+
const [before, after] = [TestCheckpointSchema.parse(row.previous), TestCheckpointSchema.parse(snapshot)];
|
|
133
|
+
return before.text === after.text ? [] : [{ kind: "checkpoint", action: "edited", text: after.text, previous: before.text }];
|
|
134
|
+
}
|
|
135
|
+
case "idea": {
|
|
136
|
+
if (stage !== null) {
|
|
137
|
+
return [{ kind: "idea", action: stage, text: IdeaSchema.parse(snapshot ?? row.previous).text, previous: null, task: null }];
|
|
138
|
+
}
|
|
139
|
+
const [before, after] = [IdeaSchema.parse(row.previous), IdeaSchema.parse(snapshot)];
|
|
140
|
+
const changes = [];
|
|
141
|
+
if (before.text !== after.text)
|
|
142
|
+
changes.push({ kind: "idea", action: "edited", text: after.text, previous: before.text, task: null });
|
|
143
|
+
if (after.promotedTaskId !== null && before.promotedTaskId !== after.promotedTaskId) {
|
|
144
|
+
changes.push({ kind: "idea", action: "promoted", text: after.text, previous: null, task: ctx.task(after.promotedTaskId) });
|
|
145
|
+
}
|
|
146
|
+
if ((before.archivedAt === null) !== (after.archivedAt === null)) {
|
|
147
|
+
changes.push({ kind: "idea", action: after.archivedAt === null ? "unarchived" : "archived", text: after.text, previous: null, task: null });
|
|
148
|
+
}
|
|
149
|
+
return changes;
|
|
150
|
+
}
|
|
151
|
+
case "membership": {
|
|
152
|
+
const membership = MembershipSchema.parse(snapshot ?? row.previous);
|
|
153
|
+
const person = ctx.person(membershipKey(row.version.entityId).userId);
|
|
154
|
+
const self = person.id === actorId;
|
|
155
|
+
if (stage === "created" || stage === "restored") {
|
|
156
|
+
const action = membership.role === "owner" && self ? "created_space" : self ? "joined" : "added";
|
|
157
|
+
return [{ kind: "member", action, person, role: membership.role }];
|
|
158
|
+
}
|
|
159
|
+
if (stage === "deleted")
|
|
160
|
+
return [{ kind: "member", action: self ? "left" : "removed", person, role: membership.role }];
|
|
161
|
+
return MembershipSchema.parse(row.previous).role === membership.role ? [] : [{ kind: "member", action: "role", person, role: membership.role }];
|
|
162
|
+
}
|
|
163
|
+
case "invitation": {
|
|
164
|
+
const invitation = InvitationSchema.parse(snapshot ?? row.previous);
|
|
165
|
+
const user = ctx.store.findUserByEmail(invitation.email);
|
|
166
|
+
const person = user ? { id: user.id, name: user.displayName ?? user.email } : { id: null, name: invitation.email };
|
|
167
|
+
if (stage === "created")
|
|
168
|
+
return [{ kind: "invitation", action: "invited", person }];
|
|
169
|
+
if (stage !== null)
|
|
170
|
+
return [];
|
|
171
|
+
const before = InvitationSchema.parse(row.previous);
|
|
172
|
+
if (before.revokedAt === null && invitation.revokedAt !== null)
|
|
173
|
+
return [{ kind: "invitation", action: "revoked", person }];
|
|
174
|
+
if (before.declinedAt === null && invitation.declinedAt !== null)
|
|
175
|
+
return [{ kind: "invitation", action: "declined", person }];
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
case "note": {
|
|
179
|
+
if (stage !== null) {
|
|
180
|
+
const note = NoteSchema.parse(snapshot ?? row.previous);
|
|
181
|
+
return [{ kind: "note", action: stage, noteId: note.id, title: note.title, previous: null }];
|
|
182
|
+
}
|
|
183
|
+
const [before, after] = [NoteSchema.parse(row.previous), NoteSchema.parse(snapshot)];
|
|
184
|
+
const changes = [];
|
|
185
|
+
if (before.title !== after.title)
|
|
186
|
+
changes.push({ kind: "note", action: "renamed", noteId: after.id, title: after.title, previous: before.title });
|
|
187
|
+
if (before.body !== after.body)
|
|
188
|
+
changes.push({ kind: "note", action: "edited", noteId: after.id, title: after.title, previous: null });
|
|
189
|
+
return changes;
|
|
190
|
+
}
|
|
191
|
+
case "document": {
|
|
192
|
+
if (stage !== null) {
|
|
193
|
+
const document = SpaceDocumentSchema.parse(snapshot ?? row.previous);
|
|
194
|
+
return [{ kind: "document", action: stage === "created" ? "added" : stage, filename: document.filename }];
|
|
195
|
+
}
|
|
196
|
+
const [before, after] = [SpaceDocumentSchema.parse(row.previous), SpaceDocumentSchema.parse(snapshot)];
|
|
197
|
+
const changes = [];
|
|
198
|
+
if (before.version !== after.version)
|
|
199
|
+
changes.push({ kind: "document", action: "replaced", filename: after.filename });
|
|
200
|
+
if (before.description !== after.description)
|
|
201
|
+
changes.push({ kind: "document", action: "described", filename: after.filename });
|
|
202
|
+
return changes;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Changements lisibles entre deux instantanés d'une tâche, dans l'ordre de la fiche. */
|
|
207
|
+
function taskChanges(ctx, before, after, detail) {
|
|
208
|
+
const changes = [];
|
|
209
|
+
if (before.title !== after.title)
|
|
210
|
+
changes.push({ kind: "title", from: before.title, to: after.title });
|
|
211
|
+
if (before.status !== after.status)
|
|
212
|
+
changes.push({ kind: "status", from: before.status, to: after.status });
|
|
213
|
+
if (before.priority !== after.priority)
|
|
214
|
+
changes.push({ kind: "priority", from: before.priority, to: after.priority });
|
|
215
|
+
if (before.type !== after.type)
|
|
216
|
+
changes.push({ kind: "type", from: before.type, to: after.type });
|
|
217
|
+
if (before.description !== after.description) {
|
|
218
|
+
const lines = diffLines(before.description, after.description);
|
|
219
|
+
changes.push({ kind: "description", ...diffCounts(lines), lines: detail ? lines : null });
|
|
220
|
+
}
|
|
221
|
+
const added = after.assigneeIds.filter((id) => !before.assigneeIds.includes(id));
|
|
222
|
+
const removed = before.assigneeIds.filter((id) => !after.assigneeIds.includes(id));
|
|
223
|
+
if (added.length + removed.length > 0)
|
|
224
|
+
changes.push({ kind: "assignees", added: added.map((id) => ctx.person(id)), removed: removed.map((id) => ctx.person(id)) });
|
|
225
|
+
const tagName = (id) => ctx.store.findTag(id)?.name ?? "tag supprimé";
|
|
226
|
+
const addedTags = after.tagIds.filter((id) => !before.tagIds.includes(id));
|
|
227
|
+
const removedTags = before.tagIds.filter((id) => !after.tagIds.includes(id));
|
|
228
|
+
if (addedTags.length + removedTags.length > 0)
|
|
229
|
+
changes.push({ kind: "tags", added: addedTags.map(tagName), removed: removedTags.map(tagName) });
|
|
230
|
+
const ref = (id) => (id === null ? null : ctx.task(id));
|
|
231
|
+
if (before.parentId !== after.parentId)
|
|
232
|
+
changes.push({ kind: "parent", from: ref(before.parentId), to: ref(after.parentId) });
|
|
233
|
+
if (before.testedTaskId !== after.testedTaskId)
|
|
234
|
+
changes.push({ kind: "tested", from: ref(before.testedTaskId), to: ref(after.testedTaskId) });
|
|
235
|
+
return changes;
|
|
236
|
+
}
|
|
@@ -13,8 +13,10 @@ declare const TASK_FIELDS: readonly ["title", "description", "status", "priority
|
|
|
13
13
|
* refus nomme l'auteur de la modification. Une création est supprimée, une
|
|
14
14
|
* suppression recréée, une modification ramenée à l'état d'avant. Une action
|
|
15
15
|
* sur une vue du tableau de bord ne s'annule que par le membre à qui la vue appartient.
|
|
16
|
+
* Renvoie le chemin du fichier d'une pièce jointe supprimée, que l'appelant
|
|
17
|
+
* efface une fois la mutation validée ; null sinon.
|
|
16
18
|
*/
|
|
17
|
-
export declare function undoAgentAction(tx: Mutation, action: AgentAction):
|
|
19
|
+
export declare function undoAgentAction(tx: Mutation, action: AgentAction): string | null;
|
|
18
20
|
/** Libellés français des champs restaurables d'une tâche ; « position » est le rang dans une même colonne. */
|
|
19
21
|
export declare const TASK_FIELD_LABELS: Record<(typeof TASK_FIELDS)[number] | "position" | "assigneeIds" | "tagIds", string>;
|
|
20
22
|
/**
|
package/dist/src/core/history.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ForbiddenError, InvariantError, NotFoundError } from "./errors.js";
|
|
2
2
|
import { CheckpointSnapshotSchema, isTracked, snapshotOf, taskIdOfAction } from "./snapshots.js";
|
|
3
|
-
import { BoardViewSchema, ChecklistItemSchema, FollowUpSchema, QuestionSnapshotSchema, CommentSchema, IdeaSchema, TaskSnapshotSchema, TestCheckpointSchema, } from "../../shared/schemas/entities.schema.js";
|
|
3
|
+
import { BoardViewSchema, ChecklistItemSchema, FollowUpSchema, QuestionSnapshotSchema, CommentSchema, AttachmentSchema, IdeaSchema, TaskSnapshotSchema, TestCheckpointSchema, TimeSessionSchema, } from "../../shared/schemas/entities.schema.js";
|
|
4
4
|
/**
|
|
5
5
|
* Retour à un état antérieur : annulation d'une action de l'agent, après
|
|
6
6
|
* comparaison de l'état courant de l'entité avec celui que l'action a
|
|
@@ -27,6 +27,8 @@ function comparable(entityType, snapshot) {
|
|
|
27
27
|
return [TestCheckpointSchema.parse(snapshot).text];
|
|
28
28
|
case "comment":
|
|
29
29
|
return [CommentSchema.parse(snapshot).body];
|
|
30
|
+
case "attachment":
|
|
31
|
+
return [AttachmentSchema.parse(snapshot).filename];
|
|
30
32
|
case "idea": {
|
|
31
33
|
const idea = IdeaSchema.parse(snapshot);
|
|
32
34
|
return [idea.text, idea.promotedTaskId, idea.archivedAt !== null];
|
|
@@ -35,12 +37,16 @@ function comparable(entityType, snapshot) {
|
|
|
35
37
|
return viewSettings(BoardViewSchema.parse(snapshot));
|
|
36
38
|
case "follow_up":
|
|
37
39
|
return [FollowUpSchema.parse(snapshot).doneAt !== null];
|
|
40
|
+
case "time_session": {
|
|
41
|
+
const session = TimeSessionSchema.parse(snapshot);
|
|
42
|
+
return [session.endedAt, session.runningSince, session.elapsedMs];
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
/** Réglages d'une vue, comparés et restaurés par l'annulation. */
|
|
41
47
|
function viewSettings(view) {
|
|
42
|
-
const { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds } = view;
|
|
43
|
-
return { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds };
|
|
48
|
+
const { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds, types } = view;
|
|
49
|
+
return { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds, types };
|
|
44
50
|
}
|
|
45
51
|
/** Rang d'un élément de checklist ou d'un point de vérification ; null pour les autres entités. */
|
|
46
52
|
function listPosition(entityType, snapshot) {
|
|
@@ -78,12 +84,22 @@ function describe(store, entityType, snapshot) {
|
|
|
78
84
|
return { label: `Le point de vérification « ${TestCheckpointSchema.parse(snapshot).text} »`, feminine: false };
|
|
79
85
|
case "comment":
|
|
80
86
|
return { label: "Le commentaire de l'agent", feminine: false };
|
|
87
|
+
case "attachment":
|
|
88
|
+
return { label: `La pièce jointe « ${AttachmentSchema.parse(snapshot).filename} »`, feminine: true };
|
|
81
89
|
case "idea":
|
|
82
90
|
return { label: `L'idée « ${excerpt(IdeaSchema.parse(snapshot).text)} »`, feminine: true };
|
|
83
91
|
case "board_view":
|
|
84
92
|
return { label: `La vue « ${BoardViewSchema.parse(snapshot).name} »`, feminine: true };
|
|
85
93
|
case "follow_up":
|
|
86
94
|
return { label: `Le point « ${excerpt(FollowUpSchema.parse(snapshot).text)} »`, feminine: false };
|
|
95
|
+
case "time_session": {
|
|
96
|
+
const session = TimeSessionSchema.parse(snapshot);
|
|
97
|
+
const user = store.findUser(session.userId);
|
|
98
|
+
const task = store.findTask(session.taskId);
|
|
99
|
+
const space = store.findSpace(session.spaceId);
|
|
100
|
+
const who = user ? (user.displayName ?? user.email) : "un ancien membre";
|
|
101
|
+
return { label: `Le chrono de ${who}${task && space ? ` sur ${space.keyPrefix}-${task.number}` : ""}`, feminine: false };
|
|
102
|
+
}
|
|
87
103
|
}
|
|
88
104
|
}
|
|
89
105
|
function excerpt(text) {
|
|
@@ -106,6 +122,8 @@ function lastModifier(store, entityType, entityId, action) {
|
|
|
106
122
|
* refus nomme l'auteur de la modification. Une création est supprimée, une
|
|
107
123
|
* suppression recréée, une modification ramenée à l'état d'avant. Une action
|
|
108
124
|
* sur une vue du tableau de bord ne s'annule que par le membre à qui la vue appartient.
|
|
125
|
+
* Renvoie le chemin du fichier d'une pièce jointe supprimée, que l'appelant
|
|
126
|
+
* efface une fois la mutation validée ; null sinon.
|
|
109
127
|
*/
|
|
110
128
|
export function undoAgentAction(tx, action) {
|
|
111
129
|
if (action.undoneAt !== null)
|
|
@@ -116,7 +134,10 @@ export function undoAgentAction(tx, action) {
|
|
|
116
134
|
const store = tx.store;
|
|
117
135
|
if (entityType === "board_view")
|
|
118
136
|
requireViewOwner(tx, BoardViewSchema.parse(action.after ?? action.before));
|
|
137
|
+
if (entityType === "time_session")
|
|
138
|
+
requireTimerOwner(tx, TimeSessionSchema.parse(action.after ?? action.before));
|
|
119
139
|
const current = snapshotOf(store, entityType, action.entityId);
|
|
140
|
+
let removedFile = null;
|
|
120
141
|
if (action.after === null) {
|
|
121
142
|
const { label } = describe(store, entityType, action.before);
|
|
122
143
|
if (current !== null)
|
|
@@ -133,11 +154,12 @@ export function undoAgentAction(tx, action) {
|
|
|
133
154
|
throw new InvariantError(`${label} a été modifié${agreement} depuis par ${lastModifier(store, entityType, action.entityId, action)} : l'annulation écraserait cette modification.`);
|
|
134
155
|
}
|
|
135
156
|
if (action.before === null)
|
|
136
|
-
remove(tx, entityType, current, label);
|
|
157
|
+
removedFile = remove(tx, entityType, current, label);
|
|
137
158
|
else
|
|
138
159
|
restore(tx, entityType, action.entityId, action.before);
|
|
139
160
|
}
|
|
140
161
|
tx.markAgentActionUndone(action.id, taskIdOfAction(action));
|
|
162
|
+
return removedFile;
|
|
141
163
|
}
|
|
142
164
|
/** Seul le membre à qui appartient une vue annule les changements que l'agent y a faits. */
|
|
143
165
|
function requireViewOwner(tx, view) {
|
|
@@ -146,6 +168,13 @@ function requireViewOwner(tx, view) {
|
|
|
146
168
|
const owner = tx.store.findUser(view.userId);
|
|
147
169
|
throw new ForbiddenError(`La vue « ${view.name} » appartient à ${owner ? (owner.displayName ?? owner.email) : "un ancien membre"} : lui seul peut annuler ce changement.`);
|
|
148
170
|
}
|
|
171
|
+
/** Seul le membre à qui appartient un chrono annule ce que l'agent y a fait. */
|
|
172
|
+
function requireTimerOwner(tx, session) {
|
|
173
|
+
if (tx.actor.type === "user" && tx.actor.userId === session.userId)
|
|
174
|
+
return;
|
|
175
|
+
const owner = tx.store.findUser(session.userId);
|
|
176
|
+
throw new ForbiddenError(`Ce chrono appartient à ${owner ? (owner.displayName ?? owner.email) : "un ancien membre"} : lui seul peut annuler ce changement.`);
|
|
177
|
+
}
|
|
149
178
|
/** Vérifie que les assignés filtrés par une vue sont encore membres de son espace. */
|
|
150
179
|
function requireViewAssignees(tx, view) {
|
|
151
180
|
for (const userId of view.assigneeIds) {
|
|
@@ -155,7 +184,11 @@ function requireViewAssignees(tx, view) {
|
|
|
155
184
|
}
|
|
156
185
|
}
|
|
157
186
|
}
|
|
158
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Supprime une entité créée par l'agent ; une tâche qui porte d'autres
|
|
189
|
+
* éléments est refusée. Renvoie le chemin du fichier d'une pièce jointe
|
|
190
|
+
* supprimée, null pour une autre entité.
|
|
191
|
+
*/
|
|
159
192
|
function remove(tx, entityType, current, label) {
|
|
160
193
|
const store = tx.store;
|
|
161
194
|
switch (entityType) {
|
|
@@ -168,42 +201,49 @@ function remove(tx, entityType, current, label) {
|
|
|
168
201
|
[store.listCheckpoints(task.id).length, "des points de vérification"],
|
|
169
202
|
[store.listComments(task.id).length, "des commentaires"],
|
|
170
203
|
[store.listAttachments(task.id).length, "des pièces jointes"],
|
|
204
|
+
[store.listTimeSessions(task.id).length, "des sessions de chrono"],
|
|
171
205
|
];
|
|
172
206
|
const found = dependents.filter(([count]) => count > 0).map(([, what]) => what);
|
|
173
207
|
if (found.length > 0) {
|
|
174
208
|
throw new InvariantError(`${label} porte ${found.join(", ")} : annulez d'abord les actions qui les ont ajoutés, ou supprimez-les.`);
|
|
175
209
|
}
|
|
176
210
|
tx.deleteTask(task.id);
|
|
177
|
-
return;
|
|
211
|
+
return null;
|
|
178
212
|
}
|
|
179
213
|
case "checklist_item":
|
|
180
214
|
tx.deleteChecklistItem(ChecklistItemSchema.parse(current).id);
|
|
181
|
-
return;
|
|
215
|
+
return null;
|
|
182
216
|
case "task_question":
|
|
183
217
|
tx.deleteQuestion(QuestionSnapshotSchema.parse(current).id);
|
|
184
|
-
return;
|
|
218
|
+
return null;
|
|
185
219
|
case "test_checkpoint": {
|
|
186
220
|
const checkpoint = CheckpointSnapshotSchema.parse(current);
|
|
187
221
|
if (checkpoint.results.length > 0)
|
|
188
222
|
throw new InvariantError(`${label} a reçu des résultats de test depuis : annulation impossible sans les perdre.`);
|
|
189
223
|
tx.deleteCheckpoint(checkpoint.id);
|
|
190
|
-
return;
|
|
224
|
+
return null;
|
|
191
225
|
}
|
|
192
226
|
case "comment":
|
|
193
227
|
tx.deleteAgentComment(CommentSchema.parse(current).id);
|
|
194
|
-
return;
|
|
228
|
+
return null;
|
|
229
|
+
case "attachment":
|
|
230
|
+
return tx.deleteAttachment(AttachmentSchema.parse(current).id).storagePath;
|
|
195
231
|
case "idea":
|
|
196
232
|
tx.deleteIdea(IdeaSchema.parse(current).id);
|
|
197
|
-
return;
|
|
233
|
+
return null;
|
|
198
234
|
case "board_view": {
|
|
199
235
|
const view = BoardViewSchema.parse(current);
|
|
200
236
|
if (store.listBoardViews(view.spaceId, view.userId).length === 1) {
|
|
201
237
|
throw new InvariantError(`${label} est la dernière vue de son propriétaire dans l'espace : créez-en une autre avant d'annuler.`);
|
|
202
238
|
}
|
|
203
239
|
tx.deleteBoardView(view.id);
|
|
204
|
-
return;
|
|
240
|
+
return null;
|
|
205
241
|
}
|
|
242
|
+
case "time_session":
|
|
243
|
+
tx.deleteTimeSession(TimeSessionSchema.parse(current).id);
|
|
244
|
+
return null;
|
|
206
245
|
}
|
|
246
|
+
return null;
|
|
207
247
|
}
|
|
208
248
|
/** Recrée une entité supprimée par l'agent. */
|
|
209
249
|
function recreate(tx, entityType, before) {
|
|
@@ -275,6 +315,8 @@ function restore(tx, entityType, entityId, before) {
|
|
|
275
315
|
}
|
|
276
316
|
case "comment":
|
|
277
317
|
throw new InvariantError("La modification d'un commentaire ne s'annule pas.");
|
|
318
|
+
case "attachment":
|
|
319
|
+
throw new InvariantError("La modification d'une pièce jointe ne s'annule pas.");
|
|
278
320
|
case "board_view": {
|
|
279
321
|
const view = BoardViewSchema.parse(before);
|
|
280
322
|
requireViewAssignees(tx, view);
|
|
@@ -286,6 +328,11 @@ function restore(tx, entityType, entityId, before) {
|
|
|
286
328
|
tx.restoreFollowUpState(entityId, { doneAt, doneBy, doneByRequestId });
|
|
287
329
|
return;
|
|
288
330
|
}
|
|
331
|
+
case "time_session": {
|
|
332
|
+
const { runningSince, elapsedMs, endedAt } = TimeSessionSchema.parse(before);
|
|
333
|
+
tx.restoreTimeSessionState(entityId, { runningSince, elapsedMs, endedAt });
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
289
336
|
}
|
|
290
337
|
}
|
|
291
338
|
/** Libellés français des champs restaurables d'une tâche ; « position » est le rang dans une même colonne. */
|