Skip to content

Commit

Permalink
📁 feat: restrict access to drive search result (#2758)
Browse files Browse the repository at this point in the history
  • Loading branch information
MontaGhanmy committed Feb 23, 2023
1 parent 40057f7 commit 3be5fe0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion twake/backend/node/src/services/documents/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ export class DocumentsService {
options: SearchDocumentsOptions,
context?: DriveExecutionContext,
): Promise<ListResult<DriveFile>> => {
return await this.searchRepository.search(
const result = await this.searchRepository.search(
{},
{
pagination: {
Expand All @@ -726,5 +726,22 @@ export class DocumentsService {
},
context,
);

// Use Promise.all to check access on each item in parallel
const filteredResult = await Promise.all(
result.getEntities().filter(async item => {
try {
// Check access for each item
const hasAccess = await checkAccess(item.id, null, "read", this.repository, context);
// Return true if the user has access
return hasAccess;
} catch (error) {
this.logger.warn("failed to check item access", error);
return false;
}
}),
);

return new ListResult(result.type, filteredResult, result.nextPage);
};
}

0 comments on commit 3be5fe0

Please sign in to comment.