diff --git a/server.js b/server.js index 749ead8..1079380 100644 --- a/server.js +++ b/server.js @@ -94,11 +94,14 @@ async function processDocument(doc, existingTags, existingCorrespondentList, own const isProcessed = await documentModel.isDocumentProcessed(doc.id); if (isProcessed) return null; - const documentOwnerId = await paperlessService.getOwnerOfDocument(doc.id); - if (documentOwnerId !== ownUserId && documentOwnerId !== null) { - console.log(`[DEBUG] Document belongs to: ${documentOwnerId}, skipping analysis`); - console.log(`[DEBUG] Document ${doc.id} not owned by user, skipping analysis`); + //Check if the Document can be edited + const documentEditable = await paperlessService.getPermissionOfDocument(doc.id); + if (!documentEditable) { + console.log(`[DEBUG] Document belongs to: ${documentEditable}, skipping analysis`); + console.log(`[DEBUG] Document ${doc.id} Not Editable by Paper-Ai User, skipping analysis`); return null; + }else { + console.log(`[DEBUG] Document ${doc.id} rights for AI User - processed`); } let [content, originalData] = await Promise.all([ diff --git a/services/paperlessService.js b/services/paperlessService.js index 678d3c5..6e33a8d 100644 --- a/services/paperlessService.js +++ b/services/paperlessService.js @@ -946,7 +946,7 @@ async getOrCreateDocumentType(name) { return null; } } - + //Remove if not needed? async getOwnerOfDocument(documentId) { this.initialize(); try { @@ -958,6 +958,19 @@ async getOrCreateDocumentType(name) { } } + // Checks if the document is accessable by the current user + async getPermissionOfDocument(documentId) { + this.initialize(); + try { + const response = await this.client.get(`/documents/${documentId}/`); + return response.data.user_can_change; + } catch (error) { + console.error(`[ERROR] No Permission to edit document ${documentId}:`, error.message); + return null; + } + } + + async updateDocument(documentId, updates) { this.initialize(); if (!this.client) return;