From 20d04553d6e038a97c87822644dcbb3705ae2619 Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Mon, 20 Jan 2025 11:35:29 +0100 Subject: [PATCH] fix(RBAC): restore manage_account permission for roles (#6602) --- ui/actions/roles/roles.ts | 10 ++++------ ui/components/roles/workflow/forms/add-role-form.tsx | 9 +++------ ui/components/roles/workflow/forms/edit-role-form.tsx | 8 +++----- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/ui/actions/roles/roles.ts b/ui/actions/roles/roles.ts index 977cfeedda..6bd92e8034 100644 --- a/ui/actions/roles/roles.ts +++ b/ui/actions/roles/roles.ts @@ -90,6 +90,7 @@ export const addRole = async (formData: FormData) => { manage_users: formData.get("manage_users") === "true", manage_providers: formData.get("manage_providers") === "true", manage_scans: formData.get("manage_scans") === "true", + manage_account: formData.get("manage_account") === "true", // TODO: Add back when we have integrations ready // manage_integrations: formData.get("manage_integrations") === "true", unlimited_visibility: formData.get("unlimited_visibility") === "true", @@ -98,10 +99,8 @@ export const addRole = async (formData: FormData) => { }, }; - // Conditionally include manage_account and manage_billing for cloud environment + // Conditionally include manage_billing for cloud environment if (process.env.NEXT_PUBLIC_IS_CLOUD_ENV === "true") { - payload.data.attributes.manage_account = - formData.get("manage_account") === "true"; payload.data.attributes.manage_billing = formData.get("manage_billing") === "true"; } @@ -157,6 +156,7 @@ export const updateRole = async (formData: FormData, roleId: string) => { ...(name && { name }), // Include name only if provided manage_users: formData.get("manage_users") === "true", manage_providers: formData.get("manage_providers") === "true", + manage_account: formData.get("manage_account") === "true", manage_scans: formData.get("manage_scans") === "true", // TODO: Add back when we have integrations ready // manage_integrations: formData.get("manage_integrations") === "true", @@ -166,10 +166,8 @@ export const updateRole = async (formData: FormData, roleId: string) => { }, }; - // Conditionally include manage_account and manage_billing for cloud environments + // Conditionally include manage_billing for cloud environments if (process.env.NEXT_PUBLIC_IS_CLOUD_ENV === "true") { - payload.data.attributes.manage_account = - formData.get("manage_account") === "true"; payload.data.attributes.manage_billing = formData.get("manage_billing") === "true"; } diff --git a/ui/components/roles/workflow/forms/add-role-form.tsx b/ui/components/roles/workflow/forms/add-role-form.tsx index 38cf897ccb..bb07254eac 100644 --- a/ui/components/roles/workflow/forms/add-role-form.tsx +++ b/ui/components/roles/workflow/forms/add-role-form.tsx @@ -38,7 +38,6 @@ export const AddRoleForm = ({ unlimited_visibility: false, groups: [], ...(process.env.NEXT_PUBLIC_IS_CLOUD_ENV === "true" && { - manage_account: false, manage_billing: false, }), }, @@ -85,6 +84,7 @@ export const AddRoleForm = ({ formData.append("manage_users", String(values.manage_users)); formData.append("manage_providers", String(values.manage_providers)); formData.append("manage_scans", String(values.manage_scans)); + formData.append("manage_account", String(values.manage_account)); formData.append( "unlimited_visibility", String(values.unlimited_visibility), @@ -92,7 +92,6 @@ export const AddRoleForm = ({ // Conditionally append manage_account and manage_billing if (process.env.NEXT_PUBLIC_IS_CLOUD_ENV === "true") { - formData.append("manage_account", String(values.manage_account)); formData.append("manage_billing", String(values.manage_billing)); } @@ -142,12 +141,10 @@ export const AddRoleForm = ({ const permissions = [ { field: "manage_users", label: "Invite and Manage Users" }, ...(process.env.NEXT_PUBLIC_IS_CLOUD_ENV === "true" - ? [ - { field: "manage_account", label: "Manage Account" }, - { field: "manage_billing", label: "Manage Billing" }, - ] + ? [{ field: "manage_billing", label: "Manage Billing" }] : []), { field: "manage_providers", label: "Manage Cloud Providers" }, + { field: "manage_account", label: "Manage Account" }, // TODO: Add back when we have integrations ready // { field: "manage_integrations", label: "Manage Integrations" }, { field: "manage_scans", label: "Manage Scans" }, diff --git a/ui/components/roles/workflow/forms/edit-role-form.tsx b/ui/components/roles/workflow/forms/edit-role-form.tsx index 21522ded6f..0ff7eea256 100644 --- a/ui/components/roles/workflow/forms/edit-role-form.tsx +++ b/ui/components/roles/workflow/forms/edit-role-form.tsx @@ -96,12 +96,12 @@ export const EditRoleForm = ({ updatedFields.manage_users = values.manage_users; updatedFields.manage_providers = values.manage_providers; + updatedFields.manage_account = values.manage_account; // updatedFields.manage_integrations = values.manage_integrations; updatedFields.manage_scans = values.manage_scans; updatedFields.unlimited_visibility = values.unlimited_visibility; if (process.env.NEXT_PUBLIC_IS_CLOUD_ENV === "true") { - updatedFields.manage_account = values.manage_account; updatedFields.manage_billing = values.manage_billing; } @@ -165,11 +165,9 @@ export const EditRoleForm = ({ const permissions = [ { field: "manage_users", label: "Invite and Manage Users" }, ...(process.env.NEXT_PUBLIC_IS_CLOUD_ENV === "true" - ? [ - { field: "manage_account", label: "Manage Account" }, - { field: "manage_billing", label: "Manage Billing" }, - ] + ? [{ field: "manage_billing", label: "Manage Billing" }] : []), + { field: "manage_account", label: "Manage Account" }, { field: "manage_providers", label: "Manage Cloud Providers" }, // TODO: Add back when we have integrations ready // { field: "manage_integrations", label: "Manage Integrations" },