mirror of
https://github.com/outline/outline.git
synced 2026-04-28 21:49:32 -05:00
fix: check doc access before sending mention email (#7664)
* fix: check doc access before sending mention email * refactor --------- Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { Document, User } from "@server/models";
|
||||
import { authorize } from "@server/policies";
|
||||
|
||||
/**
|
||||
* Check if the given user can access a document
|
||||
*
|
||||
* @param user - The user to check
|
||||
* @param documentId - The document to check
|
||||
* @returns Boolean whether the user can access the document
|
||||
*/
|
||||
export const canUserAccessDocument = async (user: User, documentId: string) => {
|
||||
try {
|
||||
const document = await Document.findByPk(documentId, {
|
||||
userId: user.id,
|
||||
});
|
||||
authorize(user, "read", document);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user