Skip to content

Commit d47280f

Browse files
committed
Fix IMS user change password action
1 parent a569a38 commit d47280f

7 files changed

Lines changed: 27 additions & 5 deletions

File tree

apps/sensenet/src/components/context-menu/use-context-menu-actions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ export function useContextMenuActions(content: GenericContent, setActions: (cont
184184
},
185185
})
186186
break
187+
case 'ChangePassword':
188+
openDialog({
189+
name: 'change-password',
190+
props: {
191+
content,
192+
},
193+
})
194+
break
187195
case 'SetPermissions':
188196
if (snRoute.path && PathHelper.isInSubTree(content.Path, snRoute.path)) {
189197
navigateToAction({

apps/sensenet/src/components/dialogs/change-password.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Button, DialogActions, DialogContent } from '@material-ui/core'
22
import TextField from '@material-ui/core/TextField'
3+
import { GenericContent } from '@sensenet/default-content-types'
34
import { useLogger, useRepository } from '@sensenet/hooks-react'
45
import React, { useState } from 'react'
56
import { useAuth } from '../../context/auth-provider'
@@ -9,13 +10,18 @@ import { DialogTitle, useDialog } from '.'
910

1011
type PasswordFieldKeys = 'newPassword' | 'confirmPassword'
1112

12-
export function ChangePasswordDialog() {
13+
export type ChangePasswordDialogProps = {
14+
content?: GenericContent
15+
}
16+
17+
export function ChangePasswordDialog({ content }: ChangePasswordDialogProps) {
1318
const { closeLastDialog } = useDialog()
1419
const localization = useLocalization().changePassword
1520
const logger = useLogger('change-password')
1621
const globalClasses = useGlobalStyles()
1722
const repo = useRepository()
1823
const { user } = useAuth()
24+
const targetContent = content || user
1925
const [passwordFields, setPasswordFields] = useState<{
2026
[K in PasswordFieldKeys]?: string
2127
}>({
@@ -32,7 +38,7 @@ export function ChangePasswordDialog() {
3238

3339
try {
3440
await repo.executeAction({
35-
idOrPath: user!.Path,
41+
idOrPath: targetContent!.Path,
3642
name: 'ChangePassword',
3743
method: 'POST',
3844
body: {
@@ -65,7 +71,11 @@ export function ChangePasswordDialog() {
6571
return (
6672
<>
6773
<DialogTitle>
68-
<div className={globalClasses.centered}>{localization.changeYourPassword}</div>
74+
<div className={globalClasses.centered}>
75+
{content
76+
? localization.changePasswordFor.replace('{0}', content.DisplayName || content.Name)
77+
: localization.changeYourPassword}
78+
</div>
6979
</DialogTitle>
7080
<>
7181
<DialogContent data-test="change-password-fields">

apps/sensenet/src/components/dialogs/dialog-provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AddDeleteUserGroupsProps,
77
ApproveProps,
88
AreYouSureProps,
9+
ChangePasswordDialogProps,
910
CheckInProps,
1011
ContentPickerDialogProps,
1112
CopyMoveDialogProps,
@@ -43,7 +44,7 @@ export type DialogWithProps = (
4344
| { name: 'member-select'; props: MemberSelectProps }
4445
| { name: 'content-picker'; props: ContentPickerDialogProps }
4546
| { name: 'feedback' }
46-
| { name: 'change-password' }
47+
| { name: 'change-password'; props?: ChangePasswordDialogProps }
4748
| { name: 'date-range-picker'; props: DateRangePickerProps }
4849
| { name: 'column-settings'; props: any }
4950
) & { dialogProps?: Partial<DialogProps> }

apps/sensenet/src/components/dialogs/dialogs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function dialogRenderer(dialog: DialogWithProps) {
6666
case 'feedback':
6767
return <Feedback />
6868
case 'change-password':
69-
return <ChangePasswordDialog />
69+
return <ChangePasswordDialog {...dialog.props} />
7070
case 'date-range-picker':
7171
return <DateRangePicker {...dialog.props} />
7272
case 'column-settings':

apps/sensenet/src/components/dialogs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './upload'
22
export * from './approve'
33
export * from './are-you-sure'
44
export * from './check-in'
5+
export * from './change-password'
56
export * from './content-picker'
67
export * from './copy-move'
78
export * from './custom-action-result'

apps/sensenet/src/localization/default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ const values = {
677677
},
678678
changePassword: {
679679
changeYourPassword: 'Change your password',
680+
changePasswordFor: 'Change password for {0}',
680681
cancel: 'Cancel',
681682
update: 'Update',
682683
oldPassword: 'Old password',

apps/sensenet/src/localization/hungarian.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ const values: Localization = {
305305
},
306306
changePassword: {
307307
changeYourPassword: 'Jelszómódosítás',
308+
changePasswordFor: '{0} jelszavának módosítása',
308309
cancel: 'Cancel',
309310
update: 'Küldés',
310311
oldPassword: 'Régi jelszó',

0 commit comments

Comments
 (0)