-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: help users with user role assignment [DHIS2-18422] [DHIS2-18446] (
- Loading branch information
Showing
57 changed files
with
5,820 additions
and
4,540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
298 changes: 172 additions & 126 deletions
298
...ss/fixtures/network/42/show_tiles_with_list_and_add_action_to_all_available_sections.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 88 additions & 30 deletions
118
cypress/fixtures/network/42/the_app_has_a_main_navigation.json
Large diffs are not rendered by default.
Oops, something went wrong.
153 changes: 104 additions & 49 deletions
153
cypress/fixtures/network/42/the_user_group_list_can_be_searched.json
Large diffs are not rendered by default.
Oops, something went wrong.
426 changes: 0 additions & 426 deletions
426
cypress/fixtures/network/42/the_user_list_can_be_searched.json
This file was deleted.
Oops, something went wrong.
114 changes: 70 additions & 44 deletions
114
cypress/fixtures/network/42/the_user_role_list_can_be_searched.json
Large diffs are not rendered by default.
Oops, something went wrong.
114 changes: 86 additions & 28 deletions
114
cypress/fixtures/network/42/user_groups_can_be_listed.json
Large diffs are not rendered by default.
Oops, something went wrong.
116 changes: 87 additions & 29 deletions
116
cypress/fixtures/network/42/user_roles_can_be_listed.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
setupFilesAfterEnv: ['<rootDir>/src/test-utils/setup-tests.js'], | ||
transformIgnorePatterns: ['/node_modules/(?!(lodash-es)/)'], | ||
transformIgnorePatterns: ['/node_modules/(?!(lodash-es|p-debounce)/)'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/components/RoleForm/AssignmentRestrictionsWarning.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import { IconChevronDown24, IconChevronUp24, NoticeBox } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React, { useState } from 'react' | ||
import { useSystemInformation } from '../../providers/index.js' | ||
import styles from './AssignmentRestrictionsWarning.module.css' | ||
|
||
export const AssignmentRestrictionWarning = ({ | ||
currentUser, | ||
roleId, | ||
roleAuthorities, | ||
initiallyExpanded, | ||
}) => { | ||
const [detailsExpanded, setDetailsExpanded] = useState( | ||
initiallyExpanded ?? false | ||
) | ||
|
||
// check if user is able to assign this role if they are a member | ||
const { | ||
userRoleIds, | ||
authorities: userAuthorities, | ||
hasAllAuthority, | ||
} = currentUser | ||
const { usersCanAssignOwnUserRoles, authorityIdToNameMap } = | ||
useSystemInformation() | ||
const cannotAssignThisRole = | ||
!hasAllAuthority && | ||
!usersCanAssignOwnUserRoles && | ||
userRoleIds.includes(roleId) | ||
|
||
// check if role has authorities that user does not have | ||
const missingAutoritiesForUser = hasAllAuthority | ||
? [] | ||
: roleAuthorities.filter( | ||
(roleAuth) => !userAuthorities.includes(roleAuth) | ||
) | ||
|
||
if (!cannotAssignThisRole && missingAutoritiesForUser.length === 0) { | ||
return null | ||
} | ||
|
||
return ( | ||
<NoticeBox className={styles.noticeBox}> | ||
{cannotAssignThisRole && ( | ||
<div> | ||
{i18n.t( | ||
'You cannot assign this role because you are assigned to this role, and your system does not allow you to assign roles of which you are a member.' | ||
)} | ||
</div> | ||
)} | ||
{missingAutoritiesForUser?.length > 0 && ( | ||
<div> | ||
<div className={styles.missingRolesMessage}> | ||
<span> | ||
{i18n.t( | ||
'You cannot assign this role because it has authorities that you do not have.' | ||
)} | ||
</span> | ||
<div | ||
onClick={() => { | ||
setDetailsExpanded((prev) => !prev) | ||
}} | ||
data-test="roles-details-expand" | ||
> | ||
{detailsExpanded ? ( | ||
<IconChevronUp24 /> | ||
) : ( | ||
<IconChevronDown24 /> | ||
)} | ||
</div> | ||
</div> | ||
|
||
{detailsExpanded && ( | ||
<ul data-test="authorities-user-does-not-have-list"> | ||
{missingAutoritiesForUser | ||
.sort((a, b) => | ||
( | ||
authorityIdToNameMap.get(a) ?? a | ||
).localeCompare( | ||
authorityIdToNameMap.get(b) ?? b | ||
) | ||
) | ||
.map((auth) => ( | ||
<li key={auth}> | ||
{authorityIdToNameMap.get(auth) ?? auth} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
)} | ||
</NoticeBox> | ||
) | ||
} | ||
|
||
AssignmentRestrictionWarning.propTypes = { | ||
roleId: PropTypes.string.isRequired, | ||
currentUser: PropTypes.object, | ||
initiallyExpanded: PropTypes.bool, | ||
roleAuthorities: PropTypes.arrayOf(PropTypes.string), | ||
} |
13 changes: 13 additions & 0 deletions
13
src/components/RoleForm/AssignmentRestrictionsWarning.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.noticeBox { | ||
max-width: 700px; | ||
margin-bottom: var(--spacers-dp16); | ||
} | ||
|
||
.noticeBox > div { | ||
margin-block-end: var(--spacers-dp8); | ||
} | ||
|
||
.missingRolesMessage { | ||
display: flex; | ||
align-items: center; | ||
} |
Oops, something went wrong.
7a788ed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://dhis2-user.netlify.app as production
🚀 Deployed on https://677cfb00fe4449081e1b531b--dhis2-user.netlify.app