-
Notifications
You must be signed in to change notification settings - Fork 178
View as project home #8735
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
View as project home #8735
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Use the existing GetProjectWithBearerToken pattern to fetch the impersonated user's projectPermissions from the server, rather than reconstructing permissions client-side. Changes: - Project layout calls GetProjectWithBearerToken with the mocked user's JWT (from GetDeploymentCredentials) to get their actual permissions - Created effectivePermissionsStore to share permissions with TopNavBar - ProjectTabs uses effectiveProjectPermissions (impersonated user's permissions when View As is active) - TopNavigationBar uses effective permissions for Share button visibility This follows the existing architecture where the server is the single source of truth for permissions, rather than duplicating permission logic on the client. Co-authored-by: ericokuma <ericokuma@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { writable } from "svelte/store"; | ||
| import type { V1ProjectPermissions } from "../../client"; | ||
|
|
||
| /** | ||
| * Store for effective project permissions when "View As" is active. | ||
| * When null, the actual user's permissions should be used. | ||
| * When set, these are the impersonated user's permissions (from server). | ||
| */ | ||
| export const effectiveProjectPermissionsStore = | ||
| writable<V1ProjectPermissions | null>(null); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This store can be eliminated — see the top-level comment for the TanStack Query dedup approach. When TopNavigationBar creates its own query observers (matching the same query keys the project layout uses), TanStack gives it instant cache hits. No side-channel store needed. This also follows the existing |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ | |
| import { createAdminServiceGetProjectWithBearerToken } from "@rilldata/web-admin/features/public-urls/get-project-with-bearer-token"; | ||
| import { cloudVersion } from "@rilldata/web-admin/features/telemetry/initCloudMetrics"; | ||
| import { viewAsUserStore } from "@rilldata/web-admin/features/view-as-user/viewAsUserStore"; | ||
| import { effectiveProjectPermissionsStore } from "@rilldata/web-admin/features/view-as-user/effectivePermissionsStore"; | ||
| import ErrorPage from "@rilldata/web-common/components/ErrorPage.svelte"; | ||
| import { metricsService } from "@rilldata/web-common/metrics/initMetrics"; | ||
| import RuntimeProvider from "@rilldata/web-common/runtime-client/RuntimeProvider.svelte"; | ||
|
|
@@ -122,7 +123,41 @@ | |
| $: ({ data: mockedUserDeploymentCredentials } = | ||
| $mockedUserDeploymentCredentialsQuery); | ||
|
|
||
| /** | ||
| * When "View As" is active, fetch the project using the mocked user's JWT. | ||
| * This returns the impersonated user's `projectPermissions` from the server. | ||
| */ | ||
| $: mockedUserProjectQuery = createAdminServiceGetProjectWithBearerToken( | ||
| organization, | ||
| project, | ||
| mockedUserDeploymentCredentials?.accessToken ?? "", | ||
| undefined, | ||
| { | ||
| query: { | ||
| enabled: !!mockedUserDeploymentCredentials?.accessToken, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| $: ({ data: projectData, error: projectError } = $projectQuery); | ||
|
|
||
| /** | ||
| * Compute effective project permissions. | ||
| * When "View As" is active, use the impersonated user's permissions (from server). | ||
| * Otherwise, use the actual user's permissions. | ||
| */ | ||
| $: effectiveProjectPermissions = | ||
| mockedUserId && $mockedUserProjectQuery.data?.projectPermissions | ||
| ? $mockedUserProjectQuery.data.projectPermissions | ||
| : projectData?.projectPermissions; | ||
|
|
||
| // Update the global store so TopNavigationBar can access effective permissions | ||
| $: effectiveProjectPermissionsStore.set( | ||
| mockedUserId && $mockedUserProjectQuery.data?.projectPermissions | ||
| ? $mockedUserProjectQuery.data.projectPermissions | ||
| : null, | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition |
||
|
|
||
| $: deploymentStatus = projectData?.deployment?.status; | ||
| // A re-deploy triggers `DEPLOYMENT_STATUS_UPDATING` status. But we can still show the project UI. | ||
| $: isProjectAvailable = | ||
|
|
@@ -168,7 +203,7 @@ | |
|
|
||
| {#if onProjectPage && deploymentStatus === V1DeploymentStatus.DEPLOYMENT_STATUS_RUNNING} | ||
| <ProjectTabs | ||
| projectPermissions={projectData.projectPermissions} | ||
| projectPermissions={effectiveProjectPermissions} | ||
| {organization} | ||
| {pathname} | ||
| {project} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This store can be eliminated — see the top-level comment for the TanStack Query dedup approach. When TopNavigationBar creates its own query observers (matching the same query keys the project layout uses), TanStack gives it instant cache hits. No side-channel store needed. This also follows the existing
ProjectAccessControlspattern, which independently queriesGetProject.