Skip to content

Commit

Permalink
feat: Use magic tokens to access external reports (#5917)
Browse files Browse the repository at this point in the history
* Use magic tokens to access reports

* Cleanup
  • Loading branch information
AdityaHegde authored Oct 16, 2024
1 parent 11b9b1b commit 6d737e5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
13 changes: 12 additions & 1 deletion web-admin/src/features/navigation/nav-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ export function isReportExportPage(page: Page): boolean {
}

export function isPublicURLPage(page: Page): boolean {
return page.route.id === "/[organization]/[project]/-/share/[token]";
return (
page.route.id === "/[organization]/[project]/-/share/[token]" ||
isPublicReportPage(page)
);
}

export function isPublicReportPage(page: Page): boolean {
return (
!!page.route.id?.startsWith(
"/[organization]/[project]/-/reports/[report]",
) && page.url.searchParams.has("token")
);
}

export function isProjectRequestAccessPage(page: Page): boolean {
Expand Down
13 changes: 9 additions & 4 deletions web-admin/src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,38 @@ import {
getAdminServiceGetProjectWithBearerTokenQueryKey,
} from "../features/public-urls/get-project-with-bearer-token.js";

export const load = async ({ params }) => {
export const load = async ({ params, url }) => {
const { organization, project, token } = params;
let effectiveToken = token;

if (!organization || !project) {
return {
projectPermissions: <V1ProjectPermissions>{},
};
}

if (url.searchParams.has("token")) {
effectiveToken = url.searchParams.get("token");
}

let queryKey: QueryKey;
let queryFn: QueryFunction<
Awaited<ReturnType<typeof adminServiceGetProject>>
>;

if (token) {
if (effectiveToken) {
queryKey = getAdminServiceGetProjectWithBearerTokenQueryKey(
organization,
project,
token,
effectiveToken,
{},
);

queryFn = ({ signal }) =>
adminServiceGetProjectWithBearerToken(
organization,
project,
token,
effectiveToken,
{},
signal,
);
Expand Down
14 changes: 12 additions & 2 deletions web-admin/src/routes/[organization]/[project]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
type RpcStatus,
type V1GetProjectResponse,
} from "@rilldata/web-admin/client";
import { isProjectPage } from "@rilldata/web-admin/features/navigation/nav-utils";
import {
isProjectPage,
isPublicReportPage,
isPublicURLPage,
} from "@rilldata/web-admin/features/navigation/nav-utils";
import ProjectBuilding from "@rilldata/web-admin/features/projects/ProjectBuilding.svelte";
import ProjectTabs from "@rilldata/web-admin/features/projects/ProjectTabs.svelte";
import RedeployProjectCta from "@rilldata/web-admin/features/projects/RedeployProjectCTA.svelte";
Expand All @@ -62,7 +66,11 @@
$: ({ organization, project, token } = $page.params);
$: onProjectPage = isProjectPage($page);
$: onPublicURLPage = !!token;
$: onPublicURLPage = isPublicURLPage($page);
$: onPublicReportPage = isPublicReportPage($page);
$: if ($page.url.searchParams.has("token")) {
token = $page.url.searchParams.get("token");
}
/**
* `GetProject` with default cookie-based auth.
Expand Down Expand Up @@ -185,4 +193,6 @@
<slot />
</RuntimeProvider>
{/if}
{:else if onPublicReportPage}
<slot />
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import CtaContentContainer from "@rilldata/web-common/components/calls-to-action/CTAContentContainer.svelte";
import CtaLayoutContainer from "@rilldata/web-common/components/calls-to-action/CTALayoutContainer.svelte";
import CtaMessage from "@rilldata/web-common/components/calls-to-action/CTAMessage.svelte";
import type { V1ExportFormat } from "@rilldata/web-common/runtime-client";
import { V1ExportFormat } from "@rilldata/web-common/runtime-client";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
$: organization = $page.params.organization;
Expand All @@ -25,26 +25,21 @@
data: {
instanceId: $runtime.instanceId,
reportId,
format: format as V1ExportFormat,
format: (format as V1ExportFormat) ?? V1ExportFormat.EXPORT_FORMAT_CSV,
executionTime,
limit,
},
});
}
$: if (reportId && format && $runtime) {
$: if (reportId && $runtime) {
triggerDownload();
}
let error: string;
$: {
if (!format) {
error = "format is required";
} else if ($downloadReportMutation.error) {
error =
$downloadReportMutation.error.response?.data?.message ??
"unknown error";
}
$: if ($downloadReportMutation.error) {
error =
$downloadReportMutation.error.response?.data?.message ?? "unknown error";
}
</script>

Expand Down

0 comments on commit 6d737e5

Please sign in to comment.