Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/ui/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,19 @@ export function generateCore() {
const isWriterCloudApp = computed(() =>
Boolean(writerAppId.value || writerOrgId.value),
);
// ABv1 edit gating is only enforced while an ABv2 deprecation flag is
// active. Without a deprecation flag (e.g. the producer that sends the
// permission headers hasn't shipped, or the org is not in the deprecation
// rollout), editing is always permitted so the block cannot engage
// unintentionally.
const isAbv1EditGatingEnabled = computed(
() =>
featureFlags.value.includes("beforeDeprecationCutoffAbv2") ||
featureFlags.value.includes("afterDeprecationCutoffAbv2"),
);
const canEditAgent = computed(
() =>
!isAbv1EditGatingEnabled.value ||
!isWriterCloudApp.value ||
isOrganizationAdmin.value ||
Boolean(writerApplication.value?.canEdit),
Expand Down
66 changes: 66 additions & 0 deletions src/ui/src/tests/canEditAgent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { describe, it, expect } from "vitest";
import { buildMockCore } from "./mocks";

describe("canEditAgent gating", () => {
function setup() {
const { core, featureFlags, writerApplication } = buildMockCore();
return { core, featureFlags, writerApplication };
}

it("allows editing outside of Writer cloud", () => {
const { core, featureFlags } = setup();
featureFlags.value = ["beforeDeprecationCutoffAbv2"];
expect(core.canEditAgent.value).toBe(true);
});

it("does not block editing when no deprecation flag is active", () => {
const { core, featureFlags, writerApplication } = setup();
writerApplication.value = {
id: "app-1",
organizationId: "1",
isOrganizationAdmin: false,
canEdit: false,
};
featureFlags.value = [];
expect(core.canEditAgent.value).toBe(true);
});

it.each(["beforeDeprecationCutoffAbv2", "afterDeprecationCutoffAbv2"])(
"blocks editing for a non-admin without edit access when %s is active",
(flag) => {
const { core, featureFlags, writerApplication } = setup();
writerApplication.value = {
id: "app-1",
organizationId: "1",
isOrganizationAdmin: false,
canEdit: false,
};
featureFlags.value = [flag];
expect(core.canEditAgent.value).toBe(false);
},
);

it("allows editing for an org admin when gating is active", () => {
const { core, featureFlags, writerApplication } = setup();
writerApplication.value = {
id: "app-1",
organizationId: "1",
isOrganizationAdmin: true,
canEdit: false,
};
featureFlags.value = ["beforeDeprecationCutoffAbv2"];
expect(core.canEditAgent.value).toBe(true);
});

it("allows editing when canEdit is granted and gating is active", () => {
const { core, featureFlags, writerApplication } = setup();
writerApplication.value = {
id: "app-1",
organizationId: "1",
isOrganizationAdmin: false,
canEdit: true,
};
featureFlags.value = ["afterDeprecationCutoffAbv2"];
expect(core.canEditAgent.value).toBe(true);
});
});
4 changes: 4 additions & 0 deletions src/ui/src/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export function buildMockCore() {
);
core.canEditAgent = computed(
() =>
!(
featureFlags.value.includes("beforeDeprecationCutoffAbv2") ||
featureFlags.value.includes("afterDeprecationCutoffAbv2")
) ||
!core.isWriterCloudApp.value ||
core.isOrganizationAdmin.value ||
Boolean(writerApplication.value?.canEdit),
Expand Down
Loading