fix: Show 404 page for nonexistent org (#2620)
Renders 404 page if org in URL doesn't exist.
This commit is contained in:
parent
5b0f851857
commit
7c32e27f94
@ -85,7 +85,7 @@ describe("browsertrix-app", () => {
|
|||||||
expect(el.shadowRoot?.childElementCount).to.not.equal(0);
|
expect(el.shadowRoot?.childElementCount).to.not.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders org when authenticated", async () => {
|
it("renders 404 when not in org", async () => {
|
||||||
stub(AuthService, "initSessionStorage").returns(
|
stub(AuthService, "initSessionStorage").returns(
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
headers: { Authorization: "_fake_headers_" },
|
headers: { Authorization: "_fake_headers_" },
|
||||||
@ -95,7 +95,46 @@ describe("browsertrix-app", () => {
|
|||||||
);
|
);
|
||||||
// @ts-expect-error checkFreshness is private
|
// @ts-expect-error checkFreshness is private
|
||||||
stub(AuthService.prototype, "checkFreshness");
|
stub(AuthService.prototype, "checkFreshness");
|
||||||
AppStateService.updateOrgSlug("fake-org");
|
|
||||||
|
AppStateService.updateUser(
|
||||||
|
formatAPIUser({
|
||||||
|
...mockAPIUser,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
AppStateService.updateOrgSlug("nonexistent-org");
|
||||||
|
const el = await fixture<App>(
|
||||||
|
html` <browsertrix-app .settings=${mockAppSettings}></browsertrix-app>`,
|
||||||
|
);
|
||||||
|
await el.updateComplete;
|
||||||
|
expect(el.shadowRoot?.querySelector("btrix-not-found")).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders org when in org", async () => {
|
||||||
|
const id = self.crypto.randomUUID();
|
||||||
|
const mockOrg = {
|
||||||
|
id: id,
|
||||||
|
name: "test org 2",
|
||||||
|
slug: "test-org-2",
|
||||||
|
role: 10,
|
||||||
|
};
|
||||||
|
|
||||||
|
stub(AuthService, "initSessionStorage").returns(
|
||||||
|
Promise.resolve({
|
||||||
|
headers: { Authorization: "_fake_headers_" },
|
||||||
|
tokenExpiresAt: 0,
|
||||||
|
username: "test-auth@example.com",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
// @ts-expect-error checkFreshness is private
|
||||||
|
stub(AuthService.prototype, "checkFreshness");
|
||||||
|
|
||||||
|
AppStateService.updateUser(
|
||||||
|
formatAPIUser({
|
||||||
|
...mockAPIUser,
|
||||||
|
orgs: [...mockAPIUser.orgs, mockOrg],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
AppStateService.updateOrgSlug("test-org-2");
|
||||||
const el = await fixture<App>(
|
const el = await fixture<App>(
|
||||||
html` <browsertrix-app .settings=${mockAppSettings}></browsertrix-app>`,
|
html` <browsertrix-app .settings=${mockAppSettings}></browsertrix-app>`,
|
||||||
);
|
);
|
||||||
|
@ -521,7 +521,6 @@ export class App extends BtrixElement {
|
|||||||
>
|
>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
<div role="separator" class="mx-2.5 h-7 w-0 border-l"></div>
|
|
||||||
${this.renderOrgs()}
|
${this.renderOrgs()}
|
||||||
`,
|
`,
|
||||||
)}
|
)}
|
||||||
@ -639,12 +638,12 @@ export class App extends BtrixElement {
|
|||||||
|
|
||||||
const selectedOption = this.orgSlugInPath
|
const selectedOption = this.orgSlugInPath
|
||||||
? orgs.find(({ slug }) => slug === this.orgSlugInPath)
|
? orgs.find(({ slug }) => slug === this.orgSlugInPath)
|
||||||
: { slug: "", name: msg("All Organizations") };
|
: {
|
||||||
|
slug: "",
|
||||||
|
name: msg("All Organizations"),
|
||||||
|
};
|
||||||
|
|
||||||
if (!selectedOption) {
|
if (!selectedOption) {
|
||||||
console.debug(
|
|
||||||
`Couldn't find organization with slug ${this.orgSlugInPath}`,
|
|
||||||
orgs,
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,6 +651,7 @@ export class App extends BtrixElement {
|
|||||||
const orgNameLength = 50;
|
const orgNameLength = 50;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
|
<div role="separator" class="mx-2.5 h-7 w-0 border-l"></div>
|
||||||
<div class="max-w-32 truncate sm:max-w-52 md:max-w-none">
|
<div class="max-w-32 truncate sm:max-w-52 md:max-w-none">
|
||||||
${selectedOption.slug
|
${selectedOption.slug
|
||||||
? html`
|
? html`
|
||||||
@ -869,6 +869,10 @@ export class App extends BtrixElement {
|
|||||||
return html`<btrix-orgs class="w-full md:bg-neutral-50"></btrix-orgs>`;
|
return html`<btrix-orgs class="w-full md:bg-neutral-50"></btrix-orgs>`;
|
||||||
|
|
||||||
case "org": {
|
case "org": {
|
||||||
|
if (!this.isUserInCurrentOrg) {
|
||||||
|
return this.renderNotFoundPage();
|
||||||
|
}
|
||||||
|
|
||||||
const slug = this.viewState.params.slug;
|
const slug = this.viewState.params.slug;
|
||||||
const orgPath = this.viewState.pathname;
|
const orgPath = this.viewState.pathname;
|
||||||
const pathname = this.getLocationPathname();
|
const pathname = this.getLocationPathname();
|
||||||
|
Loading…
Reference in New Issue
Block a user