Skip to content

legal information - #161

Merged
nk-coding merged 1 commit into
mainfrom
feature/legal_information
Sep 22, 2025
Merged

legal information#161
nk-coding merged 1 commit into
mainfrom
feature/legal_information

Conversation

@nk-coding

@nk-coding nk-coding commented Sep 21, 2025

Copy link
Copy Markdown
Contributor
  • adds a new LegalInformation entity which can be used for stuff like GDPR

Summary by CodeRabbit

  • New Features
    • Added Legal Information items that can be shown to end users, with a label and markdown text.
    • Supports priority-based ordering (higher priority appears further left) and searchability.
    • Provides API endpoints (GraphQL mutations) to create, update, and delete Legal Information; restricted to admins.

@nk-coding
nk-coding requested a review from spethso September 21, 2025 15:14
@nk-coding nk-coding self-assigned this Sep 21, 2025
@coderabbitai

coderabbitai Bot commented Sep 21, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds LegalInformation CRUD support: a domain model, repository, service with admin-guarded operations, GraphQL mutations (create, update, delete), and input DTOs with validation. Mutations pass authorization context to the service and return entity or delete payload.

Changes

Cohort / File(s) Summary of changes
GraphQL Mutations
api-public/src/main/kotlin/gropius/schema/mutation/MiscMutations.kt
New Spring GraphQL component exposing createLegalInformation, updateLegalInformation, deleteLegalInformation; uses AutoPayloadType, transaction REQUIRES_NEW, passes gropiusAuthorizationContext to service and returns entity/delete payload.
Input DTOs
core/src/main/kotlin/gropius/dto/input/misc/CreateLegalInformationInput.kt, core/src/main/kotlin/gropius/dto/input/misc/UpdateLegalInformationInput.kt
New input types. Create: label, text, priority with non-blank validation for label/text. Update: OptionalInput fields (label, text, priority) with non-blank validation when provided.
Domain Model
core/src/main/kotlin/gropius/model/misc/LegalInformation.kt
New Node entity with label, text, priority; annotated for GraphQL, search properties, order property, and read authorization.
Repository
core/src/main/kotlin/gropius/repository/misc/LegalInformationRepository.kt
New Spring Data repository extending GropiusRepository for LegalInformation.
Service Layer
core/src/main/kotlin/gropius/service/misc/LegalInformationService.kt
New service implementing admin-guarded create, update, delete; validates inputs, loads/saves via repository, applies optional updates, uses coroutine-suspend functions.

Sequence Diagram(s)

sequenceDiagram
  actor Client
  participant GraphQL as MiscMutations (GraphQL)
  participant Service as LegalInformationService
  participant Repo as LegalInformationRepository

  rect rgba(200,235,255,0.3)
  note over Client,Repo: Create flow
  Client->>GraphQL: createLegalInformation(input)
  GraphQL->>Service: createLegalInformation(authCtx, input)
  Service->>Service: validate + assertAdmin
  Service->>Repo: save(new LegalInformation)
  Repo-->>Service: saved entity
  Service-->>GraphQL: LegalInformation
  GraphQL-->>Client: LegalInformation
  end

  rect rgba(220,255,220,0.3)
  note over Client,Repo: Update flow
  Client->>GraphQL: updateLegalInformation(input)
  GraphQL->>Service: updateLegalInformation(authCtx, input)
  Service->>Service: validate + assertAdmin
  Service->>Repo: findById(input.id)
  Repo-->>Service: entity
  Service->>Service: apply optional fields
  Service->>Repo: save(entity)
  Repo-->>Service: updated entity
  Service-->>GraphQL: LegalInformation
  GraphQL-->>Client: LegalInformation
  end

  rect rgba(255,230,230,0.4)
  note over Client,Repo: Delete flow
  Client->>GraphQL: deleteLegalInformation(input)
  GraphQL->>Service: deleteLegalInformation(authCtx, input)
  Service->>Service: validate + assertAdmin
  Service->>Repo: findById(input.id)
  Repo-->>Service: entity
  Service->>Repo: delete(entity)
  Service-->>GraphQL: DeleteNodePayload(id)
  GraphQL-->>Client: DeleteNodePayload
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I thump my paws—new laws appear,
With label, text, and priorities clear.
I hop through CRUD with admin keys,
Save, update, delete—such breeze!
In fields of GraphQL I cheer:
“Legal carrots, now right here!” 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "legal information" directly reflects the primary change in the PR — adding a LegalInformation domain entity and its inputs, repository, service, and GraphQL mutations, so it is concise and clearly related to the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/legal_information

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (10)
core/src/main/kotlin/gropius/dto/input/misc/CreateLegalInformationInput.kt (2)

8-13: Ensure GraphQL descriptions attach to properties (use @Property target).

Without the property target, descriptions may not appear in the schema for Kotlin primary‑ctor properties.

Apply:

-    @GraphQLDescription("Initial label of the LegalInformation")
+    @property:GraphQLDescription("Initial label of the LegalInformation")
     val label : String,
-    @GraphQLDescription("Initial text of the LegalInformation")
+    @property:GraphQLDescription("Initial text of the LegalInformation")
     val text : String,
-    @GraphQLDescription("Initial priority of the LegalInformation")
+    @property:GraphQLDescription("Initial priority of the LegalInformation")
     val priority : Int

16-24: Validate non‑negative priority.

Prevents odd ordering and accidental negative values.

     override fun validate() {
         super.validate()
         if (label.isBlank()) {
             throw IllegalArgumentException("Label must not be blank")
         }
         if (text.isBlank()) {
             throw IllegalArgumentException("Text must not be blank")
         }
+        if (priority < 0) {
+            throw IllegalArgumentException("Priority must not be negative")
+        }
     }
core/src/main/kotlin/gropius/dto/input/misc/UpdateLegalInformationInput.kt (2)

10-15: Use @Property:GraphQLDescription for Kotlin ctor properties.

Ensures field docs surface in the GraphQL schema.

-    @GraphQLDescription("The new label of the LegalInformation")
+    @property:GraphQLDescription("The new label of the LegalInformation")
     val label : OptionalInput<String>,
-    @GraphQLDescription("The new text of the LegalInformation")
+    @property:GraphQLDescription("The new text of the LegalInformation")
     val text: OptionalInput<String>,
-    @GraphQLDescription("The new priority of the LegalInformation")
+    @property:GraphQLDescription("The new priority of the LegalInformation")
     val priority: OptionalInput<Int>

18-30: Validate non‑negative priority when provided.

Guards updates that would break ordering semantics.

         text.ifPresent {
             if (it.isBlank()) {
                 throw IllegalArgumentException("Text must not be blank")
             }
         }
+        priority.ifPresent {
+            if (it < 0) {
+                throw IllegalArgumentException("Priority must not be negative")
+            }
+        }
core/src/main/kotlin/gropius/service/misc/LegalInformationService.kt (4)

37-41: Check authorization before validating input.

Avoids work and leaking validation errors to unauthorized callers.

-        input.validate()
-        checkIsAdmin(authorizationContext, "create LegalInformation")
+        checkIsAdmin(authorizationContext, "create LegalInformation")
+        input.validate()
         val legalInformation = LegalInformation(input.label, input.text, input.priority)
         return repository.save(legalInformation).awaitSingle()

39-41: Trim label on create.

Prevents labels consisting of leading/trailing whitespace.

-        val legalInformation = LegalInformation(input.label, input.text, input.priority)
+        val legalInformation = LegalInformation(input.label.trim(), input.text, input.priority)

54-67: Check authorization before validating input and trim label on update.

Minor ordering improvement plus normalization.

-        input.validate()
-        checkIsAdmin(authorizationContext, "update LegalInformation")
+        checkIsAdmin(authorizationContext, "update LegalInformation")
+        input.validate()
         val legalInformation = repository.findById(input.id)
         input.label.ifPresent {
-            legalInformation.label = it
+            legalInformation.label = it.trim()
         }
         input.text.ifPresent {
             legalInformation.text = it
         }
         input.priority.ifPresent {
             legalInformation.priority = it
         }

69-83: Consider auditing create/update/delete.

Given legal/compliance scope, emit structured audit events (who, when, what changed, old/new values) for these operations.

core/src/main/kotlin/gropius/model/misc/LegalInformation.kt (2)

18-20: Untrusted Markdown: ensure safe rendering downstream.

Text will likely be rendered as HTML; the UI must sanitize to prevent XSS.


21-23: Ordering by priority may benefit from an index.

If lists grow, add/verify a DB index on priority (and any sort combination you use).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ed9706 and 326f371.

📒 Files selected for processing (6)
  • api-public/src/main/kotlin/gropius/schema/mutation/MiscMutations.kt (1 hunks)
  • core/src/main/kotlin/gropius/dto/input/misc/CreateLegalInformationInput.kt (1 hunks)
  • core/src/main/kotlin/gropius/dto/input/misc/UpdateLegalInformationInput.kt (1 hunks)
  • core/src/main/kotlin/gropius/model/misc/LegalInformation.kt (1 hunks)
  • core/src/main/kotlin/gropius/repository/misc/LegalInformationRepository.kt (1 hunks)
  • core/src/main/kotlin/gropius/service/misc/LegalInformationService.kt (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
core/src/main/kotlin/gropius/service/misc/LegalInformationService.kt (1)
core/src/main/kotlin/gropius/service/common/NodeService.kt (1)
  • checkIsAdmin (57-61)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (3)
core/src/main/kotlin/gropius/repository/misc/LegalInformationRepository.kt (1)

7-11: LGTM.

Repository wiring matches existing patterns and enables CRUD.

api-public/src/main/kotlin/gropius/schema/mutation/MiscMutations.kt (2)

27-52: LGTM: mutations delegate and enforce admin via service.

Descriptions and payloads are consistent with existing patterns.


21-23: Confirm reactive transaction semantics with coroutines and REQUIRES_NEW.

Ensure a reactive transaction manager is configured and this boundary matches expectations.

@nk-coding
nk-coding requested a review from chriku September 21, 2025 17:21

@chriku chriku left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code is okay, but the artificial bunny PR comments suck

@nk-coding
nk-coding merged commit d6f82df into main Sep 22, 2025
2 checks passed
@nk-coding
nk-coding deleted the feature/legal_information branch September 22, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants