Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
refactor UserFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Apr 2, 2024
1 parent da7fadc commit a6673d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,11 @@

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;
public interface UserFilter {

@Component
public class UserFilter {

public void userPermissionAndDocumentVersionCheck(DefaultDocument document, String userEmail, Integer requestVersion) {
userPermissionCheck(document, userEmail);
if (!Objects.equals(document.getVersion(), requestVersion)) {
throw VersionMismatchException.EXCEPTION;
}
}

public void userPermissionCheck(DefaultDocument document, String userEmail) {
if (document.getEditor().hasEditPermission(userEmail)) {
throw NoEditPermissionUserException.EXCEPTION;
}
}

public void checkUserAndDocument(User user, DefaultDocument document, Integer version) {
userPermissionAndDocumentVersionCheck(document, user.getEmail(), version);
}
void userPermissionAndDocumentVersionCheck(DefaultDocument document, String userEmail, Integer requestVersion);
void userPermissionCheck(DefaultDocument document, String userEmail);
void checkUserAndDocument(User user, DefaultDocument document, Integer version);

}
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);
}

}

0 comments on commit a6673d1

Please sign in to comment.