-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(webapp): gate SSO on an entitlement instead of the Enterprise plan #4393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d6f9224
feat(webapp): gate SSO on the hasSso entitlement instead of the Enter…
matt-aitken a4a15d9
test(webapp): cover the SSO entitlement gate on directory sync
matt-aitken f616908
fix(webapp): drive the SSO upsell from the loader's entitlement decision
matt-aitken 6818be9
docs(webapp): clarify the SSO release note
matt-aitken 5bb49da
fix(webapp): bust the SSO entitlement cache on plan changes
matt-aitken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: improvement | ||
| --- | ||
|
|
||
| SSO and Directory Sync are no longer restricted to Enterprise plans — get in touch and we can turn them on for your organization whatever plan you're on. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| import type { DirectorySyncEffect } from "@trigger.dev/plugins"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| vi.mock("~/db.server", () => ({ prisma: {}, $replica: {} })); | ||
| vi.mock("~/services/platformNotifications.server", () => ({ | ||
| createPlatformNotification: vi.fn(), | ||
| })); | ||
|
|
||
| const getSsoEntitlement = vi.fn(); | ||
| vi.mock("~/services/platform.v3.server", async (importOriginal) => { | ||
| const actual = (await importOriginal()) as Record<string, unknown>; | ||
| return { ...actual, getSsoEntitlement: (orgId: string) => getSsoEntitlement(orgId) }; | ||
| }); | ||
|
|
||
| const setUserRole = vi.fn(); | ||
| vi.mock("~/services/rbac.server", () => ({ | ||
| rbac: { setUserRole: (a: unknown) => setUserRole(a) }, | ||
| })); | ||
|
|
||
| const ensureOrgMember = vi.fn(); | ||
| const ensureUserForDirectory = vi.fn(); | ||
| const removeOrgMemberForDirectory = vi.fn(); | ||
| vi.mock("~/models/orgMember.server", () => ({ | ||
| ensureOrgMember: (a: unknown) => ensureOrgMember(a), | ||
| ensureUserForDirectory: (a: unknown) => ensureUserForDirectory(a), | ||
| removeOrgMemberForDirectory: (a: unknown) => removeOrgMemberForDirectory(a), | ||
| })); | ||
|
|
||
| import { applyDirectorySyncEffects } from "~/services/directorySyncEffects.server"; | ||
|
|
||
| const ENTITLED_ORG = "org_entitled"; | ||
| const UNENTITLED_ORG = "org_unentitled"; | ||
|
|
||
| function provision(organizationId: string, email = "someone@acme.com"): DirectorySyncEffect { | ||
| return { | ||
| kind: "provision", | ||
| userId: "user_1", | ||
| email, | ||
| firstName: null, | ||
| lastName: null, | ||
| organizationId, | ||
| roleId: null, | ||
| }; | ||
| } | ||
|
|
||
| function deprovision(organizationId: string): DirectorySyncEffect { | ||
| return { kind: "deprovision", userId: "user_1", organizationId }; | ||
| } | ||
|
|
||
| describe("applyDirectorySyncEffects — SSO entitlement gate", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| ensureOrgMember.mockResolvedValue(undefined); | ||
| removeOrgMemberForDirectory.mockResolvedValue({ removed: true }); | ||
| setUserRole.mockResolvedValue({ ok: true }); | ||
| }); | ||
|
|
||
| it("applies effects for an entitled org", async () => { | ||
| getSsoEntitlement.mockResolvedValue("entitled"); | ||
|
|
||
| await applyDirectorySyncEffects([provision(ENTITLED_ORG)]); | ||
|
|
||
| expect(ensureOrgMember).toHaveBeenCalledTimes(1); | ||
| expect(ensureOrgMember).toHaveBeenCalledWith( | ||
| expect.objectContaining({ organizationId: ENTITLED_ORG, source: "directory_sync" }) | ||
| ); | ||
| }); | ||
|
|
||
| it("skips provisioning for an org without the entitlement", async () => { | ||
| getSsoEntitlement.mockResolvedValue("not_entitled"); | ||
|
|
||
| await applyDirectorySyncEffects([provision(UNENTITLED_ORG)]); | ||
|
|
||
| expect(ensureOrgMember).not.toHaveBeenCalled(); | ||
| expect(ensureUserForDirectory).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("skips deprovisioning too, so revocation cannot remove members", async () => { | ||
| getSsoEntitlement.mockResolvedValue("not_entitled"); | ||
|
|
||
| await applyDirectorySyncEffects([deprovision(UNENTITLED_ORG)]); | ||
|
|
||
| expect(removeOrgMemberForDirectory).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("throws on an unreadable entitlement so the worker retries", async () => { | ||
| getSsoEntitlement.mockResolvedValue("unknown"); | ||
|
|
||
| await expect(applyDirectorySyncEffects([provision(ENTITLED_ORG)])).rejects.toThrow( | ||
| /could not read the SSO entitlement/ | ||
| ); | ||
|
|
||
| expect(ensureOrgMember).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("marks the retry as a warning rather than a pageable error", async () => { | ||
| getSsoEntitlement.mockResolvedValue("unknown"); | ||
|
|
||
| await applyDirectorySyncEffects([provision(ENTITLED_ORG)]).then( | ||
| () => expect.unreachable("should have thrown"), | ||
| (error) => expect(error).toMatchObject({ logLevel: "warn" }) | ||
| ); | ||
| }); | ||
|
|
||
| it("resolves the entitlement once per org across a batch", async () => { | ||
| getSsoEntitlement.mockResolvedValue("entitled"); | ||
|
|
||
| await applyDirectorySyncEffects([ | ||
| provision(ENTITLED_ORG, "a@acme.com"), | ||
| provision(ENTITLED_ORG, "b@acme.com"), | ||
| provision(ENTITLED_ORG, "c@acme.com"), | ||
| ]); | ||
|
|
||
| expect(getSsoEntitlement).toHaveBeenCalledTimes(1); | ||
| expect(ensureOrgMember).toHaveBeenCalledTimes(3); | ||
| }); | ||
|
|
||
| it("gates per org, so one unentitled org does not block another", async () => { | ||
| getSsoEntitlement.mockImplementation(async (orgId: string) => | ||
| orgId === ENTITLED_ORG ? "entitled" : "not_entitled" | ||
| ); | ||
|
|
||
| await applyDirectorySyncEffects([provision(UNENTITLED_ORG), provision(ENTITLED_ORG)]); | ||
|
|
||
| expect(ensureOrgMember).toHaveBeenCalledTimes(1); | ||
| expect(ensureOrgMember).toHaveBeenCalledWith( | ||
| expect.objectContaining({ organizationId: ENTITLED_ORG }) | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.