Skip to content

Commit

Permalink
fix: remove references to deprecated userCredentials object
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rita committed Jun 13, 2024
1 parent a2537ba commit 6fa4f26
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 83 deletions.
4 changes: 2 additions & 2 deletions src/components/CurrentUserProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const query = {
'surname',
'firstName',
'authorities',
'userCredentials[userRoles[id]]',
'userRoles[id]',
'userGroups[id]',
'organisationUnits[id,path,displayName,children::isNotEmpty]',
'dataViewOrganisationUnits[id,path,displayName,children::isNotEmpty]',
Expand Down Expand Up @@ -107,7 +107,7 @@ const CurrentUserProvider = ({ children }) => {
firstName: data.me.firstName,
authorities: data.me.authorities,
userGroupIds: data.me.userGroups.map(({ id }) => id),
userRoleIds: data.me.userCredentials.userRoles.map(({ id }) => id),
userRoleIds: data.me.userRoles.map(({ id }) => id),
organisationUnits: data.me.organisationUnits ?? [],
dataViewOrganisationUnits: data.me.dataViewOrganisationUnits ?? [],
teiSearchOrganisationUnits: data.me.teiSearchOrganisationUnits ?? [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const AnalyticsDimensionsRestrictionsSection = React.memo(
user
? []
.concat(
user.userCredentials.cogsDimensionConstraints,
user.userCredentials.catDimensionConstraints
user.cogsDimensionConstraints,
user.catDimensionConstraints
)
.map(({ id }) => id)
: []
Expand Down
4 changes: 2 additions & 2 deletions src/components/UserForm/BasicInformationSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const BasicInformationSection = React.memo(
required={inviteUser !== INVITE_USER}
name="username"
label={i18n.t('Username')}
initialValue={user?.userCredentials.username}
initialValue={user?.username}
disabled={!!user}
autoComplete="new-password"
validate={validateUserName}
Expand Down Expand Up @@ -117,7 +117,7 @@ const BasicInformationSection = React.memo(
<CheckboxField
name="disabled"
label={i18n.t('Disable this user account')}
initialValue={user?.userCredentials.disabled}
initialValue={user?.disabled}
disabled={user && user.id === currentUserId}
/>
</FormSection>
Expand Down
4 changes: 1 addition & 3 deletions src/components/UserForm/RolesSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const RolesSection = React.memo(
leftHeader={i18n.t('Available user roles')}
rightHeader={i18n.t('User roles this user is assigned')}
options={userRoleOptions}
initialValue={
user?.userCredentials?.userRoles?.map(({ id }) => id) || []
}
initialValue={user?.userRoles?.map(({ id }) => id) || []}
validate={hasSelectionValidator}
/>
<TransferField
Expand Down
12 changes: 5 additions & 7 deletions src/components/UserForm/SecuritySection.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ const SecuritySection = React.memo(
name="accountExpiry"
label={i18n.t('Account expiration date')}
initialValue={
user?.userCredentials.accountExpiry &&
moment(user.userCredentials.accountExpiry).format(
'YYYY-MM-DD'
)
user?.accountExpiry &&
moment(user.accountExpiry).format('YYYY-MM-DD')
}
/>
<TextField
Expand All @@ -104,21 +102,21 @@ const SecuritySection = React.memo(
helpText={i18n.t(
'OpenID Connect mapping claim for your identity platform'
)}
initialValue={user?.userCredentials.openId}
initialValue={user?.openId}
autoComplete="off"
/>
<TextField
name="ldapId"
label={i18n.t('LDAP identifier')}
initialValue={user?.userCredentials.ldapId}
initialValue={user?.ldapId}
autoComplete="off"
/>
<CheckboxField
name="externalAuth"
label={i18n.t(
'External authentication only (OpenID / LDAP)'
)}
initialValue={user?.userCredentials.externalAuth}
initialValue={user?.externalAuth}
/>
</FormSection>
)
Expand Down
46 changes: 22 additions & 24 deletions src/components/UserForm/UserForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,45 +244,43 @@ UserForm.propTypes = {
user: PropTypes.shape({
attributeValues: PropTypes.arrayOf(PropTypes.object.isRequired)
.isRequired,
catDimensionConstraints: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
}).isRequired
).isRequired,
cogsDimensionConstraints: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
}).isRequired
).isRequired,
dataViewOrganisationUnits: OrganisationUnitsPropType.isRequired,
disabled: PropTypes.bool.isRequired,
externalAuth: PropTypes.bool.isRequired,
firstName: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
organisationUnits: OrganisationUnitsPropType.isRequired,
surname: PropTypes.string.isRequired,
teiSearchOrganisationUnits: OrganisationUnitsPropType.isRequired,
userCredentials: PropTypes.shape({
catDimensionConstraints: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
}).isRequired
).isRequired,
cogsDimensionConstraints: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
}).isRequired
).isRequired,
disabled: PropTypes.bool.isRequired,
externalAuth: PropTypes.bool.isRequired,
userRoles: PropTypes.arrayOf(
PropTypes.shape({
displayName: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
}).isRequired
).isRequired,
username: PropTypes.string.isRequired,
accountExpiry: PropTypes.string,
ldapId: PropTypes.string,
openId: PropTypes.string,
}).isRequired,
userGroups: PropTypes.arrayOf(
PropTypes.shape({
displayName: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
}).isRequired
).isRequired,
userRoles: PropTypes.arrayOf(
PropTypes.shape({
displayName: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
}).isRequired
).isRequired,
username: PropTypes.string.isRequired,
accountExpiry: PropTypes.string,
dataViewMaxOrganisationUnitLevel: PropTypes.number,
email: PropTypes.string,
facebookMessenger: PropTypes.string,
ldapId: PropTypes.string,
openId: PropTypes.string,
phoneNumber: PropTypes.string,
skype: PropTypes.string,
telegram: PropTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserForm/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useDebouncedUniqueUsernameValidator = ({
export const useUserNameValidator = ({ user, isInviteUser }) => {
const debouncedUniqueUsernameValidator =
useDebouncedUniqueUsernameValidator({
username: user?.userCredentials.username,
username: user?.username,
})
if (user) {
return undefined
Expand Down
14 changes: 12 additions & 2 deletions src/pages/EditUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ const userQuery = {
'dataViewOrganisationUnits[id,displayName,path]',
'teiSearchOrganisationUnits[id,displayName,path]',
'dataViewMaxOrganisationUnitLevel',
'userCredentials[id,username,accountExpiry,lastLogin,externalAuth,userRoles[id,displayName],cogsDimensionConstraints[id,displayName,dimensionType],catDimensionConstraints[id,displayName,dimensionType],openId,ldapId,disabled]',
'id',
'username',
'accountExpiry',
'lastLogin',
'externalAuth',
'userRoles[id,displayName]',
'cogsDimensionConstraints[id,displayName,dimensionType]',
'catDimensionConstraints[id,displayName,dimensionType]',
'openId',
'ldapId',
'disabled',
'whatsApp',
'facebookMessenger',
'skype',
Expand All @@ -44,7 +54,7 @@ const userSettingsQuery = {

const useUser = (userId) => {
const user = useDataQuery(userQuery, { lazy: true })
const username = user.data?.user?.userCredentials?.username
const username = user.data?.user?.username
const userSettings = useDataQuery(userSettingsQuery, { lazy: true })

useEffect(() => {
Expand Down
10 changes: 2 additions & 8 deletions src/pages/UserList/ContextMenu/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ const ContextMenu = ({ user, anchorRef, refetchUsers, onClose }) => {
systemInfo: { emailConfigured },
} = useConfig()
const [CurrentModal, setCurrentModal] = useCurrentModal()
const {
access,
twoFactorEnabled,
userCredentials: { disabled },
} = user
const { access, twoFactorEnabled, disabled } = user
const canReplicate =
access.update &&
currentUser.authorities.some(
Expand Down Expand Up @@ -177,11 +173,9 @@ ContextMenu.propTypes = {
read: PropTypes.bool.isRequired,
update: PropTypes.bool.isRequired,
}).isRequired,
disabled: PropTypes.bool.isRequired,
id: PropTypes.string.isRequired,
twoFactorEnabled: PropTypes.bool.isRequired,
userCredentials: PropTypes.shape({
disabled: PropTypes.bool.isRequired,
}).isRequired,
email: PropTypes.string,
}).isRequired,
onClose: PropTypes.func.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/UserList/ContextMenu/Modals/DisableModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const DisableModal = ({ user, refetchUsers, onClose }) => {
data: [
{
op: 'replace',
path: '/userCredentials/disabled',
path: '/disabled',
value: true,
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/pages/UserList/ContextMenu/Modals/EnableModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const EnableModal = ({ user, refetchUsers, onClose }) => {
data: [
{
op: 'replace',
path: '/userCredentials/disabled',
path: '/disabled',
value: false,
},
],
Expand Down
4 changes: 3 additions & 1 deletion src/pages/UserList/UserList.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const usersQuery = {
'access',
'email',
'twoFactorEnabled',
'userCredentials[username,disabled,lastLogin]',
'username',
'disabled',
'lastLogin',
'teiSearchOrganisationUnits[id,path]',
],
order: [
Expand Down
18 changes: 11 additions & 7 deletions src/pages/UserList/UserTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ const UserTable = ({
</DataTableHead>
<DataTableBody loading={loading}>
{users.map((user) => {
const { id, displayName, access, userCredentials } = user
const { username, lastLogin, disabled } = userCredentials
const {
id,
displayName,
access,
username,
lastLogin,
disabled,
} = user
const lastLoginClient = fromServerDate(lastLogin)

const handleClick = () => {
Expand Down Expand Up @@ -158,13 +164,11 @@ UserTable.propTypes = {
read: PropTypes.bool.isRequired,
update: PropTypes.bool.isRequired,
}).isRequired,
disabled: PropTypes.bool.isRequired,
displayName: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
userCredentials: PropTypes.shape({
disabled: PropTypes.bool.isRequired,
lastLogin: PropTypes.string,
username: PropTypes.string,
}).isRequired,
lastLogin: PropTypes.string,
username: PropTypes.string,
}).isRequired
),
}
Expand Down
35 changes: 13 additions & 22 deletions src/pages/UserList/UserTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ describe('<UserTable>', () => {
read: true,
update: true,
},
userCredentials: {
username: 'user1',
lastLogin: '2021-10-15T12:34:56Z',
disabled: false,
},
username: 'user1',
lastLogin: '2021-10-15T12:34:56Z',
disabled: false,
},
{
id: 'user-2',
Expand All @@ -97,11 +95,9 @@ describe('<UserTable>', () => {
read: true,
update: true,
},
userCredentials: {
username: 'user2',
lastLogin: '2021-09-14T12:34:56Z',
disabled: true,
},
username: 'user2',
lastLogin: '2021-09-14T12:34:56Z',
disabled: true,
},
]

Expand Down Expand Up @@ -137,8 +133,7 @@ describe('<UserTable>', () => {
).getAllByRole('row')
expect(rows).toHaveLength(users.length)
users.forEach((user, index) => {
const { displayName, userCredentials } = user
const { username, lastLogin, disabled } = userCredentials
const { displayName, username, lastLogin, disabled } = user

const row = rows[index]
expect(within(row).getAllByRole('cell')).toHaveLength(5)
Expand Down Expand Up @@ -180,11 +175,9 @@ describe('<UserTable>', () => {
read: true,
update: true,
},
userCredentials: {
username: 'user1',
lastLogin: '2021-10-15T12:34:56Z',
disabled: false,
},
username: 'user1',
lastLogin: '2021-10-15T12:34:56Z',
disabled: false,
},
{
id: 'user-2',
Expand All @@ -193,11 +186,9 @@ describe('<UserTable>', () => {
read: true,
update: true,
},
userCredentials: {
username: 'user2',
lastLogin: '2021-09-14T12:34:56Z',
disabled: true,
},
username: 'user2',
lastLogin: '2021-09-14T12:34:56Z',
disabled: true,
},
]

Expand Down

0 comments on commit 6fa4f26

Please sign in to comment.