This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
34 changes: 34 additions & 0 deletions
34
daemawiki-service/src/main/java/org/daemawiki/domain/common/UserFilterImpl.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.daemawiki.domain.common; | ||
|
||
import org.daemawiki.domain.document.model.DefaultDocument; | ||
import org.daemawiki.domain.user.model.User; | ||
import org.daemawiki.exception.h400.VersionMismatchException; | ||
import org.daemawiki.exception.h403.NoEditPermissionUserException; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Objects; | ||
|
||
@Component | ||
public class UserFilterImpl implements UserFilter { | ||
|
||
@Override | ||
public void userPermissionAndDocumentVersionCheck(DefaultDocument document, String userEmail, Integer requestVersion) { | ||
userPermissionCheck(document, userEmail); | ||
if (!Objects.equals(document.getVersion(), requestVersion)) { | ||
throw VersionMismatchException.EXCEPTION; | ||
} | ||
} | ||
|
||
@Override | ||
public void userPermissionCheck(DefaultDocument document, String userEmail) { | ||
if (document.getEditor().hasEditPermission(userEmail)) { | ||
throw NoEditPermissionUserException.EXCEPTION; | ||
} | ||
} | ||
|
||
@Override | ||
public void checkUserAndDocument(User user, DefaultDocument document, Integer version) { | ||
userPermissionAndDocumentVersionCheck(document, user.getEmail(), version); | ||
} | ||
|
||
} |