-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] PermissionQueryService 구현 - 문서 접근 권한 5단계 판단 로직 #23
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7cbc7ed
feat: 권한 판단용 Repository 쿼리 추가 (캐시/ROLE/DEPT live)
kangcheolung ea38ceb
feat: PermissionQueryService 구현 (문서 5단계 판단 + 컬렉션 권한)
kangcheolung 4f76c12
refactor: owner 직접 비교 → PermissionQueryService 호출로 교체
kangcheolung c78ab1a
test: PermissionQueryService 단위 테스트 추가 및 기존 테스트 수정
kangcheolung 1fdd06b
Merge branch 'develop' of https://github.com/DocGrid/backend into ref…
kangcheolung be6cea2
refactor: CodeRabbit 리뷰 반영 — 주석 오류·타이밍 로그·컬렉션 권한 ROLE/DEPT 체크 추가
kangcheolung 674059c
test: PermissionQueryService 누락 테스트 추가 (canWriteDocument·canAdminDocu…
kangcheolung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...a/com/opensource/docgrid/domain/permission/repository/CollectionPermissionRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,110 @@ | ||
| package com.opensource.docgrid.domain.permission.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import com.opensource.docgrid.domain.permission.entity.CollectionPermission; | ||
|
|
||
| public interface CollectionPermissionRepository extends JpaRepository<CollectionPermission, Long> { | ||
|
|
||
| // ROLE live — 사용자 역할 기반 컬렉션→문서 읽기 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(cp) > 0 FROM CollectionPermission cp | ||
| JOIN CollectionDocument cd ON cd.collection = cp.collection | ||
| JOIN UserRole ur ON ur.role = cp.role | ||
| WHERE cd.document.id = :documentId | ||
| AND cp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.ROLE | ||
| AND ur.user.id = :userId | ||
| AND cp.canRead = true | ||
| AND (cp.expiresAt IS NULL OR cp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsRoleReadPermissionForDocument(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // ROLE live — 사용자 역할 기반 컬렉션→문서 쓰기 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(cp) > 0 FROM CollectionPermission cp | ||
| JOIN CollectionDocument cd ON cd.collection = cp.collection | ||
| JOIN UserRole ur ON ur.role = cp.role | ||
| WHERE cd.document.id = :documentId | ||
| AND cp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.ROLE | ||
| AND ur.user.id = :userId | ||
| AND cp.canWrite = true | ||
| AND (cp.expiresAt IS NULL OR cp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsRoleWritePermissionForDocument(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // ROLE live — 사용자 역할 기반 컬렉션→문서 관리 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(cp) > 0 FROM CollectionPermission cp | ||
| JOIN CollectionDocument cd ON cd.collection = cp.collection | ||
| JOIN UserRole ur ON ur.role = cp.role | ||
| WHERE cd.document.id = :documentId | ||
| AND cp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.ROLE | ||
| AND ur.user.id = :userId | ||
| AND cp.canAdmin = true | ||
| AND (cp.expiresAt IS NULL OR cp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsRoleAdminPermissionForDocument(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // DEPARTMENT live — 사용자 부서 기반 컬렉션→문서 읽기 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(cp) > 0 FROM CollectionPermission cp | ||
| JOIN CollectionDocument cd ON cd.collection = cp.collection | ||
| JOIN User u ON u.department = cp.department | ||
| WHERE cd.document.id = :documentId | ||
| AND cp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.DEPARTMENT | ||
| AND u.id = :userId | ||
| AND cp.canRead = true | ||
| AND (cp.expiresAt IS NULL OR cp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsDeptReadPermissionForDocument(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // DEPARTMENT live — 사용자 부서 기반 컬렉션→문서 쓰기 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(cp) > 0 FROM CollectionPermission cp | ||
| JOIN CollectionDocument cd ON cd.collection = cp.collection | ||
| JOIN User u ON u.department = cp.department | ||
| WHERE cd.document.id = :documentId | ||
| AND cp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.DEPARTMENT | ||
| AND u.id = :userId | ||
| AND cp.canWrite = true | ||
| AND (cp.expiresAt IS NULL OR cp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsDeptWritePermissionForDocument(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // DEPARTMENT live — 사용자 부서 기반 컬렉션→문서 관리 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(cp) > 0 FROM CollectionPermission cp | ||
| JOIN CollectionDocument cd ON cd.collection = cp.collection | ||
| JOIN User u ON u.department = cp.department | ||
| WHERE cd.document.id = :documentId | ||
| AND cp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.DEPARTMENT | ||
| AND u.id = :userId | ||
| AND cp.canAdmin = true | ||
| AND (cp.expiresAt IS NULL OR cp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsDeptAdminPermissionForDocument(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // USER 직접 권한 — 컬렉션에 쓰기 권한이 있는지 (canAdminCollection 판단용) | ||
| @Query(""" | ||
| SELECT COUNT(cp) > 0 FROM CollectionPermission cp | ||
| WHERE cp.collection.id = :collectionId | ||
| AND cp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.USER | ||
| AND cp.user.id = :userId | ||
| AND cp.canWrite = true | ||
| AND (cp.expiresAt IS NULL OR cp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsUserWritePermission(@Param("userId") Long userId, @Param("collectionId") Long collectionId); | ||
|
|
||
| // USER 직접 권한 — 컬렉션에 관리 권한이 있는지 (canAdminCollection 판단용) | ||
| @Query(""" | ||
| SELECT COUNT(cp) > 0 FROM CollectionPermission cp | ||
| WHERE cp.collection.id = :collectionId | ||
| AND cp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.USER | ||
| AND cp.user.id = :userId | ||
| AND cp.canAdmin = true | ||
| AND (cp.expiresAt IS NULL OR cp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsUserAdminPermission(@Param("userId") Long userId, @Param("collectionId") Long collectionId); | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
...ava/com/opensource/docgrid/domain/permission/repository/DocumentPermissionRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,82 @@ | ||
| package com.opensource.docgrid.domain.permission.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import com.opensource.docgrid.domain.permission.entity.DocumentPermission; | ||
|
|
||
| public interface DocumentPermissionRepository extends JpaRepository<DocumentPermission, Long> { | ||
|
|
||
| // ROLE live — 사용자 역할 기반 문서 읽기 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(dp) > 0 FROM DocumentPermission dp | ||
| JOIN UserRole ur ON ur.role = dp.role | ||
| WHERE dp.document.id = :documentId | ||
| AND dp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.ROLE | ||
| AND ur.user.id = :userId | ||
| AND dp.canRead = true | ||
| AND (dp.expiresAt IS NULL OR dp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsRoleReadPermission(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // ROLE live — 사용자 역할 기반 문서 쓰기 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(dp) > 0 FROM DocumentPermission dp | ||
| JOIN UserRole ur ON ur.role = dp.role | ||
| WHERE dp.document.id = :documentId | ||
| AND dp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.ROLE | ||
| AND ur.user.id = :userId | ||
| AND dp.canWrite = true | ||
| AND (dp.expiresAt IS NULL OR dp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsRoleWritePermission(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // ROLE live — 사용자 역할 기반 문서 관리 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(dp) > 0 FROM DocumentPermission dp | ||
| JOIN UserRole ur ON ur.role = dp.role | ||
| WHERE dp.document.id = :documentId | ||
| AND dp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.ROLE | ||
| AND ur.user.id = :userId | ||
| AND dp.canAdmin = true | ||
| AND (dp.expiresAt IS NULL OR dp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsRoleAdminPermission(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // DEPARTMENT live — 사용자 부서 기반 문서 읽기 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(dp) > 0 FROM DocumentPermission dp | ||
| JOIN User u ON u.department = dp.department | ||
| WHERE dp.document.id = :documentId | ||
| AND dp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.DEPARTMENT | ||
| AND u.id = :userId | ||
| AND dp.canRead = true | ||
| AND (dp.expiresAt IS NULL OR dp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsDeptReadPermission(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // DEPARTMENT live — 사용자 부서 기반 문서 쓰기 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(dp) > 0 FROM DocumentPermission dp | ||
| JOIN User u ON u.department = dp.department | ||
| WHERE dp.document.id = :documentId | ||
| AND dp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.DEPARTMENT | ||
| AND u.id = :userId | ||
| AND dp.canWrite = true | ||
| AND (dp.expiresAt IS NULL OR dp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsDeptWritePermission(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
|
|
||
| // DEPARTMENT live — 사용자 부서 기반 문서 관리 권한 존재 여부 | ||
| @Query(""" | ||
| SELECT COUNT(dp) > 0 FROM DocumentPermission dp | ||
| JOIN User u ON u.department = dp.department | ||
| WHERE dp.document.id = :documentId | ||
| AND dp.targetType = com.opensource.docgrid.domain.permission.enums.PermissionTargetType.DEPARTMENT | ||
| AND u.id = :userId | ||
| AND dp.canAdmin = true | ||
| AND (dp.expiresAt IS NULL OR dp.expiresAt > CURRENT_TIMESTAMP) | ||
| """) | ||
| boolean existsDeptAdminPermission(@Param("userId") Long userId, @Param("documentId") Long documentId); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.