Skip to content

Commit

Permalink
Merge pull request #121 from ilyarudyi/fix/can-manage-organization
Browse files Browse the repository at this point in the history
add condition for "manage-organization" permission
  • Loading branch information
wender authored Aug 11, 2023
2 parents 00cbe79 + 4bf983c commit eb45a61
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions react/components/EditUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface Props {
canEdit?: boolean
canEditSales?: boolean
isSalesAdmin: boolean
canManageOrg?: boolean
}

interface DropdownOption {
Expand All @@ -42,6 +43,7 @@ const EditUserModal: FunctionComponent<Props> = ({
canEdit,
canEditSales,
isSalesAdmin,
canManageOrg
}) => {
const { formatMessage } = useIntl()
const [userState, setUserState] = useState({} as UserDetails)
Expand Down Expand Up @@ -114,6 +116,10 @@ const EditUserModal: FunctionComponent<Props> = ({
const filteredArray = rolesData.listRoles.filter((role: any) => {
if (isAdmin) return true

if(canManageOrg) {
return true
}

if (role.slug.includes('customer') && canEdit) {
return true
}
Expand Down
4 changes: 4 additions & 0 deletions react/components/NewUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface Props {
canEdit?: boolean
canEditSales?: boolean
isSalesAdmin?: boolean
canManageOrg: boolean
}

interface DropdownOption {
Expand All @@ -39,6 +40,7 @@ const NewUserModal: FunctionComponent<Props> = ({
canEdit,
canEditSales,
isSalesAdmin,
canManageOrg
}) => {
const { formatMessage } = useIntl()
const [userState, setUserState] = useState({
Expand Down Expand Up @@ -117,6 +119,8 @@ const NewUserModal: FunctionComponent<Props> = ({
const filteredArray = rolesData.listRoles.filter((role: any) => {
if (isAdmin) return true

if(canManageOrg) return true

if (role.slug.includes('customer') && canEdit) {
return true
}
Expand Down
55 changes: 33 additions & 22 deletions react/components/OrganizationUsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ const OrganizationUsersTable: FunctionComponent<Props> = ({
}
}

const canManageOrganization = permissions.includes('manage-organization')

const canEdit = isAdmin || permissions.includes('add-users-organization')

const canEditSales =
isAdmin ||
permissions.includes('add-sales-users-all') ||
Expand Down Expand Up @@ -387,14 +390,19 @@ const OrganizationUsersTable: FunctionComponent<Props> = ({
}

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: {
Expand Down Expand Up @@ -535,7 +543,20 @@ const OrganizationUsersTable: FunctionComponent<Props> = ({
}

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,
Expand All @@ -544,21 +565,9 @@ const OrganizationUsersTable: FunctionComponent<Props> = ({
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 = ({
Expand Down Expand Up @@ -658,6 +667,7 @@ const OrganizationUsersTable: FunctionComponent<Props> = ({
canEdit={canEdit}
canEditSales={canEditSales}
isSalesAdmin={isSalesAdmin}
canManageOrg={canManageOrganization}
/>
)}
{editUserModalOpen && (
Expand All @@ -673,6 +683,7 @@ const OrganizationUsersTable: FunctionComponent<Props> = ({
canEdit={canEdit}
canEditSales={canEditSales}
isSalesAdmin={isSalesAdmin}
canManageOrg={canManageOrganization}
/>
)}
<RemoveUserModal
Expand Down

0 comments on commit eb45a61

Please sign in to comment.