- Notifications
You must be signed in to change notification settings - Fork906
fix: fix deployment settings navigation issues#16780
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
157 changes: 157 additions & 0 deletionssite/e2e/tests/roles.spec.ts
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,157 @@ | ||
import { type Page, expect, test } from "@playwright/test"; | ||
import { | ||
createOrganization, | ||
createOrganizationMember, | ||
setupApiCalls, | ||
} from "../api"; | ||
import { license, users } from "../constants"; | ||
import { login, requiresLicense } from "../helpers"; | ||
import { beforeCoderTest } from "../hooks"; | ||
test.beforeEach(async ({ page }) => { | ||
beforeCoderTest(page); | ||
}); | ||
type AdminSetting = (typeof adminSettings)[number]; | ||
const adminSettings = [ | ||
"Deployment", | ||
"Organizations", | ||
"Healthcheck", | ||
"Audit Logs", | ||
] as const; | ||
async function hasAccessToAdminSettings(page: Page, settings: AdminSetting[]) { | ||
// Organizations and Audit Logs both require a license to be visible | ||
const visibleSettings = license | ||
? settings | ||
: settings.filter((it) => it !== "Organizations" && it !== "Audit Logs"); | ||
const adminSettingsButton = page.getByRole("button", { | ||
name: "Admin settings", | ||
}); | ||
if (visibleSettings.length < 1) { | ||
await expect(adminSettingsButton).not.toBeVisible(); | ||
return; | ||
} | ||
await adminSettingsButton.click(); | ||
for (const name of visibleSettings) { | ||
await expect(page.getByText(name, { exact: true })).toBeVisible(); | ||
} | ||
const hiddenSettings = adminSettings.filter( | ||
(it) => !visibleSettings.includes(it), | ||
); | ||
for (const name of hiddenSettings) { | ||
await expect(page.getByText(name, { exact: true })).not.toBeVisible(); | ||
} | ||
} | ||
test.describe("roles admin settings access", () => { | ||
test("member cannot see admin settings", async ({ page }) => { | ||
await login(page, users.member); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
// None, "Admin settings" button should not be visible | ||
await hasAccessToAdminSettings(page, []); | ||
}); | ||
test("template admin can see admin settings", async ({ page }) => { | ||
await login(page, users.templateAdmin); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
await hasAccessToAdminSettings(page, ["Deployment", "Organizations"]); | ||
}); | ||
test("user admin can see admin settings", async ({ page }) => { | ||
await login(page, users.userAdmin); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
await hasAccessToAdminSettings(page, ["Deployment", "Organizations"]); | ||
}); | ||
test("auditor can see admin settings", async ({ page }) => { | ||
await login(page, users.auditor); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
await hasAccessToAdminSettings(page, [ | ||
"Deployment", | ||
"Organizations", | ||
"Audit Logs", | ||
]); | ||
}); | ||
test("admin can see admin settings", async ({ page }) => { | ||
aslilac marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
await login(page, users.admin); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
await hasAccessToAdminSettings(page, [ | ||
"Deployment", | ||
"Organizations", | ||
"Healthcheck", | ||
"Audit Logs", | ||
]); | ||
}); | ||
}); | ||
test.describe("org-scoped roles admin settings access", () => { | ||
requiresLicense(); | ||
test.beforeEach(async ({ page }) => { | ||
await login(page); | ||
await setupApiCalls(page); | ||
}); | ||
test("org template admin can see admin settings", async ({ page }) => { | ||
const org = await createOrganization(); | ||
const orgTemplateAdmin = await createOrganizationMember({ | ||
[org.id]: ["organization-template-admin"], | ||
}); | ||
await login(page, orgTemplateAdmin); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
await hasAccessToAdminSettings(page, ["Organizations"]); | ||
}); | ||
test("org user admin can see admin settings", async ({ page }) => { | ||
const org = await createOrganization(); | ||
const orgUserAdmin = await createOrganizationMember({ | ||
[org.id]: ["organization-user-admin"], | ||
}); | ||
await login(page, orgUserAdmin); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
await hasAccessToAdminSettings(page, ["Deployment", "Organizations"]); | ||
}); | ||
test("org auditor can see admin settings", async ({ page }) => { | ||
const org = await createOrganization(); | ||
const orgAuditor = await createOrganizationMember({ | ||
[org.id]: ["organization-auditor"], | ||
}); | ||
await login(page, orgAuditor); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
await hasAccessToAdminSettings(page, ["Organizations", "Audit Logs"]); | ||
}); | ||
test("org admin can see admin settings", async ({ page }) => { | ||
const org = await createOrganization(); | ||
const orgAdmin = await createOrganizationMember({ | ||
[org.id]: ["organization-admin"], | ||
}); | ||
await login(page, orgAdmin); | ||
await page.goto("/", { waitUntil: "domcontentloaded" }); | ||
await hasAccessToAdminSettings(page, [ | ||
"Deployment", | ||
"Organizations", | ||
"Audit Logs", | ||
]); | ||
}); | ||
}); |
17 changes: 0 additions & 17 deletionssite/src/api/queries/organizations.ts
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
6 changes: 3 additions & 3 deletionssite/src/contexts/auth/AuthProvider.tsx
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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.