Skip to content

Commit

Permalink
Merge pull request #277 from xairam/DifferentOwner
Browse files Browse the repository at this point in the history
Enables different owner of the executed document
  • Loading branch information
clusterzx authored Feb 4, 2025
2 parents 856ab77 + 1a39d48 commit f16dfde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 7 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
15 changes: 14 additions & 1 deletion services/paperlessService.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ async getOrCreateDocumentType(name) {
return null;
}
}

//Remove if not needed?
async getOwnerOfDocument(documentId) {
this.initialize();
try {
Expand All @@ -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;
Expand Down

0 comments on commit f16dfde

Please sign in to comment.