Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(inao-pp-cem): dataverse check and template-api-module adjustments #16958

Merged
merged 13 commits into from
Nov 22, 2024

Conversation

jonnigs
Copy link
Member

@jonnigs jonnigs commented Nov 20, 2024

What

Added a new userRole to political party and cemetery that sends you right away to a screen that says that the national Id is not registered correctly with Ríkisendurskoðun

Adjusted the template-api-modules so that they won't do the same user check again.
Made the template-api-modules behave the same way.

Why

Requested behaviour

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced notAllowedForm and notAllowedSection to handle restricted access scenarios.
    • Added specific messages for unregistered national IDs in both financial statement templates.
  • Improvements

    • Enhanced role management with new roles (NOTALLOWED and REJECTED) and refined user type validation.
    • Improved error handling in application submissions for both cemetery and political party templates.
  • Removals

    • Removed the DelegationCheck component from both financial statement templates to simplify user input validation.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The pull request includes modifications to the ownership structure in the .github/CODEOWNERS file, transferring ownership of the /libs/clients/financial-statements-inao path from the @island-is/programm team to the @island-is/norda team. Additionally, several updates were made to the FinancialStatementCemeteryTemplateService and FinancialStatementPoliticalPartyTemplateService classes, enhancing type safety, error handling, and the overall logic for user role management. New forms and sections were introduced for handling not-allowed scenarios, while existing delegation check components were removed from both cemetery and political party templates.

Changes

File Change Summary
.github/CODEOWNERS Ownership of /libs/clients/financial-statements-inao changed from @island-is/programm to @island-is/norda.
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts Updated type inference, modified getCurrentUserType to return null, restructured submitApplication, added prepareValues method.
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-political-party/financial-statement-political-party.service.ts Simplified getCurrentUserType, modified getUserType to return null, adjusted error handling in submitApplication.
libs/application/templates/inao/financial-statement-cemetery/src/fields/DelegationCheck/index.ts Component DelegationCheck removed.
libs/application/templates/inao/financial-statement-cemetery/src/fields/index.ts Removed export of DelegationCheck.
libs/application/templates/inao/financial-statement-cemetery/src/forms/applicationForm/clientInfoSection/index.ts Removed buildCustomField for delegation check.
libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/index.ts Introduced notAllowedForm using buildForm.
libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/notAllowedSection.ts Introduced notAllowedSection with description field.
libs/application/templates/inao/financial-statement-cemetery/src/lib/financialStatementCemeteryTemplate.ts Updated state machine configuration and user role logic.
libs/application/templates/inao/financial-statement-cemetery/src/lib/messages.ts Added messages for notAllowedTitle and notAllowedDescription.
libs/application/templates/inao/financial-statement-cemetery/src/types/types.ts Added NOTALLOWED enum value to Roles.
libs/application/templates/inao/financial-statement-cemetery/src/utils/constants.ts Added constant CEMETERY_USER_TYPE.
libs/application/templates/inao/financial-statement-political-party/src/fields/DelegationCheck/DelegationCheck.tsx Component DelegationCheck removed.
libs/application/templates/inao/financial-statement-political-party/src/fields/index.ts Removed export of DelegationCheck.
libs/application/templates/inao/financial-statement-political-party/src/forms/applicationForm/clientInfoSection/index.ts Removed buildCustomField for delegation check.
libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/index.ts Introduced notAllowedForm.
libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/notAllowedSection.ts Introduced notAllowedSection with description field.
libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts Updated user role logic and state machine configuration.
libs/application/templates/inao/financial-statement-political-party/src/lib/messages.ts Added messages for notAllowedTitle and notAllowedDescription.
libs/application/templates/inao/financial-statement-political-party/src/types/types.ts Added REJECTED enum value to States and NOTALLOWED to Roles.
libs/application/templates/inao/financial-statement-political-party/src/utils/constants.ts Added constant POLITICALPARTY_USER_TYPE.
libs/clients/financial-statements-inao/src/lib/financialStatementsInao.config.ts Updated environment variable values for FINANCIAL_STATEMENTS_INAO_BASE_PATH and FINANCIAL_STATEMENTS_INAO_SCOPE.

Suggested labels

automerge

Suggested reviewers

  • kksteini
  • rafnarnason

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jonnigs jonnigs changed the title Chore/inao cem procure and dataverse chore(inao-pp-cem): dataverse check and template-api-module adjustments Nov 20, 2024
@jonnigs jonnigs marked this pull request as ready for review November 20, 2024 14:15
@jonnigs jonnigs requested review from a team as code owners November 20, 2024 14:15
@jonnigs jonnigs requested a review from a team as a code owner November 20, 2024 14:19
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.

Project coverage is 35.89%. Comparing base (9997637) to head (02f6874).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...t-cemetery/financial-statement-cemetery.service.ts 0.00% 15 Missing ⚠️
...rty/financial-statement-political-party.service.ts 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16958      +/-   ##
==========================================
+ Coverage   35.62%   35.89%   +0.27%     
==========================================
  Files        6915     6913       -2     
  Lines      146037   145298     -739     
  Branches    41457    41456       -1     
==========================================
+ Hits        52021    52155     +134     
+ Misses      94016    93143     -873     
Flag Coverage Δ
api 3.34% <ø> (ø)
application-system-api 38.69% <0.00%> (+<0.01%) ⬆️
application-template-api-modules 27.74% <0.00%> (+0.02%) ⬆️
application-ui-shell 20.57% <ø> (ø)
clients-financial-statements-inao 49.06% <ø> (ø)
contentful-apps 4.69% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rty/financial-statement-political-party.service.ts 21.73% <0.00%> (+0.31%) ⬆️
...t-cemetery/financial-statement-cemetery.service.ts 27.77% <0.00%> (+2.35%) ⬆️

... and 86 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9997637...02f6874. Read the comment docs.

---- 🚨 Try these New Features:

Copy link
Member

@norda-gunni norda-gunni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 20, 2024

Datadog Report

All test runs c4ae6df 🔗

5 Total Test Services: 0 Failed, 5 Passed
➡️ Test Sessions change in coverage: 14 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.43s 1 no change Link
application-system-api 0 0 0 34 0 2m 14s 1 no change Link
application-template-api-modules 0 0 0 116 0 2m 5.43s 1 no change Link
application-ui-shell 0 0 0 74 0 38.98s 1 no change Link
clients-financial-statements-inao 0 0 0 13 0 5.8s 1 no change Link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Outside diff range and nitpick comments (18)
libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/index.ts (2)

5-10: Consider adding explicit type definitions for form configuration.

While the code is functionally correct, we should enhance type safety by explicitly defining the form configuration type.

+import { Form } from '@island.is/application/core'

-export const notAllowedForm = buildForm({
+export const notAllowedForm: Form = buildForm({
   id: 'notAllowedForm',
   title: '',
   logo: Logo,
   children: [notAllowedSection],
})

1-10: Overall structure looks good and follows template guidelines.

The form implementation is clean, modular, and follows the reusability guidelines for template components.

Consider documenting the purpose of this form in a comment block, especially since it's part of a not-allowed flow, to help other developers understand its usage context.

libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/index.ts (1)

1-3: Consider enhancing type safety and import structure.

To improve type safety and maintainability:

  1. Consider importing and explicitly typing the form configuration interface
  2. Consider using absolute imports instead of relative paths for better maintainability
-import { buildForm } from '@island.is/application/core'
+import { buildForm, FormBuilder } from '@island.is/application/core'
-import { notAllowedSection } from './notAllowedSection'
-import Logo from '../../components/Logo'
+import { notAllowedSection } from '@island.is/application/templates/inao/financial-statement-political-party/forms/notAllowedForm/notAllowedSection'
+import { Logo } from '@island.is/application/templates/inao/financial-statement-political-party/components/Logo'
libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/notAllowedSection.ts (1)

1-6: LGTM! Consider exporting types for better reusability

The imports are well-organized and properly destructured. Since this is in the libs directory, consider exporting any relevant types for better TypeScript integration across different apps.

+import type { Section } from '@island.is/application/core'
 import {
   buildDescriptionField,
   buildSection,
 } from '@island.is/application/core'
 import { m } from '../../lib/messages'
+
+export type NotAllowedSectionType = Section
libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/notAllowedSection.ts (2)

7-17: Consider adding a descriptive title for better accessibility.

The empty title string might affect screen readers and accessibility. Consider adding a meaningful title or documenting why it's intentionally left empty.

 export const notAllowedSection = buildSection({
   id: 'notAllowedSection',
-  title: '',
+  title: m.notAllowedTitle,
   children: [

7-17: Consider making the section more reusable.

To improve reusability across different NextJS apps (as per coding guidelines), consider:

  1. Making the messages configurable through props
  2. Adding documentation for reuse scenarios
+interface NotAllowedSectionProps {
+  titleMessage: string;
+  descriptionMessage: string;
+}
+
+export const createNotAllowedSection = ({
+  titleMessage,
+  descriptionMessage,
+}: NotAllowedSectionProps): Section => buildSection({
   id: 'notAllowedSection',
   title: '',
   children: [
     buildDescriptionField({
       id: 'notAllowedDescription',
-      title: m.notAllowedTitle,
-      description: m.notAllowedDescription,
+      title: titleMessage,
+      description: descriptionMessage,
     }),
   ],
 })
libs/application/templates/inao/financial-statement-political-party/src/types/types.ts (1)

14-14: Maintain consistent naming convention in Roles enum

The value 'notAllowed' uses camelCase while other enum values use lowercase. Consider maintaining consistency with the existing pattern:

-  NOTALLOWED = 'notAllowed',
+  NOTALLOWED = 'notallowed',
libs/application/templates/inao/financial-statement-cemetery/src/types/types.ts (2)

37-37: Add JSDoc comment to document the role's purpose.

The new role aligns well with the requirement to handle users not registered correctly with Ríkisendurskoðun. Consider adding documentation to explain its purpose.

+  /** Role assigned to users whose national ID is not properly registered with Ríkisendurskoðun */
   NOTALLOWED = 'notAllowed',

37-37: Follow consistent enum naming convention.

The enum value uses camelCase ('notAllowed') while other values in the enum use UPPERCASE. Consider maintaining consistency:

-  NOTALLOWED = 'notAllowed',
+  NOTALLOWED = 'NOTALLOWED',
libs/application/templates/inao/financial-statement-cemetery/src/utils/constants.ts (1)

17-17: Document the meaning of the user type value

The magic number 150000002 should be documented to explain its significance and usage. Consider adding a comment explaining what this user type represents and why this specific value is used.

+// Represents a cemetery user type in the system, used for role-based access control
 export const CEMETERY_USER_TYPE = 150000002
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts (1)

88-91: Enhance type safety with explicit return type.

The method could benefit from an explicit return type to ensure type safety across the codebase.

-  async getUserType({ auth }: TemplateApiModuleActionProps) {
+  async getUserType({ auth }: TemplateApiModuleActionProps): Promise<number | null> {
libs/application/templates/inao/financial-statement-cemetery/src/lib/financialStatementCemeteryTemplate.ts (1)

155-158: Enhance type safety for external data access

While the code uses TypeScript, the type safety of external data access could be improved.

Consider defining an interface for the external data structure:

interface UserTypeData {
  getUserType: {
    data: {
      value: number;
    };
  };
}

// Then use it in getValueViaPath
const userType = getValueViaPath<number, UserTypeData>(
  application.externalData as UserTypeData,
  'getUserType.data.value',
)
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-political-party/financial-statement-political-party.service.ts (1)

Line range hint 115-127: Standardize error handling approach.

The error handling in submitApplication shows mixed patterns:

  • Some errors are thrown directly
  • Others return an error object
  • There's a commented-out throw statement

Consider standardizing the error handling approach across the service for consistency.

Suggested approach:

 } catch (error) {
   this.logger.error('Error submitting application', error)
-  return {
-    success: false,
-    message: error.message,
-  }
-  // throw new Error('Application submission failed')
+  throw new Error(`Application submission failed: ${error.message}`)
 }
libs/application/templates/inao/financial-statement-political-party/src/lib/messages.ts (2)

561-572: Consider making the phone number configurable

The implementation looks good and aligns with the PR objectives. However, consider extracting the phone number into a separate message to make it configurable independently.

 notAllowedDescription: {
   id: 'fspp.application:notAllowedDescription',
   defaultMessage:
-    'Ef þú telur að þessi kennitala ætti að vera skráð sem stjórnmálasamtök þá bendum við þér á að hafa samband við Ríkisendurskoðun í síma 448 8800',
+    'Ef þú telur að þessi kennitala ætti að vera skráð sem stjórnmálasamtök þá bendum við þér á að hafa samband við Ríkisendurskoðun í síma {phoneNumber}',
   description: 'Descriptionwhen user is not allowed to apply',
 },
+inaoPhoneNumber: {
+  id: 'fspp.application:inaoPhoneNumber',
+  defaultMessage: '448 8800',
+  description: 'Phone number for INAO (Ríkisendurskoðun)',
+},

571-571: Fix typo in the description field

There's a typo in the description field: "Descriptionwhen" should be "Description when".

-  description: 'Descriptionwhen user is not allowed to apply',
+  description: 'Description when user is not allowed to apply',
libs/application/templates/inao/financial-statement-cemetery/src/lib/messages.ts (1)

679-684: Consider extracting the phone number into a separate message.

The phone number (448 8800) is currently hard-coded in the message. To improve maintainability, consider extracting it to a separate message.

+  inaoPhoneNumber: {
+    id: 'fsc.application:inaoPhoneNumber',
+    defaultMessage: '448 8800',
+    description: 'INAO contact phone number',
+  },
   notAllowedDescription: {
     id: 'fsc.application:notAllowedDescription',
     defaultMessage:
-      'Ef þú telur að þessi kennitala ætti að vera skráð sem kirkjugarður þá bendum við þér á að hafa samband við Ríkisendurskoðun í síma 448 8800',
+      'Ef þú telur að þessi kennitala ætti að vera skráð sem kirkjugarður þá bendum við þér á að hafa samband við Ríkisendurskoðun í síma {phoneNumber}',
-    description: 'Descriptionwhen user is not allowed to apply',
+    description: 'Description when user is not allowed to apply',
   },
libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts (2)

159-159: Consider removing unused parameter _nationalId

Since _nationalId is not utilized within the mapUserToRole method, consider removing it if it is not required by the interface. This will clean up the code and prevent potential confusion.


162-165: Ensure safe retrieval of userType from external data

To prevent potential runtime errors, consider adding a default value or validation when retrieving userType using getValueViaPath, in case the path does not exist or returns undefined.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c20e595 and 830a5ae.

📒 Files selected for processing (22)
  • .github/CODEOWNERS (1 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts (3 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/financial-statement-political-party/financial-statement-political-party.service.ts (2 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/fields/DelegationCheck/index.tsx (0 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/fields/index.ts (0 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/forms/applicationForm/clientInfoSection/index.ts (0 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/index.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/notAllowedSection.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/lib/financialStatementCemeteryTemplate.ts (5 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/lib/messages.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/types/types.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/utils/constants.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/fields/DelegationCheck/DelegationCheck.tsx (0 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/fields/index.ts (0 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/forms/applicationForm/clientInfoSection/index.ts (0 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/index.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/notAllowedSection.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts (5 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/lib/messages.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/types/types.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/utils/constants.ts (1 hunks)
  • libs/clients/financial-statements-inao/src/lib/financialStatementsInao.config.ts (1 hunks)
💤 Files with no reviewable changes (6)
  • libs/application/templates/inao/financial-statement-cemetery/src/fields/DelegationCheck/index.tsx
  • libs/application/templates/inao/financial-statement-cemetery/src/fields/index.ts
  • libs/application/templates/inao/financial-statement-cemetery/src/forms/applicationForm/clientInfoSection/index.ts
  • libs/application/templates/inao/financial-statement-political-party/src/fields/DelegationCheck/DelegationCheck.tsx
  • libs/application/templates/inao/financial-statement-political-party/src/fields/index.ts
  • libs/application/templates/inao/financial-statement-political-party/src/forms/applicationForm/clientInfoSection/index.ts
✅ Files skipped from review due to trivial changes (1)
  • libs/clients/financial-statements-inao/src/lib/financialStatementsInao.config.ts
🧰 Additional context used
📓 Path-based instructions (14)
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-political-party/financial-statement-political-party.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/index.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/notAllowedSection.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-cemetery/src/lib/financialStatementCemeteryTemplate.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-cemetery/src/lib/messages.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-cemetery/src/types/types.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-cemetery/src/utils/constants.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/index.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/notAllowedSection.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-political-party/src/lib/messages.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-political-party/src/types/types.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-political-party/src/utils/constants.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (20)
libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/index.ts (2)

1-4: LGTM! Clean imports following best practices.

The imports are well-organized and follow tree-shaking practices by importing specific components.


7-7: Verify if empty title is intentional.

The form title is set to an empty string. Please confirm if this is intentional or if it should display a meaningful title for better user experience.

✅ Verification successful

Empty title is intentional for this not-allowed form

Based on the context, the empty title is intentional as this is a special "not allowed" form that displays a message to users who aren't authorized to submit financial statements. The form's content is managed through the messages file where notAllowedTitle and notAllowedDescription define the actual content shown to users, explaining why they can't proceed and providing guidance on next steps.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if other forms in the codebase typically have titles
# Look for buildForm usage with title property

ast-grep --pattern 'buildForm({
  $$$
  title: $title,
  $$$
})'

Length of output: 66


Script:

#!/bin/bash
# Let's try a different approach to find form title patterns
# Search for files containing 'title' in forms directories
fd "index.ts" -p "forms" --exec rg -A 2 -B 2 "title: ['\"](.*?)['\"]" {}

# Also check the specific file content
cat libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/index.ts

Length of output: 549


Script:

#!/bin/bash
# Let's check the notAllowedSection to understand the context better
cat libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/notAllowedSection.ts

# Also search for other similar not allowed forms
rg -B 2 -A 2 "notAllowed.*Form" --type ts

Length of output: 3656


Script:

#!/bin/bash
# Let's check the messages file to see if there's a pattern with titles being defined there
cat libs/application/templates/inao/financial-statement-cemetery/src/lib/messages.ts

Length of output: 23403

libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/index.ts (1)

5-10: Verify handling of political party user role.

Please ensure that the notAllowedSection properly handles the new userRole for political parties as mentioned in the PR objectives.

✅ Verification successful

Let me gather more information about the notAllowedSection implementation.


Let me check the implementation of notAllowedSection to verify the handling of political party roles.


Let me check the complete implementation of the template to understand how political party roles are handled.


Political party role handling is properly implemented

The template correctly handles the political party user role through the following mechanisms:

  • The mapUserToRole function checks if the user is a political party (POLITICALPARTY_USER_TYPE) and assigns the appropriate role (APPLICANT or NOTALLOWED)
  • The notAllowedSection is shown to users with NOTALLOWED role, displaying appropriate messages defined in the template
  • The messages inform users that their ID is not registered as a political party and provide guidance to contact the relevant authority
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if notAllowedSection handles the new userRole

# Search for userRole handling in notAllowedSection
ast-grep --pattern 'export const notAllowedSection = {
  $$$
  userRole $$$
  $$$
}'

# Check for role-related messages
rg -A 2 "notAllowedTitle|notAllowedDescription" --type ts

Length of output: 3668


Script:

#!/bin/bash
# Check the complete implementation of notAllowedSection
ast-grep --pattern 'export const notAllowedSection = {
  $$$
}'

# Check for any role-based checks or conditions
rg -A 5 "userRole|isValidPoliticalParty" --type ts

Length of output: 42521


Script:

#!/bin/bash
# Get the implementation of notAllowedSection
cat libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/notAllowedSection.ts

# Check for any role-based logic in the template
rg -A 5 "mapUserToRole|getRoleInState" libs/application/templates/inao/financial-statement-political-party/src/

Length of output: 1522


Script:

#!/bin/bash
# Get the complete template implementation
cat libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts

# Check for role-related constants or types
rg -A 3 "enum.*Role|type.*Role|interface.*Role" libs/application/templates/inao/financial-statement-political-party/src/

Length of output: 5596

libs/application/templates/inao/financial-statement-cemetery/src/forms/notAllowed/notAllowedSection.ts (1)

7-17: Verify the empty title and consider adding documentation

The section implementation looks good with proper localization. However, there are two points to consider:

  1. Verify if the empty title on line 9 is intentional
  2. Consider adding JSDoc comments to document the purpose of this section
+/**
+ * Builds a section to display when a user is not allowed to access the application.
+ * This section contains a description explaining why access is denied.
+ */
 export const notAllowedSection = buildSection({
   id: 'notAllowedSection',
   title: '',
   children: [

Let's verify the empty title pattern usage:

✅ Verification successful

Based on the search results, I can see that empty titles are commonly used throughout the codebase in various forms and sections. The pattern of having an empty title (title: '') appears to be an established practice, particularly in:

  1. Notification/status sections (e.g. in InReview forms)
  2. Conclusion sections
  3. Prerequisite sections
  4. Sections where the visual hierarchy doesn't require a title

The notAllowedSection in question follows this pattern appropriately since it's a notification-type section displaying access denial information.

Empty title is an established pattern, and JSDoc documentation would improve clarity

The empty title is consistent with the codebase patterns. Adding JSDoc documentation as suggested would indeed improve code clarity by explaining the section's purpose.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if empty titles are used in other sections for consistency

# Search for buildSection with empty titles
rg -A 5 "buildSection\({[\s\n]*id:.*title:\s*['\"]'," libs/

Length of output: 206


Script:

#!/bin/bash
# Search for buildSection with empty titles using a simpler pattern
rg "title: ''" libs/

# Also search for buildSection pattern to understand the general usage
rg "buildSection\(" -A 3 libs/

Length of output: 552846

libs/application/templates/inao/financial-statement-political-party/src/forms/notAllowedForm/notAllowedSection.ts (2)

1-5: LGTM! Well-structured imports following best practices.

The imports are properly organized, using named imports which enables effective tree-shaking.


13-14: Verify the message keys exist in the messages file.

Ensure that notAllowedTitle and notAllowedDescription are properly defined in the messages file.

✅ Verification successful

Message keys are properly defined in the messages file

Both notAllowedTitle and notAllowedDescription keys are correctly defined in the messages file at libs/application/templates/inao/financial-statement-political-party/src/lib/messages.ts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the required message keys exist in the messages file
rg "notAllowedTitle|notAllowedDescription" "libs/application/templates/inao/financial-statement-political-party/src/lib/messages.ts"

Length of output: 274

libs/application/templates/inao/financial-statement-political-party/src/types/types.ts (1)

9-9: LGTM! New state added correctly

The REJECTED state is properly added to handle applications that don't meet the registration requirements.

libs/application/templates/inao/financial-statement-cemetery/src/utils/constants.ts (1)

17-17: Consider explicit typing and potential relocation

A few suggestions to improve type safety and reusability:

  1. Add explicit type annotation
  2. If this user type is used across different templates, consider moving it to a shared constants file
-export const CEMETERY_USER_TYPE = 150000002
+export const CEMETERY_USER_TYPE: number = 150000002

Let's check if this constant is used in other templates:

✅ Verification successful

No need to relocate the constant, but type annotation would improve safety

The constant CEMETERY_USER_TYPE is only used within the financial-statement-cemetery template (in financialStatementCemeteryTemplate.ts). Since it's not shared across other templates, it should remain in its current location. However, adding the explicit type annotation would indeed improve type safety.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for CEMETERY_USER_TYPE usage across the codebase
rg "CEMETERY_USER_TYPE" --type ts

Length of output: 474

libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts (1)

139-142: LGTM! Good separation of concerns.

The new private method properly encapsulates the value preparation logic with appropriate TypeScript types.

libs/application/templates/inao/financial-statement-cemetery/src/lib/financialStatementCemeteryTemplate.ts (2)

4-4: LGTM: Import changes are well-structured

The new imports are properly organized and support tree-shaking by importing specific utilities.

Also applies to: 28-28


53-56: LGTM: Template API configuration is properly structured

The onEntry configuration correctly sets up the user type check and persists the data, which is essential for the subsequent role mapping.

libs/application/template-api-modules/src/lib/modules/templates/financial-statement-political-party/financial-statement-political-party.service.ts (2)

36-37: Document the purpose of fake user types.

The fakeUserType appears to be used for testing purposes. Consider adding a comment explaining its purpose and when it should be used.

Let's verify the test usage:

✅ Verification successful

The fakeUserType pattern is consistently used across financial statement templates

The code follows an established pattern used across multiple financial statement templates (cemetery, individual election, political party, etc.) where fakeUserType is used to override the actual user type during testing. This is a standard testing mechanism in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how fake user types are used in tests
# Expected: Find test files using fakeUserType for political party template

rg -A 5 "fakeUserType|fakeData.options" --type ts

Length of output: 12988


92-92: Document and verify the null return behavior.

The change to return null for person IDs is a significant behavioral change that could affect downstream code. This appears to be part of implementing the new user role system for directing users to the "not registered correctly" screen.

Let's verify the handling of null returns:

✅ Verification successful

Null return behavior is properly handled

The code change to return null for person IDs is safe and aligns with the application's role-based access control pattern. From the codebase analysis:

  • The template checks getUserType.data.value and maps it to appropriate roles (APPLICANT or NOTALLOWED)
  • The DelegationCheck component explicitly handles null responses from getUserType
  • Other similar services (Cemetery, Individual Election) follow the same pattern of returning null for invalid user types
  • The null response is used consistently across the application to trigger the "not registered correctly" screen
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how null returns from getUserType are handled
# Expected: Find components that handle the null case appropriately

# Check for getUserType usage
ast-grep --pattern 'getUserType($$$).then($$$)' 

# Check for null handling
rg -A 5 "getUserType.*\b(null|undefined)\b" --type ts

Length of output: 105


Script:

#!/bin/bash
# Let's try a broader search for getUserType usage patterns
rg -A 10 "getUserType" --type ts

# Also search for any references to this service
rg -A 10 "FinancialStatementPoliticalPartyService" --type ts

# Look for components that might handle user type responses
ast-grep --pattern 'if ($_ === null) { $$$ }'

Length of output: 60947

libs/application/templates/inao/financial-statement-cemetery/src/lib/messages.ts (1)

673-684: LGTM! The new messages are well-structured and provide clear user guidance.

The messages follow the established pattern and provide appropriate feedback for users whose national ID is not registered as a cemetery.

.github/CODEOWNERS (2)

237-237: LGTM! The new entry follows the file's conventions.

The entry is properly formatted and positioned with other norda team assignments.


237-237: Consider consolidating financial statements ownership.

The client library is now owned by @island-is/norda, while related components (API domain, templates, template API modules) are owned by @island-is/programm. This split ownership might require additional coordination between teams.

Let's verify all related financial statements components:

✅ Verification successful

Let me gather more information about the ownership patterns to verify this concern.


Split ownership of financial statements components confirmed

The verification confirms the split ownership pattern:

  • Client library (/libs/clients/financial-statements-inao) is owned by @island-is/norda
  • All other components are owned by @island-is/programm:
    • API domain (/libs/api/domains/financial-statements-inao/)
    • Application template (/libs/application/templates/financial-statements-inao/)
    • Template API module (/libs/application/template-api-modules/src/lib/modules/templates/financial-statements-inao)

This split ownership structure could indeed lead to coordination overhead, especially since the client library is tightly coupled with other financial statements components as evidenced by the import statements found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: List all financial statements related paths and their owners
# to help assess the impact of split ownership

echo "Financial statements related paths and their owners:"
rg "financial-statements-inao" --no-filename | sort -u

Length of output: 3322


Script:

#!/bin/bash
# Check CODEOWNERS entries for all financial statements related paths
echo "CODEOWNERS entries for financial statements components:"
rg "/financial-statements" .github/CODEOWNERS

# List all unique paths containing financial-statements-inao
echo -e "\nUnique paths containing financial-statements-inao:"
fd "financial-statements-inao"

Length of output: 1392

libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts (4)

17-17: Approved import of getValueViaPath utility function

The inclusion of getValueViaPath from @island.is/application/core correctly supports the retrieval of nested values from application.externalData.


28-28: Approved import of POLITICALPARTY_USER_TYPE constant

Importing POLITICALPARTY_USER_TYPE ensures consistency and maintainability when comparing user types throughout the application.


89-97: Approved addition of Roles.NOTALLOWED with appropriate form loader

The introduction of the Roles.NOTALLOWED role and the associated notAllowedForm provides clear guidance to users who are not permitted to proceed, improving user experience.


166-169: Approved logic for role assignment in mapUserToRole

The updated logic correctly assigns Roles.APPLICANT or Roles.NOTALLOWED based on the userType, enhancing access control within the application.

Copy link
Member

@norda-gunni norda-gunni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODEOWNERS LGTM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts (2)

86-86: Enhance type safety and error handling.

The method should explicitly define its return type and handle potential errors from isPerson validation.

Consider applying these changes:

-  async getUserType({ auth }: TemplateApiModuleActionProps) {
+  async getUserType({ auth }: TemplateApiModuleActionProps): Promise<number | null> {
     const { nationalId } = auth
+    if (!nationalId) {
+      throw new Error('National ID is required')
+    }
     if (kennitala.isPerson(nationalId)) {
       return null
     } else {
       return this.financialStatementClientService.getUserClientType(nationalId)
     }
   }

111-133: Improve error handling and logging.

While the error handling structure is good, there are opportunities for improvement:

  1. The empty string parameter on line 118 needs explanation or removal
  2. Error messages could be more specific
  3. Logging could include more context

Consider applying these changes:

   try {
     const result =
       await this.financialStatementClientService.postFinancialStatementForCemetery(
         client,
         contacts,
         digitalSignee,
         year,
-        '',
+        '', // TODO: Document why this parameter is empty or remove if not needed
         values,
         fileName,
       )

     if (!result) {
-      throw new Error('Application submission failed')
+      throw new Error('Cemetery financial statement submission failed: No result returned')
     }

     return { success: true }
   } catch (error) {
-    this.logger.error('Error submitting application', error)
+    this.logger.error(
+      `Failed to submit cemetery financial statement for client ${client.nationalId}`,
+      { error, year, hasAttachment: !!fileName }
+    )
     return {
       success: false,
-      message: error.message,
+      message: `Failed to submit financial statement: ${error.message}`,
     }
   }
libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts (2)

89-96: Enhance type safety for the notAllowedForm import

Consider adding type safety to the form import to ensure the imported component matches the expected interface.

-              formLoader: () =>
-                import('../forms/notAllowedForm').then((val) =>
-                  Promise.resolve(val.notAllowedForm),
-                ),
+              formLoader: () =>
+                import('../forms/notAllowedForm').then(
+                  (val): Promise<typeof val.notAllowedForm> =>
+                    Promise.resolve(val.notAllowedForm),
+                ),

Line range hint 36-40: Enhance TypeScript usage with explicit types

Consider adding explicit type definitions for the configuration object and template interface to improve type safety and documentation.

-const configuration =
-  ApplicationConfigurations[
-    ApplicationTypes.FINANCIAL_STATEMENT_POLITICAL_PARTY
-  ]
+const configuration: typeof ApplicationConfigurations[ApplicationTypes.FINANCIAL_STATEMENT_POLITICAL_PARTY] =
+  ApplicationConfigurations[
+    ApplicationTypes.FINANCIAL_STATEMENT_POLITICAL_PARTY
+  ]
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 830a5ae and 224db5b.

📒 Files selected for processing (6)
  • libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts (3 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/financial-statement-political-party/financial-statement-political-party.service.ts (2 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/lib/financialStatementCemeteryTemplate.ts (5 hunks)
  • libs/application/templates/inao/financial-statement-cemetery/src/utils/constants.ts (1 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts (5 hunks)
  • libs/application/templates/inao/financial-statement-political-party/src/utils/constants.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • libs/application/template-api-modules/src/lib/modules/templates/financial-statement-political-party/financial-statement-political-party.service.ts
  • libs/application/templates/inao/financial-statement-cemetery/src/lib/financialStatementCemeteryTemplate.ts
  • libs/application/templates/inao/financial-statement-cemetery/src/utils/constants.ts
  • libs/application/templates/inao/financial-statement-political-party/src/utils/constants.ts
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (2)
libs/application/template-api-modules/src/lib/modules/templates/financial-statement-cemetery/financial-statement-cemetery.service.ts (1)

137-140: LGTM! Well-structured method.

The new private method follows good practices with proper TypeScript usage and clear single responsibility.

libs/application/templates/inao/financial-statement-political-party/src/lib/financialStatementPoliticalPartyTemplate.ts (1)

55-58: Add error handling for the getUserType API action

The API action is correctly defined, but there's no visible error handling strategy. Consider adding error handling to gracefully handle API failures.

@jonnigs jonnigs added the deploy-feature Deploys features to dev label Nov 20, 2024
Copy link
Member

@FridrikMProgramm FridrikMProgramm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Bara ein pæling í kringum code-owner

.github/CODEOWNERS Show resolved Hide resolved
@jonnigs jonnigs added the automerge Merge this PR as soon as all checks pass label Nov 22, 2024
@kodiakhq kodiakhq bot merged commit 20768c5 into main Nov 22, 2024
52 checks passed
@kodiakhq kodiakhq bot deleted the chore/inao-cem-procure-and-dataverse branch November 22, 2024 14:39
jonnigs added a commit that referenced this pull request Nov 26, 2024
…ts (#16958)

* feat: add in the dataverse check before you enter the application

* feat: adjust cemetery client

* chore: remove console.dir

* chore: remove unused imports

* chore: remove console.log

* chore: remove unused imports

* chore: change codeowners of inao client

* fix: remove delegation check once you are in the application

* chore: remove fakeUser, not used any more

* chore: add documentation

* chore: edit not allowed permissions

* feat: change financial-statements codeowner to Norda by Programm request

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass deploy-feature Deploys features to dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants