Files
Tom Moor 93509564e0 Update template management policies (#11608)
* Template management policies

* PR feedback

* fix: Should not be able to navigate to template edit screen
Remove unused action
Add 'New document from template' to template menu
2026-03-01 09:48:17 -05:00

60 lines
1.0 KiB
TypeScript

import { Team, User } from "@server/models";
import { allow } from "./cancan";
import {
and,
isCloudHosted,
isTeamAdmin,
isTeamModel,
isTeamMutable,
or,
} from "./utils";
allow(User, "read", Team, isTeamModel);
allow(User, "readTemplate", Team, (actor, team) =>
and(
//
!actor.isGuest,
!actor.isViewer,
isTeamModel(actor, team)
)
);
allow(User, "share", Team, (actor, team) =>
and(
isTeamModel(actor, team),
!actor.isGuest,
!actor.isViewer,
!!team?.sharing
)
);
allow(User, "createTeam", Team, (actor, team) =>
and(
//
isCloudHosted(),
!actor.isGuest,
!actor.isViewer,
or(actor.isAdmin, !!team?.memberTeamCreate)
)
);
allow(User, "update", Team, isTeamAdmin);
allow(User, ["delete", "audit"], Team, (actor, team) =>
and(
//
isCloudHosted(),
isTeamAdmin(actor, team)
)
);
allow(User, ["createTemplate", "updateTemplate"], Team, (actor, team) =>
and(
//
actor.isAdmin,
isTeamModel(actor, team),
isTeamMutable(actor)
)
);