Feat/owner create case och attachemnts#234
Conversation
…medical-record mutations
…and closed case restrictions
…te rules test: update MedicalRecordPolicyTest to refine OWNER update logic for own records only
📝 WalkthroughWalkthroughAuthorization logic is refactored to allow VET users to upload attachments across clinics when records are open, and OWNER users to update their own records. Security configuration URL matchers are narrowed to delegate OWNER updates to policy-level authorization checks rather than URL-level filters. Test coverage is expanded with a new comprehensive attachment policy test suite and updated record update tests. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/test/java/org/example/vet1177/policy/AttachmentPolicyTest.java (1)
177-188: Nit: inconsistent exception handling — preferthrows Exceptionlike the rest of the class.Every other test in this file declares
throws Exceptionand callssetPrivateFielddirectly. Wrapping it here in atry/catchthat rethrows asRuntimeExceptionis just noise.♻️ Suggested cleanup
- `@Test` - void canDelete_vetSameClinicOthersUpload_shouldThrowForbidden() { - User otherVet = new User("Dr. Annan Klinik", "ak@vet.se", "hash", Role.VET, clinic); - try { - setPrivateField(otherVet, "id", UUID.randomUUID()); - } catch (Exception e) { - throw new RuntimeException(e); - } + `@Test` + void canDelete_vetSameClinicOthersUpload_shouldThrowForbidden() throws Exception { + User otherVet = new User("Dr. Annan Klinik", "ak@vet.se", "hash", Role.VET, clinic); + setPrivateField(otherVet, "id", UUID.randomUUID()); assertThatThrownBy(() -> policy.canDelete(otherVet, attachmentUploadedByVet)) .isInstanceOf(ForbiddenException.class); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/vet1177/policy/AttachmentPolicyTest.java` around lines 177 - 188, The test AttachmentPolicyTest::canDelete_vetSameClinicOthersUpload_shouldThrowForbidden currently wraps setPrivateField in a try/catch and rethrows RuntimeException; change the method signature to declare throws Exception (like other tests) and call setPrivateField(otherVet, "id", UUID.randomUUID()) directly, removing the try/catch, so the test compiles and follows the same exception-handling style used across the class when preparing otherVet and attachmentUploadedByVet before invoking policy.canDelete.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/test/java/org/example/vet1177/policy/AttachmentPolicyTest.java`:
- Around line 177-188: The test
AttachmentPolicyTest::canDelete_vetSameClinicOthersUpload_shouldThrowForbidden
currently wraps setPrivateField in a try/catch and rethrows RuntimeException;
change the method signature to declare throws Exception (like other tests) and
call setPrivateField(otherVet, "id", UUID.randomUUID()) directly, removing the
try/catch, so the test compiles and follows the same exception-handling style
used across the class when preparing otherVet and attachmentUploadedByVet before
invoking policy.canDelete.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dc5bb558-6f13-4c1c-b24f-c3fcb07e6fc0
📒 Files selected for processing (5)
src/main/java/org/example/vet1177/policy/AttachmentPolicy.javasrc/main/java/org/example/vet1177/policy/MedicalRecordPolicy.javasrc/main/java/org/example/vet1177/security/SecurityConfig.javasrc/test/java/org/example/vet1177/policy/AttachmentPolicyTest.javasrc/test/java/org/example/vet1177/policy/MedicalRecordPolicyTest.java
|
Ser bra ut, samma logik som jag har tänkt kring detta. |
Öppnar upp AttachmentPolicy.canUpload så att VET alltid kan bifoga filer, oavsett kliniktillhörighet — t.ex. i remiss- och konsultflöden där remitterande
veterinär behöver komplettera ett ärende på en annan klinik. Samtidigt spärras VET på CLOSED-ärenden (samma regel som för OWNER) så att stängda journaler
förblir oförändrade.
Beteende
┌────────────────────┬──────────────┬───────────────┐
│ Roll │ Öppet ärende │ Stängt ärende │
├────────────────────┼──────────────┼───────────────┤
│ ADMIN │ ✅ │ ✅ │
├────────────────────┼──────────────┼───────────────┤
│ VET (samma klinik) │ ✅ │ ❌ 403 │ ──
├────────────────────┼──────────────┼───────────────┤
│ VET (annan klinik) │ ✅ (nytt) │ ❌ 403 │
├────────────────────┼──────────────┼───────────────┤
│ VET (ingen klinik) │ ✅ (nytt) │ ❌ 403 │
├────────────────────┼──────────────┼───────────────┤
│ OWNER (eget) │ ✅ │ ❌ 403 │
├────────────────────┼──────────────┼───────────────┤
│ OWNER (annans) │ ❌ 403 │ ❌ 403 │
└────────────────────┴──────────────┴───────────────┘
Ändringar
AttachmentPolicy.canUpload
Oförändrat
Tester
AttachmentPolicyTest
Test plan
Summary by CodeRabbit
New Features
Bug Fixes