[Feat] 문서 권한 확인 API - #28
Conversation
…TO 추가 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mission 서비스 + 컨트롤러) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…/DEPT/복수source/denied/예외) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthrough문서별 현재 사용자 권한 확인 기능을 추가했습니다. 권한 요약 응답과 출처 열거형을 정의하고, 다섯 가지 권한 경로를 계산하는 서비스를 구현했으며, 이를 조회하는 GET 엔드포인트와 단위 테스트를 추가했습니다. Changes문서 권한 확인
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 (2)
src/main/java/com/opensource/docgrid/domain/permission/dto/response/DocumentPermissionSummaryResponse.java (1)
10-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDTO 컬렉션 필드의 완전한 불변성 보장
레코드(record)를 활용한 깔끔한 DTO 설계입니다! 🎉 다만, 주입받는
sources필드가 가변 리스트(ArrayList)일 수 있어 레코드 외부에서 내부 컬렉션 요소가 임의로 변경될 위험이 있습니다. 컴팩트 생성자를 추가하여 리스트를 불변 객체로 방어적 복사하면 외부 변경에 흔들리지 않는 견고한 불변 객체를 완성할 수 있어요! ✨As per path instructions,
**/dto/**/*.java파일의 "불변성 - Getter/Setter 남용을 지양하고 고정된 데이터 구조(Java Record 활용 등)로 설계되었는지 확인" 지침을 고려한 제안입니다.♻️ 불변 리스트 보장을 위한 생성자 추가
public record DocumentPermissionSummaryResponse( `@Schema`(description = "문서 ID") Long documentId, `@Schema`(description = "읽기 권한") boolean canRead, `@Schema`(description = "쓰기 권한") boolean canWrite, `@Schema`(description = "관리 권한") boolean canAdmin, `@Schema`(description = "권한 부여 경로 (OWNER/PUBLIC/USER_CACHE/ROLE/DEPARTMENT)") List<PermissionSourceType> sources ) { + public DocumentPermissionSummaryResponse { + sources = (sources != null) ? java.util.List.copyOf(sources) : java.util.List.of(); + } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/opensource/docgrid/domain/permission/dto/response/DocumentPermissionSummaryResponse.java` around lines 10 - 17, Update the DocumentPermissionSummaryResponse record with a compact constructor that defensively copies sources into an unmodifiable list, preserving the existing field values and allowing the collection to be safely exposed without external mutation.Source: Path instructions
src/main/java/com/opensource/docgrid/domain/permission/service/query/PermissionQueryService.java (1)
182-247: 🚀 Performance & Scalability | 🔵 TrivialN개의 권한 검사로 인한 다중 DB 쿼리 최적화 제안
권한 확인 로직이 각 출처별로 아주 꼼꼼하게 잘 구현되었네요! 🚀 하지만 현재 방식은 단계별로 읽기/쓰기/관리 권한을 개별 쿼리(
exists...)로 검사하기 때문에, 모든 단계를 거칠 경우 최대 15번의 카운트 쿼리가 발생할 수 있습니다. 당장은 문제없더라도 추후 트래픽이 증가하면 DB 병목 원인이 될 수 있으니, 사용자 ID와 문서 ID를 기반으로 해당 권한 플래그 묶음을 한 번의 쿼리로 가져오도록 Repository 단을 최적화하는 방안을 추후 고려해 보세요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/opensource/docgrid/domain/permission/service/query/PermissionQueryService.java` around lines 182 - 247, Optimize checkDocumentPermission by replacing the separate per-permission exists... calls across document and collection repositories with repository methods that fetch the user/document read, write, and admin flags in a single query per permission source. Preserve the existing OWNER, PUBLIC, USER_CACHE, ROLE, DEPARTMENT, source collection, and response behavior while reducing the maximum number of database queries.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@src/main/java/com/opensource/docgrid/domain/permission/dto/response/DocumentPermissionSummaryResponse.java`:
- Around line 10-17: Update the DocumentPermissionSummaryResponse record with a
compact constructor that defensively copies sources into an unmodifiable list,
preserving the existing field values and allowing the collection to be safely
exposed without external mutation.
In
`@src/main/java/com/opensource/docgrid/domain/permission/service/query/PermissionQueryService.java`:
- Around line 182-247: Optimize checkDocumentPermission by replacing the
separate per-permission exists... calls across document and collection
repositories with repository methods that fetch the user/document read, write,
and admin flags in a single query per permission source. Preserve the existing
OWNER, PUBLIC, USER_CACHE, ROLE, DEPARTMENT, source collection, and response
behavior while reducing the maximum number of database queries.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d6318160-438d-4eac-9d17-61478cac5ff2
📒 Files selected for processing (5)
src/main/java/com/opensource/docgrid/domain/permission/controller/PermissionController.javasrc/main/java/com/opensource/docgrid/domain/permission/dto/response/DocumentPermissionSummaryResponse.javasrc/main/java/com/opensource/docgrid/domain/permission/enums/PermissionSourceType.javasrc/main/java/com/opensource/docgrid/domain/permission/service/query/PermissionQueryService.javasrc/test/java/com/opensource/docgrid/domain/permission/service/query/PermissionQueryServiceTest.java
🔍️ 작업 내용
✨ 상세 설명
이슈 3에서 만든
PermissionQueryService의 5단계 판단 로직을 외부 API로 처음 노출합니다.현재 로그인한 사용자가 특정 문서에 대해 읽기·쓰기·관리 권한을 가지고 있는지, 그리고 그 권한이 어떤 경로(
OWNER / PUBLIC / USER_CACHE / ROLE / DEPARTMENT)로 부여됐는지 한 번에 확인할 수 있습니다.설계 결정 — 기존 boolean 메서드는 수정하지 않음
canReadDocument등 기존 3개 메서드는 CommandService들이 이미 사용 중이므로 반환 타입 변경 없이,checkDocumentPermission()단일 메서드를 신규 추가하는 방식으로 구현했습니다. 이 메서드 안에서 문서 조회를 1회만 수행하고 read/write/admin 판단과 sources 수집을 한 번에 처리합니다.응답 예시
{ "documentId": 10, "canRead": true, "canWrite": true, "canAdmin": false, "sources": ["USER_CACHE", "ROLE"] }🛠 추후 리팩토링 및 고도화 계획
GET /collections,DELETE /collections/{id}등) 구현 후 Swagger 전체 흐름 테스트 예정📸 스크린샷 (선택)
💬 리뷰 요구사항
checkDocumentPermission최악의 경우 쿼리 15회 발생 (캐시 3 + ROLE 6 + DEPT 6) — UI에서 1회성 호출 용도이므로 허용 범위로 판단했는데 의견 부탁드립니다.Summary by CodeRabbit
새로운 기능
테스트