From 9dd0cb9f5ac4da7545d2d92e65c5f294b0f94826 Mon Sep 17 00:00:00 2001 From: Daniel Eriksson Date: Tue, 14 Jan 2025 11:01:37 +0100 Subject: [PATCH 1/3] Finished behandling: All saksbehandlere can edit documents, unfinished behandling: Only assigned saksbehandler can edit --- .../src/components/smart-editor/context.tsx | 4 +- .../smart-editor/history/history-editor.tsx | 2 +- .../hooks/use-can-edit-document.test.ts | 439 +++++++++--------- .../hooks/use-can-edit-document.ts | 134 +++--- .../new-document/new-document.tsx | 5 +- .../smart-editor/tabbed-editors/editor.tsx | 4 +- .../smart-editor/tabbed-editors/tab-panel.tsx | 2 +- .../plate/components/signature/signature.tsx | 2 +- frontend/src/plate/templates/helpers.ts | 4 +- .../src/plate/templates/simple-templates.ts | 8 +- 10 files changed, 284 insertions(+), 320 deletions(-) diff --git a/frontend/src/components/smart-editor/context.tsx b/frontend/src/components/smart-editor/context.tsx index 8c6631442..089b969c6 100644 --- a/frontend/src/components/smart-editor/context.tsx +++ b/frontend/src/components/smart-editor/context.tsx @@ -65,8 +65,8 @@ export const SmartEditorContextComponent = ({ children, smartDocument }: Props) useSmartEditorAnnotationsAtOrigin(); // const [sheetRef, setSheetRef] = useState(null); const sheetRef = useRef(null); - const canManage = useCanManageDocument(templateId, creator.employee.navIdent); - const canEdit = useCanEditDocument(templateId, creator.employee.navIdent); + const canManage = useCanManageDocument(templateId); + const canEdit = useCanEditDocument(templateId); return ( { const mainEditor = useMyPlateEditorRef(smartDocument.id); const { templateId } = useContext(SmartEditorContext); - const canManage = useCanManageDocument(templateId, smartDocument.creator.employee.navIdent); + const canManage = useCanManageDocument(templateId); const id = `${smartDocument.id}-${versionId}`; diff --git a/frontend/src/components/smart-editor/hooks/use-can-edit-document.test.ts b/frontend/src/components/smart-editor/hooks/use-can-edit-document.test.ts index 96e90d976..f1c97bcf5 100644 --- a/frontend/src/components/smart-editor/hooks/use-can-edit-document.test.ts +++ b/frontend/src/components/smart-editor/hooks/use-can-edit-document.test.ts @@ -12,186 +12,116 @@ const createOppgave = ( avsluttetAvSaksbehandlerDate: string | null, ): IOppgavebehandling => ({ - saksbehandler: { navIdent: 'creator' }, + saksbehandler: { navIdent: 'assigned saksbehandler' }, typeId: SaksTypeEnum.KLAGE, rol: { flowState: rolFlowState, employee: { navIdent: 'rol' } }, medunderskriver: { flowState: muFlowState, employee: { navIdent: 'mu' } }, avsluttetAvSaksbehandlerDate, }) as IOppgavebehandling; -type Cases = [FlowState, FlowState, string, string | null, boolean][]; +type Cases = [FlowState, FlowState, string | null, boolean][]; const CANT_EDIT: Cases = [ - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'creator', null, false], - [FlowState.NOT_SENT, FlowState.SENT, 'creator', null, false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'creator', null, false], - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'not creator', null, false], - [FlowState.NOT_SENT, FlowState.SENT, 'not creator', null, false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'not creator', null, false], - [FlowState.SENT, FlowState.NOT_SENT, 'creator', null, false], - [FlowState.SENT, FlowState.SENT, 'creator', null, false], - [FlowState.SENT, FlowState.RETURNED, 'creator', null, false], - [FlowState.SENT, FlowState.NOT_SENT, 'not creator', null, false], - [FlowState.SENT, FlowState.SENT, 'not creator', null, false], - [FlowState.SENT, FlowState.RETURNED, 'not creator', null, false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'creator', null, false], - [FlowState.RETURNED, FlowState.SENT, 'creator', null, false], - [FlowState.RETURNED, FlowState.RETURNED, 'creator', null, false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'not creator', null, false], - [FlowState.RETURNED, FlowState.SENT, 'not creator', null, false], - [FlowState.RETURNED, FlowState.RETURNED, 'not creator', null, false], - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.SENT, 'creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'not creator', '03.14.1969', false], - [FlowState.SENT, FlowState.NOT_SENT, 'creator', '03.14.1969', false], - [FlowState.SENT, FlowState.SENT, 'creator', '03.14.1969', false], - [FlowState.SENT, FlowState.RETURNED, 'creator', '03.14.1969', false], - [FlowState.SENT, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.SENT, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.SENT, FlowState.RETURNED, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.SENT, 'creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.RETURNED, 'creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.RETURNED, 'not creator', '03.14.1969', false], + [FlowState.NOT_SENT, FlowState.NOT_SENT, '03.14.1969', false], + [FlowState.NOT_SENT, FlowState.NOT_SENT, null, false], + [FlowState.NOT_SENT, FlowState.RETURNED, '03.14.1969', false], + [FlowState.NOT_SENT, FlowState.RETURNED, null, false], + [FlowState.NOT_SENT, FlowState.SENT, '03.14.1969', false], + [FlowState.NOT_SENT, FlowState.SENT, null, false], + [FlowState.RETURNED, FlowState.NOT_SENT, '03.14.1969', false], + [FlowState.RETURNED, FlowState.NOT_SENT, null, false], + [FlowState.RETURNED, FlowState.RETURNED, '03.14.1969', false], + [FlowState.RETURNED, FlowState.RETURNED, null, false], + [FlowState.RETURNED, FlowState.SENT, '03.14.1969', false], + [FlowState.RETURNED, FlowState.SENT, null, false], + [FlowState.SENT, FlowState.NOT_SENT, '03.14.1969', false], + [FlowState.SENT, FlowState.NOT_SENT, null, false], + [FlowState.SENT, FlowState.RETURNED, '03.14.1969', false], + [FlowState.SENT, FlowState.RETURNED, null, false], + [FlowState.SENT, FlowState.SENT, '03.14.1969', false], + [FlowState.SENT, FlowState.SENT, null, false], ]; describe('canEditDocument', () => { - describe('Saksbehandler', () => { - const user = { navIdent: 'creator', roller: [Role.KABAL_SAKSBEHANDLING] } as IUserData; + describe('Assigned saksbehandler', () => { + const user = { navIdent: 'assigned saksbehandler', roller: [Role.KABAL_SAKSBEHANDLING] } as IUserData; describe('ROL answers', () => { - it.each(CANT_EDIT)('%#. should never allow editing', (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.ROL_ANSWERS, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); + it.each(CANT_EDIT)('%#. should never allow editing', (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.ROL_ANSWERS, createOppgave(mu, rol, finished), user)).toBe(expected); }); }); describe('ROL questions', () => { const cases: Cases = [ - // Assigned saksbehandler can edit in not-finished behandling when ROL flow state is NOT_SENT/RETURNED - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'creator', null, true], - [FlowState.SENT, FlowState.NOT_SENT, 'creator', null, true], - [FlowState.RETURNED, FlowState.NOT_SENT, 'creator', null, true], - [FlowState.NOT_SENT, FlowState.RETURNED, 'creator', null, true], - [FlowState.SENT, FlowState.RETURNED, 'creator', null, true], - [FlowState.RETURNED, FlowState.RETURNED, 'creator', null, true], - - // User is assigned saksbehandler in open behandling, so it doesn't matter if there was another creator - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'not creator', null, true], - [FlowState.NOT_SENT, FlowState.RETURNED, 'not creator', null, true], - [FlowState.SENT, FlowState.NOT_SENT, 'not creator', null, true], - [FlowState.SENT, FlowState.RETURNED, 'not creator', null, true], - [FlowState.RETURNED, FlowState.NOT_SENT, 'not creator', null, true], - [FlowState.RETURNED, FlowState.RETURNED, 'not creator', null, true], - - // Creator can edit in finished behandling when ROL flow state is NOT_SENT/RETURNED - // Flow state in finished behandling doesn't really make sense. These cases are just for completeness' sake - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'creator', '03.14.1969', true], - [FlowState.SENT, FlowState.NOT_SENT, 'creator', '03.14.1969', true], - [FlowState.RETURNED, FlowState.NOT_SENT, 'creator', '03.14.1969', true], - [FlowState.NOT_SENT, FlowState.RETURNED, 'creator', '03.14.1969', true], - [FlowState.SENT, FlowState.RETURNED, 'creator', '03.14.1969', true], - [FlowState.RETURNED, FlowState.RETURNED, 'creator', '03.14.1969', true], - - // Only creator can edit in finished behandling - // Flow state in finished behandling doesn't really make sense. These cases are just for completeness' sake - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.SENT, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'not creator', '03.14.1969', false], - [FlowState.SENT, FlowState.RETURNED, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.RETURNED, 'not creator', '03.14.1969', false], - - // Flow state is sent - only ROL can edit - [FlowState.NOT_SENT, FlowState.SENT, 'creator', null, false], - [FlowState.SENT, FlowState.SENT, 'creator', null, false], - [FlowState.SENT, FlowState.SENT, 'not creator', null, false], - [FlowState.NOT_SENT, FlowState.SENT, 'not creator', null, false], - [FlowState.RETURNED, FlowState.SENT, 'creator', null, false], - [FlowState.NOT_SENT, FlowState.SENT, 'creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.SENT, 'not creator', null, false], - [FlowState.NOT_SENT, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.SENT, FlowState.SENT, 'creator', '03.14.1969', false], - [FlowState.SENT, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.SENT, 'creator', '03.14.1969', false], + // Only assigned saksbehandler can edit in not-finished behandling when flow states are NOT_SENT/RETURNED + [FlowState.NOT_SENT, FlowState.RETURNED, null, true], + [FlowState.RETURNED, FlowState.RETURNED, null, true], + [FlowState.NOT_SENT, FlowState.NOT_SENT, null, true], + [FlowState.RETURNED, FlowState.NOT_SENT, null, true], + + // All saksbehandlere can edit in finished behandling + [FlowState.NOT_SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.RETURNED, '03.14.1969', true], + [FlowState.RETURNED, FlowState.SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.SENT, FlowState.SENT, '03.14.1969', true], + + // MU flow state is sent - can't edit + [FlowState.SENT, FlowState.RETURNED, null, false], + [FlowState.SENT, FlowState.NOT_SENT, null, false], + + // ROL state is sent - only ROL can edit + [FlowState.NOT_SENT, FlowState.SENT, null, false], + [FlowState.SENT, FlowState.SENT, null, false], + [FlowState.RETURNED, FlowState.SENT, null, false], ]; - it.each(cases)( - '%#. should not allow editing if ROL flow state is sent or if user is not the creator of the document', - (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.ROL_QUESTIONS, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); - }, - ); + it.each(cases)('%#. should not allow editing if flow state is sent', (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.ROL_QUESTIONS, createOppgave(mu, rol, finished), user)).toBe(expected); + }); }); describe('Other templates', () => { const cases: Cases = [ // Assigned saksbehandler can edit in not-finished behandling when MU flow state is NOT_SENT/RETURNED - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'creator', null, true], - [FlowState.NOT_SENT, FlowState.SENT, 'creator', null, true], - [FlowState.NOT_SENT, FlowState.RETURNED, 'creator', null, true], - [FlowState.RETURNED, FlowState.NOT_SENT, 'creator', null, true], - [FlowState.RETURNED, FlowState.SENT, 'creator', null, true], - [FlowState.RETURNED, FlowState.RETURNED, 'creator', null, true], - - // Creator can edit in finished behandling when MU flow state is NOT_SENT/RETURNED - // Flow state in finished behandling doesn't really make sense. These cases are just for completeness' sake - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'creator', '03.14.1969', true], - [FlowState.NOT_SENT, FlowState.SENT, 'creator', '03.14.1969', true], - [FlowState.NOT_SENT, FlowState.RETURNED, 'creator', '03.14.1969', true], - [FlowState.RETURNED, FlowState.NOT_SENT, 'creator', '03.14.1969', true], - [FlowState.RETURNED, FlowState.SENT, 'creator', '03.14.1969', true], - [FlowState.RETURNED, FlowState.RETURNED, 'creator', '03.14.1969', true], - - // User is assigned saksbehandler in open behandling, so it doesn't matter if there was another creator - [FlowState.RETURNED, FlowState.NOT_SENT, 'not creator', null, true], - [FlowState.RETURNED, FlowState.SENT, 'not creator', null, true], - [FlowState.RETURNED, FlowState.RETURNED, 'not creator', null, true], - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'not creator', null, true], - [FlowState.NOT_SENT, FlowState.SENT, 'not creator', null, true], - [FlowState.NOT_SENT, FlowState.RETURNED, 'not creator', null, true], - - // Only creator can edit in finished behandling - // Flow state in finished behandling doesn't really make sense. These cases are just for completeness' sake - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.RETURNED, 'not creator', '03.14.1969', false], + [FlowState.NOT_SENT, FlowState.NOT_SENT, null, true], + [FlowState.NOT_SENT, FlowState.RETURNED, null, true], + [FlowState.NOT_SENT, FlowState.SENT, null, true], + [FlowState.RETURNED, FlowState.NOT_SENT, null, true], + [FlowState.RETURNED, FlowState.RETURNED, null, true], + [FlowState.RETURNED, FlowState.SENT, null, true], + + // All saksbehandlere can edit in finished behandling when MU flow state is NOT_SENT/RETURNED + [FlowState.NOT_SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.SENT, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.RETURNED, '03.14.1969', true], + [FlowState.RETURNED, FlowState.RETURNED, '03.14.1969', true], + [FlowState.RETURNED, FlowState.SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.SENT, FlowState.SENT, '03.14.1969', true], // Flow state is sent - only MU can edit - [FlowState.SENT, FlowState.NOT_SENT, 'creator', null, false], - [FlowState.SENT, FlowState.SENT, 'creator', null, false], - [FlowState.SENT, FlowState.RETURNED, 'creator', null, false], - [FlowState.SENT, FlowState.NOT_SENT, 'not creator', null, false], - [FlowState.SENT, FlowState.SENT, 'not creator', null, false], - [FlowState.SENT, FlowState.RETURNED, 'not creator', null, false], - [FlowState.SENT, FlowState.NOT_SENT, 'creator', '03.14.1969', false], - [FlowState.SENT, FlowState.SENT, 'creator', '03.14.1969', false], - [FlowState.SENT, FlowState.RETURNED, 'creator', '03.14.1969', false], - [FlowState.SENT, FlowState.NOT_SENT, 'not creator', '03.14.1969', false], - [FlowState.SENT, FlowState.SENT, 'not creator', '03.14.1969', false], - [FlowState.SENT, FlowState.RETURNED, 'not creator', '03.14.1969', false], + [FlowState.SENT, FlowState.NOT_SENT, null, false], + [FlowState.SENT, FlowState.RETURNED, null, false], + [FlowState.SENT, FlowState.SENT, null, false], ]; - it.each(cases)( - '%#. should not allow editing if MU flow state is sent, or if user is not the creator of the document', - (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.KLAGEVEDTAK_V2, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); - }, - ); + it.each(cases)('%#. should not allow editing if MU flow state is sent', (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.KLAGEVEDTAK_V2, createOppgave(mu, rol, finished), user)).toBe(expected); + }); }); }); @@ -199,92 +129,127 @@ describe('canEditDocument', () => { const user = { navIdent: 'mu', roller: [Role.KABAL_SAKSBEHANDLING] } as IUserData; describe('ROL answers', () => { - it.each(CANT_EDIT)('%#. should never allow editing', (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.ROL_ANSWERS, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); + it.each(CANT_EDIT)('%#. should never allow editing', (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.ROL_ANSWERS, createOppgave(mu, rol, finished), user)).toBe(expected); }); }); + describe('ROL questions', () => { + const cases: Cases = [ + // User is MU and MU flow state is sent - can edit + [FlowState.SENT, FlowState.NOT_SENT, null, true], + [FlowState.SENT, FlowState.RETURNED, null, true], + + // Behandling is finished, and MU has saksbehandler role - can edit + [FlowState.NOT_SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.RETURNED, '03.14.1969', true], + [FlowState.RETURNED, FlowState.SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.SENT, FlowState.SENT, '03.14.1969', true], + + // ROL flow state is sent - can't edit + [FlowState.SENT, FlowState.SENT, null, false], + + // MU Flow state is not sent - MU can't edit + [FlowState.NOT_SENT, FlowState.NOT_SENT, null, false], + [FlowState.NOT_SENT, FlowState.SENT, null, false], + [FlowState.NOT_SENT, FlowState.RETURNED, null, false], + [FlowState.RETURNED, FlowState.NOT_SENT, null, false], + [FlowState.RETURNED, FlowState.SENT, null, false], + [FlowState.RETURNED, FlowState.RETURNED, null, false], + ]; + + it.each(cases)( + '%#. should allow editing if MU flow state is sent and ROL flow state is not sent', + (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.ROL_QUESTIONS, createOppgave(mu, rol, finished), user)).toBe(expected); + }, + ); + }); + describe('Other templates', () => { const cases: Cases = [ // User is MU and MU flow state is sent - can edit - [FlowState.SENT, FlowState.NOT_SENT, 'creator', null, true], - [FlowState.SENT, FlowState.SENT, 'creator', null, true], - [FlowState.SENT, FlowState.RETURNED, 'creator', null, true], - [FlowState.SENT, FlowState.NOT_SENT, 'creator', '03.14.1969', true], - [FlowState.SENT, FlowState.SENT, 'creator', '03.14.1969', true], - [FlowState.SENT, FlowState.RETURNED, 'creator', '03.14.1969', true], - - // Behandling is finished, and MU is not creator - can't edit - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.SENT, 'creator', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.SENT, 'creator', '03.14.1969', false], - [FlowState.RETURNED, FlowState.RETURNED, 'creator', '03.14.1969', false], + [FlowState.SENT, FlowState.NOT_SENT, null, true], + [FlowState.SENT, FlowState.RETURNED, null, true], + [FlowState.SENT, FlowState.SENT, null, true], + + // Behandling is finished, and MU has saksbehandler role - can edit + [FlowState.NOT_SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.RETURNED, '03.14.1969', true], + [FlowState.RETURNED, FlowState.SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.SENT, FlowState.SENT, '03.14.1969', true], // MU Flow state is not sent - MU can't edit - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'creator', null, false], - [FlowState.NOT_SENT, FlowState.SENT, 'creator', null, false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'creator', null, false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'creator', null, false], - [FlowState.RETURNED, FlowState.SENT, 'creator', null, false], - [FlowState.RETURNED, FlowState.RETURNED, 'creator', null, false], + [FlowState.NOT_SENT, FlowState.NOT_SENT, null, false], + [FlowState.NOT_SENT, FlowState.SENT, null, false], + [FlowState.NOT_SENT, FlowState.RETURNED, null, false], + [FlowState.RETURNED, FlowState.NOT_SENT, null, false], + [FlowState.RETURNED, FlowState.SENT, null, false], + [FlowState.RETURNED, FlowState.RETURNED, null, false], ]; - it.each(cases)('%#. should allow editing if MU flow state is sent', (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.KLAGEVEDTAK_V2, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); - }); + it.each(cases)( + '%#. should allow editing if MU flow state is sent or if behandling is finished (and MU has saksbehandler role)', + (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.KLAGEVEDTAK_V2, createOppgave(mu, rol, finished), user)).toBe(expected); + }, + ); }); }); describe('ROL', () => { - const user = { navIdent: 'rol' } as IUserData; + const user = { navIdent: 'rol', roller: [Role.KABAL_ROL] } as IUserData; describe('ROL answers', () => { const cases: Cases = [ // ROL can edit if ROL flow state is sent - [FlowState.NOT_SENT, FlowState.SENT, 'rol', null, true], - [FlowState.SENT, FlowState.SENT, 'rol', null, true], - [FlowState.RETURNED, FlowState.SENT, 'rol', null, true], + [FlowState.NOT_SENT, FlowState.SENT, null, true], + [FlowState.SENT, FlowState.SENT, null, true], + [FlowState.RETURNED, FlowState.SENT, null, true], - // Flow state in finished behandling doesn't really make sense. These cases are just for completeness' sake - [FlowState.NOT_SENT, FlowState.SENT, 'rol', '03.14.1969', true], - [FlowState.SENT, FlowState.SENT, 'rol', '03.14.1969', true], - [FlowState.RETURNED, FlowState.SENT, 'rol', '03.14.1969', true], + // ROL can't edit if behandling is finished + [FlowState.NOT_SENT, FlowState.SENT, '03.14.1969', false], + [FlowState.SENT, FlowState.SENT, '03.14.1969', false], + [FlowState.RETURNED, FlowState.SENT, '03.14.1969', false], // ROL can't edit if ROL flow state is not SENT - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'rol', null, false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'rol', null, false], - [FlowState.SENT, FlowState.NOT_SENT, 'rol', null, false], - [FlowState.SENT, FlowState.RETURNED, 'rol', null, false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'rol', null, false], - [FlowState.RETURNED, FlowState.RETURNED, 'rol', null, false], - - // Flow state in finished behandling doesn't really make sense. These cases are just for completeness' sake - [FlowState.NOT_SENT, FlowState.NOT_SENT, 'rol', '03.14.1969', false], - [FlowState.NOT_SENT, FlowState.RETURNED, 'rol', '03.14.1969', false], - [FlowState.SENT, FlowState.NOT_SENT, 'rol', '03.14.1969', false], - [FlowState.SENT, FlowState.RETURNED, 'rol', '03.14.1969', false], - [FlowState.RETURNED, FlowState.NOT_SENT, 'rol', '03.14.1969', false], - [FlowState.RETURNED, FlowState.RETURNED, 'rol', '03.14.1969', false], + [FlowState.NOT_SENT, FlowState.NOT_SENT, null, false], + [FlowState.NOT_SENT, FlowState.RETURNED, null, false], + [FlowState.SENT, FlowState.NOT_SENT, null, false], + [FlowState.SENT, FlowState.RETURNED, null, false], + [FlowState.RETURNED, FlowState.NOT_SENT, null, false], + [FlowState.RETURNED, FlowState.RETURNED, null, false], + + // Non-saksbehandler can't edit in finished behandling + [FlowState.NOT_SENT, FlowState.NOT_SENT, '03.14.1969', false], + [FlowState.NOT_SENT, FlowState.RETURNED, '03.14.1969', false], + [FlowState.SENT, FlowState.NOT_SENT, '03.14.1969', false], + [FlowState.SENT, FlowState.RETURNED, '03.14.1969', false], + [FlowState.RETURNED, FlowState.NOT_SENT, '03.14.1969', false], + [FlowState.RETURNED, FlowState.RETURNED, '03.14.1969', false], ]; - it.each(cases)('%#. should allow editing if ROL flow state is sent', (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.ROL_ANSWERS, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); - }); + it.each(cases)( + '%#. should allow editing in non-finished behandling if ROL flow state is sent', + (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.ROL_ANSWERS, createOppgave(mu, rol, finished), user)).toBe(expected); + }, + ); }); describe('Other templates', () => { - it.each(CANT_EDIT)('%#. should never allow editing', (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.KLAGEVEDTAK_V2, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); + it.each(CANT_EDIT)('%#. should never allow editing', (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.KLAGEVEDTAK_V2, createOppgave(mu, rol, finished), user)).toBe(expected); }); }); }); @@ -293,33 +258,45 @@ describe('canEditDocument', () => { const user = { navIdent: 'other saksbehandler', roller: [Role.KABAL_SAKSBEHANDLING] } as IUserData; describe('ROL answers', () => { - it.each(CANT_EDIT)('%#. should never allow editing', (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.ROL_ANSWERS, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); + it.each(CANT_EDIT)('%#. should never allow editing', (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.ROL_ANSWERS, createOppgave(mu, rol, finished), user)).toBe(expected); }); }); + const cases: Cases = [ + // All saksbehandlere can edit in finished behandling + [FlowState.NOT_SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.NOT_SENT, FlowState.SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.RETURNED, FlowState.RETURNED, '03.14.1969', true], + [FlowState.RETURNED, FlowState.SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.NOT_SENT, '03.14.1969', true], + [FlowState.SENT, FlowState.RETURNED, '03.14.1969', true], + [FlowState.SENT, FlowState.SENT, '03.14.1969', true], + + // Not assigned saksbehandler can't edit not-finished behandling + [FlowState.NOT_SENT, FlowState.NOT_SENT, null, false], + [FlowState.NOT_SENT, FlowState.RETURNED, null, false], + [FlowState.NOT_SENT, FlowState.SENT, null, false], + [FlowState.RETURNED, FlowState.NOT_SENT, null, false], + [FlowState.RETURNED, FlowState.RETURNED, null, false], + [FlowState.RETURNED, FlowState.SENT, null, false], + [FlowState.SENT, FlowState.NOT_SENT, null, false], + [FlowState.SENT, FlowState.RETURNED, null, false], + [FlowState.SENT, FlowState.SENT, null, false], + ]; + describe('ROL questions', () => { - it.each(CANT_EDIT)( - '%#. should not allow editing if ROL flow state is sent or if user is not the creator of the document', - (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.ROL_QUESTIONS, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); - }, - ); + it.each(cases)('%#. should allow editing in finished behandling', (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.ROL_QUESTIONS, createOppgave(mu, rol, finished), user)).toBe(expected); + }); }); describe('Other templates', () => { - it.each(CANT_EDIT)( - '%#. should not allow editing if MU flow state is sent, or if user is not the creator of the document', - (mu, rol, creator, finished, expected) => { - expect(canEditDocument(TemplateIdEnum.KLAGEVEDTAK_V2, createOppgave(mu, rol, finished), user, creator)).toBe( - expected, - ); - }, - ); + it.each(cases)('%#. should allow editing in finished behandling', (mu, rol, finished, expected) => { + expect(canEditDocument(TemplateIdEnum.KLAGEVEDTAK_V2, createOppgave(mu, rol, finished), user)).toBe(expected); + }); }); }); }); diff --git a/frontend/src/components/smart-editor/hooks/use-can-edit-document.ts b/frontend/src/components/smart-editor/hooks/use-can-edit-document.ts index a26b0eaa7..ac5f07b4c 100644 --- a/frontend/src/components/smart-editor/hooks/use-can-edit-document.ts +++ b/frontend/src/components/smart-editor/hooks/use-can-edit-document.ts @@ -1,106 +1,90 @@ import { StaticDataContext } from '@app/components/app/static-data-context'; import { useOppgave } from '@app/hooks/oppgavebehandling/use-oppgave'; -import type { IUserData } from '@app/types/bruker'; +import { type IUserData, Role } from '@app/types/bruker'; import { SaksTypeEnum } from '@app/types/kodeverk'; import { FlowState } from '@app/types/oppgave-common'; -import type { IOppgavebehandling } from '@app/types/oppgavebehandling/oppgavebehandling'; +import type { + IAnkebehandling, + IKlagebehandling, + IOppgavebehandling, +} from '@app/types/oppgavebehandling/oppgavebehandling'; import { TemplateIdEnum } from '@app/types/smart-editor/template-enums'; import { useContext, useMemo } from 'react'; -export const useCanManageDocument = (templateId: TemplateIdEnum, creator: string): boolean => { +const supportsRol = (oppgave: IOppgavebehandling): oppgave is IKlagebehandling | IAnkebehandling => + oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE; + +export const useCanManageDocument = (templateId: TemplateIdEnum): boolean => { const { data: oppgave, isSuccess } = useOppgave(); const { user } = useContext(StaticDataContext); return useMemo( - () => isSuccess && canManageDocument(templateId, oppgave, user, creator), - [oppgave, isSuccess, templateId, user, creator], + () => isSuccess && canEditDocument(templateId, oppgave, user), + [oppgave, isSuccess, templateId, user], ); }; -const canManageDocument = ( - templateId: TemplateIdEnum, - oppgave: IOppgavebehandling, - user: IUserData, - creator: string, -): boolean => { - if ( - (oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE) && - oppgave.rol?.flowState === FlowState.SENT && - templateId === TemplateIdEnum.ROL_QUESTIONS - ) { - // No one can edit ROL questions after they have been sent. - return false; - } - - if (isRol(oppgave, user)) { - return rolCanEdit(templateId, oppgave); - } - - if (isMu(oppgave, user)) { - return oppgave.avsluttetAvSaksbehandlerDate !== null && saksbehandlerCanEdit(templateId, oppgave, user, creator); - } +export const useCanEditDocument = (templateId: TemplateIdEnum): boolean => { + const { data: oppgave, isSuccess } = useOppgave(); + const { user } = useContext(StaticDataContext); - return saksbehandlerCanEdit(templateId, oppgave, user, creator); + return useMemo( + () => isSuccess && canEditDocument(templateId, oppgave, user), + [oppgave, isSuccess, templateId, user], + ); }; -const saksbehandlerCanEdit = ( - templateId: TemplateIdEnum, - oppgave: IOppgavebehandling, - user: IUserData, - creator: string, -): boolean => { - const isCreator = creator === user.navIdent; - const isFinished = oppgave.avsluttetAvSaksbehandlerDate !== null; - const isAssigned = oppgave.saksbehandler?.navIdent === user.navIdent; +const isRol = (oppgave: IOppgavebehandling, user: IUserData): boolean => + supportsRol(oppgave) && oppgave.rol.employee?.navIdent === user.navIdent; - const canWrite = (!isFinished && isAssigned) || (isFinished && isCreator); +const rolCanEdit = (oppgave: IOppgavebehandling, user: IUserData): boolean => + supportsRol(oppgave) && + isRol(oppgave, user) && + oppgave.avsluttetAvSaksbehandlerDate === null && + oppgave.rol?.flowState === FlowState.SENT; +export const canEditDocument = (templateId: TemplateIdEnum, oppgave: IOppgavebehandling, user: IUserData): boolean => { if (templateId === TemplateIdEnum.ROL_ANSWERS) { - return false; + return rolCanEdit(oppgave, user); } - // When behandling is sent to ROL, saksbehandler can edit everything except questions. - if (templateId === TemplateIdEnum.ROL_QUESTIONS) { - return ( - canWrite && - (oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE) && - oppgave.rol?.flowState !== FlowState.SENT - ); + const hasSaksbehandlerRole = user.roller.includes(Role.KABAL_SAKSBEHANDLING); + + if (oppgave.avsluttetAvSaksbehandlerDate !== null) { + return hasSaksbehandlerRole; } - return canWrite && oppgave.medunderskriver?.flowState !== FlowState.SENT; -}; + const isAssignedSaksbehandler = oppgave.saksbehandler?.navIdent === user.navIdent; + const isMu = oppgave.medunderskriver?.employee?.navIdent === user.navIdent; + const sentToMu = oppgave.medunderskriver.flowState === FlowState.SENT; -const isMu = (oppgave: IOppgavebehandling, user: IUserData): boolean => - oppgave.medunderskriver?.employee?.navIdent === user.navIdent; + if (templateId === TemplateIdEnum.ROL_QUESTIONS && supportsRol(oppgave)) { + if (isRol(oppgave, user)) { + return false; + } -const isRol = (oppgave: IOppgavebehandling, user: IUserData): boolean => - (oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE) && - oppgave.rol.employee?.navIdent === user.navIdent; + if (oppgave.rol?.flowState === FlowState.SENT) { + return false; + } -// Only ROL can edit answers after they have been sent. -const rolCanEdit = (templateId: TemplateIdEnum, oppgave: IOppgavebehandling): boolean => - (oppgave.typeId === SaksTypeEnum.KLAGE || oppgave.typeId === SaksTypeEnum.ANKE) && - oppgave.rol.flowState === FlowState.SENT && - templateId === TemplateIdEnum.ROL_ANSWERS; + if (isAssignedSaksbehandler) { + return !sentToMu; + } -export const useCanEditDocument = (templateId: TemplateIdEnum, creator: string): boolean => { - const { data: oppgave, isSuccess } = useOppgave(); - const { user } = useContext(StaticDataContext); + if (isMu) { + return sentToMu; + } + } - return useMemo( - () => isSuccess && canEditDocument(templateId, oppgave, user, creator), - [oppgave, isSuccess, templateId, user, creator], - ); -}; + if (isMu) { + return sentToMu; + } -const muCanEdit = (templateId: TemplateIdEnum, oppgave: IOppgavebehandling): boolean => - oppgave.medunderskriver.flowState === FlowState.SENT && templateId !== TemplateIdEnum.ROL_ANSWERS; + if (sentToMu) { + return false; + } -export const canEditDocument = ( - templateId: TemplateIdEnum, - oppgave: IOppgavebehandling, - user: IUserData, - creator: string, -): boolean => - canManageDocument(templateId, oppgave, user, creator) || (isMu(oppgave, user) && muCanEdit(templateId, oppgave)); + const isFinished = oppgave.avsluttetAvSaksbehandlerDate !== null; + + return (!isFinished && isAssignedSaksbehandler) || (isFinished && hasSaksbehandlerRole); +}; diff --git a/frontend/src/components/smart-editor/new-document/new-document.tsx b/frontend/src/components/smart-editor/new-document/new-document.tsx index 63ab9f951..832ed0066 100644 --- a/frontend/src/components/smart-editor/new-document/new-document.tsx +++ b/frontend/src/components/smart-editor/new-document/new-document.tsx @@ -6,7 +6,7 @@ import { useHasDocumentsAccess } from '@app/hooks/use-has-documents-access'; import { useIsFeilregistrert } from '@app/hooks/use-is-feilregistrert'; import { useIsRol } from '@app/hooks/use-is-rol'; import { useIsSaksbehandler } from '@app/hooks/use-is-saksbehandler'; -import { GENERELT_BREV_WITHOUT_MU_TEMPLATE, NOTAT_TEMPLATE } from '@app/plate/templates/simple-templates'; +import { NOTAT_TEMPLATE, getGenereltBrevTemplate } from '@app/plate/templates/simple-templates'; import { ANKE_I_TRYGDERETTEN_TEMPLATES, ANKE_TEMPLATES, @@ -104,6 +104,7 @@ export const NewDocument = ({ onCreate }: Props) => { const useTemplates = (oppgave: IOppgavebehandling | undefined) => { const isSaksbehandler = useIsSaksbehandler(); const isRol = useIsRol(); + const { user } = useContext(StaticDataContext); if (oppgave === undefined) { return []; @@ -112,7 +113,7 @@ const useTemplates = (oppgave: IOppgavebehandling | undefined) => { const { isAvsluttetAvSaksbehandler, typeId } = oppgave; if (isAvsluttetAvSaksbehandler) { - return [GENERELT_BREV_WITHOUT_MU_TEMPLATE, NOTAT_TEMPLATE]; + return [getGenereltBrevTemplate(false, user.navIdent), NOTAT_TEMPLATE]; } if (isSaksbehandler || isRol) { diff --git a/frontend/src/components/smart-editor/tabbed-editors/editor.tsx b/frontend/src/components/smart-editor/tabbed-editors/editor.tsx index 2d5c05b9a..55c63b6a0 100644 --- a/frontend/src/components/smart-editor/tabbed-editors/editor.tsx +++ b/frontend/src/components/smart-editor/tabbed-editors/editor.tsx @@ -68,10 +68,10 @@ interface LoadedEditorProps extends EditorProps { } const LoadedEditor = ({ oppgave, smartDocument, scalingGroup }: LoadedEditorProps) => { - const { id, templateId, creator } = smartDocument; + const { id, templateId } = smartDocument; const { newCommentSelection } = useContext(SmartEditorContext); const { user } = useContext(StaticDataContext); - const canEdit = useCanEditDocument(templateId, creator.employee.navIdent); + const canEdit = useCanEditDocument(templateId); const plugins = collaborationSaksbehandlerPlugins(oppgave.id, id, smartDocument, user); const editor = usePlateEditor({ diff --git a/frontend/src/components/smart-editor/tabbed-editors/tab-panel.tsx b/frontend/src/components/smart-editor/tabbed-editors/tab-panel.tsx index 7fd2682f0..f81242ed2 100644 --- a/frontend/src/components/smart-editor/tabbed-editors/tab-panel.tsx +++ b/frontend/src/components/smart-editor/tabbed-editors/tab-panel.tsx @@ -16,7 +16,7 @@ export const TabPanel = ({ smartDocument }: TabPanelProps) => { const { id } = smartDocument; const smartDocumentRef = useRef(smartDocument); - const canEditDocument = useCanEditDocument(smartDocument.templateId, smartDocument.creator.employee.navIdent); + const canEditDocument = useCanEditDocument(smartDocument.templateId); const canEditDocumentRef = useRef(canEditDocument); // Ensure that smartDocumentRef and canEditDocumentRef are always up to date in order to avoid the unmount debounce triggering on archive/delete/fradeling diff --git a/frontend/src/plate/components/signature/signature.tsx b/frontend/src/plate/components/signature/signature.tsx index dbdc29b19..dfac6fbb6 100644 --- a/frontend/src/plate/components/signature/signature.tsx +++ b/frontend/src/plate/components/signature/signature.tsx @@ -31,7 +31,7 @@ export const Signature = (props: PlateElementProps) => { const showMedunderskriverCheckbox = hasMedunderskriver && !isRolAnswers; const showForkortedeNavnCheckbox = hasMedunderskriver || !signature.anonymous; const showSuffixCheckbox = !(signature.anonymous || isRolAnswers); - const showUseMyNameCheckbox = oppgave.avsluttetAvSaksbehandlerDate === null; + const showUseMyNameCheckbox = oppgave.avsluttetAvSaksbehandlerDate !== null; const hideAll = !(showForkortedeNavnCheckbox || showSuffixCheckbox || hasMedunderskriver); diff --git a/frontend/src/plate/templates/helpers.ts b/frontend/src/plate/templates/helpers.ts index c2e337526..5191323ee 100644 --- a/frontend/src/plate/templates/helpers.ts +++ b/frontend/src/plate/templates/helpers.ts @@ -140,12 +140,12 @@ export const createSimpleBulletList = (...textItems: string[]): BulletListElemen children: textItems.map(createSimpleListItem), }); -export const createSignature = (includeMedunderskriver = true): SignatureElement => ({ +export const createSignature = (includeMedunderskriver = true, overriddenSaksbehandler?: string): SignatureElement => ({ type: ELEMENT_SIGNATURE, useShortName: false, includeMedunderskriver, useSuffix: true, - overriddenSaksbehandler: undefined, + overriddenSaksbehandler, children: [{ text: '' }], threadIds: [], }); diff --git a/frontend/src/plate/templates/simple-templates.ts b/frontend/src/plate/templates/simple-templates.ts index 620793d9a..fac14cd8b 100644 --- a/frontend/src/plate/templates/simple-templates.ts +++ b/frontend/src/plate/templates/simple-templates.ts @@ -19,7 +19,10 @@ import { createSimpleParagraph, } from './helpers'; -const getGenereltBrevTemplate = (includeMedunderskriver: boolean): Immutable => +export const getGenereltBrevTemplate = ( + includeMedunderskriver: boolean, + overriddenSaksbehandler?: string, +): Immutable => deepFreeze({ templateId: TemplateIdEnum.GENERELT_BREV, tittel: 'Generelt brev', @@ -27,14 +30,13 @@ const getGenereltBrevTemplate = (includeMedunderskriver: boolean): Immutable({ templateId: TemplateIdEnum.NOTAT, From 2ae29cbf4fc9277c58ba510ef48f338ce66f045c Mon Sep 17 00:00:00 2001 From: Daniel Eriksson Date: Tue, 14 Jan 2025 11:22:02 +0100 Subject: [PATCH 2/3] Fix bug where anonymous signature was missing --- frontend/src/plate/components/signature/hooks.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/plate/components/signature/hooks.ts b/frontend/src/plate/components/signature/hooks.ts index f6494afc8..c429bf1cd 100644 --- a/frontend/src/plate/components/signature/hooks.ts +++ b/frontend/src/plate/components/signature/hooks.ts @@ -38,10 +38,6 @@ export const useMainSignature = (element: SignatureElement): ISignature | undefi isRolAnswers && isRolSakstype ? (oppgave.rol.employee?.navIdent ?? skipToken) : skipToken, ); - if (element.anonymous) { - return { name: 'Nav klageinstans' }; - } - const suffix = templateId !== TemplateIdEnum.ROL_ANSWERS && element.useSuffix ? 'saksbehandler' : undefined; if (isRolAnswers) { @@ -64,6 +60,10 @@ const toSignature = ( return undefined; } + if (signature.anonymous) { + return { name: 'Nav klageinstans' }; + } + return { name: getName(signature, useShortName), title: getTitle(signature.customJobTitle, suffix) ?? MISSING_TITLE, From f1cb0f99d0bf037e5b899dae63cf7f93cfd6d584 Mon Sep 17 00:00:00 2001 From: Daniel Eriksson Date: Tue, 14 Jan 2025 11:24:58 +0100 Subject: [PATCH 3/3] Only show 'Bruk forkortede navn' checkbox if medunderskriver is included (or signature is not anonymous) --- frontend/src/plate/components/signature/signature.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/plate/components/signature/signature.tsx b/frontend/src/plate/components/signature/signature.tsx index dfac6fbb6..c6a3caf1c 100644 --- a/frontend/src/plate/components/signature/signature.tsx +++ b/frontend/src/plate/components/signature/signature.tsx @@ -27,15 +27,15 @@ export const Signature = (props: PlateElementProps) => { const isRolAnswers = templateId === TemplateIdEnum.ROL_ANSWERS; + const { children, element, editor } = props; const hasMedunderskriver = oppgave.medunderskriver.employee !== null; const showMedunderskriverCheckbox = hasMedunderskriver && !isRolAnswers; - const showForkortedeNavnCheckbox = hasMedunderskriver || !signature.anonymous; + const showForkortedeNavnCheckbox = element.includeMedunderskriver || !signature.anonymous; const showSuffixCheckbox = !(signature.anonymous || isRolAnswers); const showUseMyNameCheckbox = oppgave.avsluttetAvSaksbehandlerDate !== null; const hideAll = !(showForkortedeNavnCheckbox || showSuffixCheckbox || hasMedunderskriver); - const { children, element, editor } = props; const overriddenWithSelf = element.overriddenSaksbehandler === user.navIdent; const options: SetNodesOptions = { at: [], voids: true, mode: 'lowest', match: (n) => n === element };