Skip to content

fix: only show editable orgs on deployment page #14193

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

Merged
merged 14 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass in ids instead of entire orgs
  • Loading branch information
code-asher committed Aug 8, 2024
commit e4f5bf7f0c4c03e76bb73567ed2b8e38f357ec58
13 changes: 6 additions & 7 deletions site/src/api/queries/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { API } from "api/api";
import type {
AuthorizationResponse,
CreateOrganizationRequest,
Organization,
UpdateOrganizationRequest,
} from "api/typesGenerated";
import { meKey } from "./users";
Expand Down Expand Up @@ -169,9 +168,9 @@ export const organizationPermissions = (organizationId: string | undefined) => {
* If organizations are undefined, return a disabled query.
*/
export const organizationsPermissions = (
organizations: Organization[] | undefined,
organizationIds: string[] | undefined,
) => {
if (!organizations) {
if (!organizationIds) {
return { enabled: false };
}

Expand Down Expand Up @@ -215,10 +214,10 @@ export const organizationsPermissions = (

// The endpoint takes a flat array, so to avoid collisions prepend each
// check with the org ID (the key can be anything we want).
const prefixedChecks = organizations
.map((org) =>
Object.entries(checks(org.id)).map(([key, val]) => [
`${org.id}.${key}`,
const prefixedChecks = organizationIds
.map((orgId) =>
Object.entries(checks(orgId)).map(([key, val]) => [
`${orgId}.${key}`,
val,
]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const OrganizationSettingsPage: FC = () => {
organizations && organizationName
? getOrganizationByName(organizations, organizationName)
: undefined;
const permissionsQuery = useQuery(organizationsPermissions(organizations));
const permissionsQuery = useQuery(
organizationsPermissions(organizations?.map((o) => o.id)),
);

const permissions = permissionsQuery.data;
if (!organizations || !permissions) {
Expand Down
4 changes: 3 additions & 1 deletion site/src/pages/ManagementSettingsPage/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const Sidebar: FC = () => {
organization?: string;
};

const orgPermissionsQuery = useQuery(organizationsPermissions(organizations));
const orgPermissionsQuery = useQuery(
organizationsPermissions(organizations?.map((o) => o.id)),
);

// Sometimes a user can read an organization but cannot actually do anything
// with it. For now, these are filtered out so you only see organizations you
Expand Down