mirror of
https://github.com/outline/outline.git
synced 2026-11-26 15:43:48 +03:00
feat: Gate audit log behind AuditLog entitlement
This commit is contained in:
2 files changed
+37
-1
No files matched your search
+11
-1
@@ -1,3 +1,4 @@
|
||||
import { PlanFeature } from "@shared/types";
|
||||
import { Team, User } from "@server/models";
|
||||
import { allow } from "./cancan";
|
||||
import {
|
||||
@@ -7,6 +8,7 @@ import {
|
||||
isTeamModel,
|
||||
isTeamMutable,
|
||||
or,
|
||||
teamHasEntitlement,
|
||||
} from "./utils";
|
||||
|
||||
allow(User, "read", Team, isTeamModel);
|
||||
@@ -41,7 +43,7 @@ allow(User, "createTeam", Team, (actor, team) =>
|
||||
|
||||
allow(User, "update", Team, isTeamAdmin);
|
||||
|
||||
allow(User, ["delete", "audit"], Team, (actor, team) =>
|
||||
allow(User, "delete", Team, (actor, team) =>
|
||||
and(
|
||||
//
|
||||
isCloudHosted(),
|
||||
@@ -49,6 +51,14 @@ allow(User, ["delete", "audit"], Team, (actor, team) =>
|
||||
)
|
||||
);
|
||||
|
||||
allow(User, "audit", Team, (actor, team) =>
|
||||
and(
|
||||
//
|
||||
isTeamAdmin(actor, team),
|
||||
teamHasEntitlement(team, PlanFeature.AuditLog)
|
||||
)
|
||||
);
|
||||
|
||||
allow(User, ["createTemplate", "updateTemplate"], Team, (actor, team) =>
|
||||
and(
|
||||
//
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import type { MockInstance } from "vitest";
|
||||
import { Plan } from "@shared/types";
|
||||
import { Team } from "@server/models";
|
||||
import {
|
||||
buildAdmin,
|
||||
buildCollection,
|
||||
@@ -10,6 +13,18 @@ import { getTestServer } from "@server/test/support";
|
||||
const server = getTestServer();
|
||||
|
||||
describe("#events.list", () => {
|
||||
let planSpy: MockInstance<() => Plan>;
|
||||
|
||||
beforeEach(() => {
|
||||
planSpy = vi
|
||||
.spyOn(Team.prototype, "plan", "get")
|
||||
.mockReturnValue(Plan.Business);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
planSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("should only return activity events", async () => {
|
||||
const user = await buildUser();
|
||||
const admin = await buildAdmin({ teamId: user.teamId });
|
||||
@@ -364,6 +379,17 @@ describe("#events.list", () => {
|
||||
expect(body.data[0].id).toEqual(event.id);
|
||||
});
|
||||
|
||||
it("should require the audit log entitlement", async () => {
|
||||
planSpy.mockReturnValue(Plan.Community);
|
||||
const admin = await buildAdmin();
|
||||
const res = await server.post("/api/events.list", admin, {
|
||||
body: {
|
||||
auditLog: true,
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(403);
|
||||
});
|
||||
|
||||
it("should require authorization for audit events", async () => {
|
||||
const user = await buildUser();
|
||||
const res = await server.post("/api/events.list", user, {
|
||||
|
||||
Reference in new issue
Block a user