feat: Add preference to disable download option for viewers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import invariant from "invariant";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
import { Document, Revision, User, Team } from "@server/models";
|
||||
import { allow, _cannot as cannot } from "./cancan";
|
||||
|
||||
@@ -9,7 +10,7 @@ allow(User, "createDocument", Team, (user, team) => {
|
||||
return true;
|
||||
});
|
||||
|
||||
allow(User, ["read", "download"], Document, (user, document) => {
|
||||
allow(User, "read", Document, (user, document) => {
|
||||
if (!document) {
|
||||
return false;
|
||||
}
|
||||
@@ -22,6 +23,26 @@ allow(User, ["read", "download"], Document, (user, document) => {
|
||||
return user.teamId === document.teamId;
|
||||
});
|
||||
|
||||
allow(User, "download", Document, (user, document) => {
|
||||
if (!document) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (
|
||||
user.isViewer &&
|
||||
!user.team.getPreference(TeamPreference.ViewersCanExport, true)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return user.teamId === document.teamId;
|
||||
});
|
||||
|
||||
allow(User, "star", Document, (user, document) => {
|
||||
if (!document) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user