diff --git a/CHANGELOG.md b/CHANGELOG.md index b007adff..2423f10e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + ## [Unreleased] +### Added + +- Add condition to use the `manage-organization` permission + ## [1.26.1] - 2023-08-11 ### Changed diff --git a/react/components/EditUserModal.tsx b/react/components/EditUserModal.tsx index f69ad72c..c9bcfcbf 100644 --- a/react/components/EditUserModal.tsx +++ b/react/components/EditUserModal.tsx @@ -23,6 +23,7 @@ interface Props { canEdit?: boolean canEditSales?: boolean isSalesAdmin: boolean + canManageOrg?: boolean } interface DropdownOption { @@ -42,6 +43,7 @@ const EditUserModal: FunctionComponent = ({ canEdit, canEditSales, isSalesAdmin, + canManageOrg }) => { const { formatMessage } = useIntl() const [userState, setUserState] = useState({} as UserDetails) @@ -114,6 +116,10 @@ const EditUserModal: FunctionComponent = ({ const filteredArray = rolesData.listRoles.filter((role: any) => { if (isAdmin) return true + if(canManageOrg) { + return true + } + if (role.slug.includes('customer') && canEdit) { return true } diff --git a/react/components/NewUserModal.tsx b/react/components/NewUserModal.tsx index 8f8b104f..5331a19a 100644 --- a/react/components/NewUserModal.tsx +++ b/react/components/NewUserModal.tsx @@ -22,6 +22,7 @@ interface Props { canEdit?: boolean canEditSales?: boolean isSalesAdmin?: boolean + canManageOrg: boolean } interface DropdownOption { @@ -39,6 +40,7 @@ const NewUserModal: FunctionComponent = ({ canEdit, canEditSales, isSalesAdmin, + canManageOrg }) => { const { formatMessage } = useIntl() const [userState, setUserState] = useState({ @@ -117,6 +119,8 @@ const NewUserModal: FunctionComponent = ({ const filteredArray = rolesData.listRoles.filter((role: any) => { if (isAdmin) return true + if(canManageOrg) return true + if (role.slug.includes('customer') && canEdit) { return true } diff --git a/react/components/OrganizationUsersTable.tsx b/react/components/OrganizationUsersTable.tsx index 03ecd0ab..2f8f3742 100644 --- a/react/components/OrganizationUsersTable.tsx +++ b/react/components/OrganizationUsersTable.tsx @@ -108,7 +108,10 @@ const OrganizationUsersTable: FunctionComponent = ({ } } + const canManageOrganization = permissions.includes('manage-organization') + const canEdit = isAdmin || permissions.includes('add-users-organization') + const canEditSales = isAdmin || permissions.includes('add-sales-users-all') || @@ -387,14 +390,19 @@ const OrganizationUsersTable: FunctionComponent = ({ } const getSchema = () => { - const isEnabled = ({ role: { slug } }: { role: { slug: string } }) => - ruleClickEnabled({ - isAdmin, - canEditSales, - slug, - canEdit, - isSalesAdmin, - }) + const isEnabled = ({ role: { slug } }: { role: { slug: string } }) => { + if (!canManageOrganization) { + return ruleClickEnabled({ + isAdmin, + canEditSales, + slug, + canEdit, + isSalesAdmin, + }) + } + + return canManageOrganization + } const properties = { email: { @@ -535,7 +543,20 @@ const OrganizationUsersTable: FunctionComponent = ({ } const handleRowClick = ({ rowData }: CellRendererProps) => { - if ( + if (canManageOrganization) { + setEditUserDetails({ + id: rowData.id, + roleId: rowData.roleId, + userId: rowData.userId, + clId: rowData.clId, + orgId: rowData.orgId, + costId: rowData.costId, + name: rowData.name, + email: rowData.email, + canImpersonate: rowData.canImpersonate, + }) + setEditUserModalOpen(true) + } else if ( !ruleClickEnabled({ isAdmin, canEditSales, @@ -544,21 +565,9 @@ const OrganizationUsersTable: FunctionComponent = ({ isSalesAdmin, }) ) { + // eslint-disable-next-line no-useless-return return } - - setEditUserDetails({ - id: rowData.id, - roleId: rowData.roleId, - userId: rowData.userId, - clId: rowData.clId, - orgId: rowData.orgId, - costId: rowData.costId, - name: rowData.name, - email: rowData.email, - canImpersonate: rowData.canImpersonate, - }) - setEditUserModalOpen(true) } const handleSort = ({ @@ -658,6 +667,7 @@ const OrganizationUsersTable: FunctionComponent = ({ canEdit={canEdit} canEditSales={canEditSales} isSalesAdmin={isSalesAdmin} + canManageOrg={canManageOrganization} /> )} {editUserModalOpen && ( @@ -673,6 +683,7 @@ const OrganizationUsersTable: FunctionComponent = ({ canEdit={canEdit} canEditSales={canEditSales} isSalesAdmin={isSalesAdmin} + canManageOrg={canManageOrganization} /> )}