Skip to content

Commit

Permalink
Stop sys admins from de-activating themselves
Browse files Browse the repository at this point in the history
The sys admin will no longer see the feature for their own accounts, it will only available on other users, this should stop them from eccidentally deactivating their accounts.

#7691
  • Loading branch information
Siyasanga committed Nov 29, 2024
1 parent 274fcb6 commit 00d19a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 9 additions & 4 deletions packages/client/src/views/SysAdmin/Team/user/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import { SysAdminContentWrapper } from '@client/views/SysAdmin/SysAdminContentWr
import {
getAddressName,
getUserRoleIntlKey,
UserStatus
UserStatus,
canDeactivateUser
} from '@client/views/SysAdmin/Team/utils'
import { LinkButton } from '@opencrvs/components/lib/buttons'
import { Button } from '@opencrvs/components/lib/Button'
Expand Down Expand Up @@ -396,7 +397,7 @@ function UserListComponent(props: IProps) {
)

const getMenuItems = useCallback(
function getMenuItems(user: User) {
function getMenuItems(user: User, userDetails: UserDetails | null) {
const menuItems = [
{
label: intl.formatMessage(messages.editUserDetailsTitle),
Expand Down Expand Up @@ -432,7 +433,11 @@ function UserListComponent(props: IProps) {
})
}

if (user.status === 'active') {
if (
userDetails &&
user.status === 'active' &&
canDeactivateUser(user.id, userDetails)
) {
menuItems.push({
label: intl.formatMessage(messages.deactivate),
handler: () => toggleUserActivationModal(user)
Expand Down Expand Up @@ -530,7 +535,7 @@ function UserListComponent(props: IProps) {
toggleButton={
<Icon name="DotsThreeVertical" color="primary" size="large" />
}
menuItems={getMenuItems(user)}
menuItems={getMenuItems(user, userDetails)}
/>
)}
</Stack>
Expand Down
5 changes: 5 additions & 0 deletions packages/client/src/views/SysAdmin/Team/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IntlShape, MessageDescriptor } from 'react-intl'
import { messages } from '@client/i18n/messages/views/userSetup'
import { SystemRoleType } from '@client/utils/gateway'
import { ILocation, IOfflineData } from '@client/offline/reducer'
import { UserDetails } from '@client/utils/userUtils'

export enum UserStatus {
ACTIVE,
Expand Down Expand Up @@ -112,3 +113,7 @@ export function getUserSystemRole(
export const getUserRoleIntlKey = (_roleId: string) => {
return `role.${_roleId}`
}

export const canDeactivateUser = (id: string, userDetails: UserDetails) => {
return id !== userDetails.id ? true : false
}
11 changes: 9 additions & 2 deletions packages/client/src/views/UserAudit/UserAudit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import { AvatarSmall } from '@client/components/Avatar'
import styled from 'styled-components'
import { ToggleMenu } from '@opencrvs/components/lib/ToggleMenu'
import { Button } from '@opencrvs/components/lib/Button'
import { getUserRoleIntlKey } from '@client/views/SysAdmin//Team/utils'
import {
getUserRoleIntlKey,
canDeactivateUser
} from '@client/views/SysAdmin/Team/utils'
import { EMPTY_STRING, LANG_EN } from '@client/utils/constants'
import { Loader } from '@opencrvs/components/lib/Loader'
import { messages as userSetupMessages } from '@client/i18n/messages/views/userSetup'
Expand Down Expand Up @@ -246,7 +249,11 @@ export const UserAudit = () => {
)
}

if (status === 'active') {
if (
status === 'active' &&
userDetails &&
canDeactivateUser(userId, userDetails)
) {
menuItems.push({
label: intl.formatMessage(sysMessages.deactivate),
handler: () => toggleUserActivationModal()
Expand Down

0 comments on commit 00d19a6

Please sign in to comment.