Files
Tom Moor a4badbea9c feat: Role preference for collection template mangement (#11821)
* wip

* ui

* test

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-20 23:57:38 -04:00

68 lines
1.5 KiB
TypeScript

import { Template, User, Team } from "@server/models";
import { allow, can } from "./cancan";
import { and, isTeamModel, isTeamMutable, or } from "./utils";
allow(User, "updateTemplate", Team, (actor, team) =>
and(
//
actor.isAdmin,
isTeamModel(actor, team),
isTeamMutable(actor)
)
);
allow(User, "read", Template, (actor, template) =>
and(
isTeamModel(actor, template),
or(
and(!!template?.isWorkspaceTemplate, can(actor, "read", actor.team)),
can(actor, "readDocument", template?.collection)
)
)
);
allow(User, "listRevisions", Template, (actor, template) =>
or(
and(can(actor, "read", template), !actor.isGuest),
and(can(actor, "update", template), actor.isGuest)
)
);
allow(User, ["update", "move", "duplicate"], Template, (actor, template) =>
and(
can(actor, "read", template),
isTeamMutable(actor),
or(
and(
!!template?.isWorkspaceTemplate,
can(actor, "updateTemplate", actor.team)
),
can(actor, "manageTemplate", template?.collection)
)
)
);
allow(User, "delete", Template, (actor, template) =>
and(
//
can(actor, "update", template),
!template?.isDeleted
)
);
allow(User, "restore", Template, (actor, template) =>
and(
//
!!template?.isDeleted,
isTeamModel(actor, template),
isTeamMutable(actor),
or(
and(
!!template?.isWorkspaceTemplate,
can(actor, "updateTemplate", actor.team)
),
can(actor, "manageTemplate", template?.collection)
)
)
);