Suppress draft doc reading by team through direct url

This commit is contained in:
Saumya Pandey committed 2021-08-25 01:31:40 +05:30
1 parent f6d889f759
commit 2f09ef1928
2 files changed
+13 -5

No files matched your search

+1
View File
@@ -536,6 +536,7 @@ async function loadDocument({
// If the user has access to read the document, we can just update
// the last access date and return the document without additional checks.
document.fromShare = true;
const canReadDocument = can(user, "read", document);
if (canReadDocument) {
await share.update({ lastAccessedAt: new Date() });
+12 -5
View File
@@ -11,6 +11,13 @@ allow(User, "createDocument", Team, (user, team) => {
});
allow(User, ["read", "download"], Document, (user, document) => {
if (
!document.fromShare &&
!document.publishedAt &&
document.createdBy !== user.id
)
return false;
// existence of collection option is not required here to account for share tokens
if (document.collection && cannot(user, "read", document.collection)) {
return false;
@@ -23,6 +30,7 @@ allow(User, ["star", "unstar"], Document, (user, document) => {
if (document.archivedAt) return false;
if (document.deletedAt) return false;
if (document.template) return false;
if (!document.publishedAt && document.createdBy !== user.id) return false;
invariant(
document.collection,
@@ -36,6 +44,7 @@ allow(User, ["star", "unstar"], Document, (user, document) => {
allow(User, "share", Document, (user, document) => {
if (document.archivedAt) return false;
if (document.deletedAt) return false;
if (!document.publishedAt && document.createdBy !== user.id) return false;
if (cannot(user, "share", document.collection)) {
return false;
@@ -47,6 +56,7 @@ allow(User, "share", Document, (user, document) => {
allow(User, "update", Document, (user, document) => {
if (document.archivedAt) return false;
if (document.deletedAt) return false;
if (!document.publishedAt && document.createdBy.id !== user.id) return false;
if (cannot(user, "update", document.collection)) {
return false;
@@ -102,6 +112,7 @@ allow(User, ["pin", "unpin"], Document, (user, document) => {
allow(User, "delete", Document, (user, document) => {
if (user.isViewer) return false;
if (document.deletedAt) return false;
if (!document.publishedAt && document.createdBy !== user.id) return false;
// allow deleting document without a collection
if (document.collection && cannot(user, "update", document.collection)) {
@@ -109,11 +120,7 @@ allow(User, "delete", Document, (user, document) => {
}
// unpublished drafts can always be deleted
if (
!document.deletedAt &&
!document.publishedAt &&
user.teamId === document.teamId
) {
if (!document.publishedAt && user.teamId === document.teamId) {
return true;
}