-
Notifications
You must be signed in to change notification settings - Fork 170
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 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,15 @@ | |
| ); | ||
|
|
||
| onNavigate(({ from, to }) => { | ||
| viewAsUserStore.set(null); | ||
| // Only clear "View As" state when navigating outside of the current project | ||
| const changedProject = | ||
| !from || | ||
| !to || | ||
| from.params.organization !== to.params.organization || | ||
| from.params.project !== to.params.project; | ||
| if (changedProject) { | ||
| viewAsUserStore.set(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 navigation guard should move to the project layout (
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 navigation guard should move to the project layout ( |
||
| } | ||
|
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. onNavigate clears org-level view-as on project changeHigh Severity The Additional Locations (2) |
||
| errorStore.reset(); | ||
|
|
||
| const changedDashboard = | ||
|
|
||


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.