Skip to content

feat: add organization-scoped permission checks to deployment settings #14063

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 20 commits into from
Aug 6, 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
Dedupe disable org permission query
  • Loading branch information
code-asher committed Aug 1, 2024
commit 69c50ecd87e586987379a3ca0dd2995fc6adf9bd
7 changes: 6 additions & 1 deletion site/src/api/queries/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ export const organizations = () => {

/**
* Fetch permissions for a single organization.
*
* If the ID is undefined, return a disabled query.
*/
export const organizationPermissions = (organizationId: string) => {
export const organizationPermissions = (organizationId: string | undefined) => {
if (!organizationId) {
return { enabled: false };
}
return {
queryKey: ["organization", organizationId, "permissions"],
queryFn: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ export const GroupsPage: FC = () => {
// TODO: If we could query permissions based on the name then we would not
// have to cascade off the organizations query.
const organization = organizations?.find((o) => o.name === organizationName);
const permissionsQuery = useQuery(
organization
? organizationPermissions(organization.id)
: { enabled: false },
);
const permissionsQuery = useQuery(organizationPermissions(organization?.id));

useEffect(() => {
if (groupsQuery.error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ const OrganizationMembersPage: FC = () => {
// have to cascade off the organizations query.
const { organizations } = useOrganizationSettings();
const organization = organizations?.find((o) => o.name === organizationName);
const permissionsQuery = useQuery(
organization
? organizationPermissions(organization.id)
: { enabled: false },
);
const permissionsQuery = useQuery(organizationPermissions(organization?.id));

const permissions = permissionsQuery.data;
if (!permissions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ const OrganizationSettingsPage: FC = () => {
// TODO: If we could query permissions based on the name then we would not
// have to cascade off the organizations query.
const organization =
organizations &&
organizationName &&
getOrganizationByName(organizations, organizationName);
const permissionsQuery = useQuery(
organization
? organizationPermissions(organization.id)
: { enabled: false },
);
organizations && organizationName
? getOrganizationByName(organizations, organizationName)
: undefined;
const permissionsQuery = useQuery(organizationPermissions(organization?.id));

if (!organizations) {
return <Loader />;
Expand Down
15 changes: 7 additions & 8 deletions site/src/pages/ManagementSettingsPage/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ interface OrganizationSettingsNavigationProps {
export const OrganizationSettingsNavigation: FC<
OrganizationSettingsNavigationProps
> = ({ organization, active }) => {
const permissionsQuery = useQuery({
...organizationPermissions(organization.id),
// The menu items only show while the menu is expanded, so we can wait until
// expanded to run the query. Downside is that we have to show a loader
// until the query finishes...maybe we should prefetch permissions for all
// the orgs instead?
enabled: active,
});
// The menu items only show while the menu is expanded, so we can wait until
// expanded to run the query. Downside is that we have to show a loader
// until the query finishes...maybe we should prefetch permissions for all
// the orgs instead?
const permissionsQuery = useQuery(
organizationPermissions(active ? organization.id : undefined),
);

return (
<>
Expand Down