Skip to content
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

#520 [feat] 인가체제 변경 #523

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ public SuccessResponse<MoimPublicStatusResponse> getPublicStatusOfMoim(

@Override
@DeleteMapping("/{moimId}")
@UserAuthAnnotation(UserAuthenticationType.OWNER)
public ResponseEntity<SuccessResponse> deleteMoim(
@MoimIdPathVariable final Long moimId,
@UserId final Long userId,
@PathVariable("moimId") final String moimUrl
) {
moimService.deleteMoim(moimId, userId);
moimService.deleteMoim(moimId);
return ResponseEntity.ok(SuccessResponse.of(SuccessMessage.MOIM_DELETE_SUCCESS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ SuccessResponse getPublicStatusOfMoim(
)
ResponseEntity<SuccessResponse> deleteMoim(
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) final Long moimId,
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) @UserId final Long userId,
@PathVariable("moimId") final String moimUrl
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ public ResponseEntity<SuccessResponse> putPost(

@DeleteMapping("/{postId}")
@Override
@UserAuthAnnotation(UserAuthenticationType.WRITER_NAME)
public ResponseEntity<SuccessResponse> deletePost(
@PostIdPathVariable final Long postId,
@UserId final Long userId,
@PathVariable("postId") final String postUrl
) {
postService.deletePost(postId, userId);
postService.deletePost(postId, WriterNameContextUtil.getMoimWriterNameMapContext());
return ResponseEntity.status(HttpStatus.OK).body(SuccessResponse.of(SuccessMessage.POST_DELETE_SUCCESS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ ResponseEntity<SuccessResponse> deleteTemporaryPost(
)
ResponseEntity<SuccessResponse> deletePost(
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) final Long postId,
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) @UserId final Long userId,
@PathVariable("postId") final String postUrl
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mile.controller.topic;

import com.mile.common.auth.annotation.UserAuthAnnotation;
import com.mile.common.auth.annotation.UserAuthenticationType;
import com.mile.common.resolver.user.UserId;
import com.mile.dto.SuccessResponse;
import com.mile.exception.message.SuccessMessage;
Expand Down Expand Up @@ -49,23 +51,24 @@ public ResponseEntity<SuccessResponse<TopicDetailResponse>> getTopicDetail(

@Override
@DeleteMapping("/{topicId}")
@UserAuthAnnotation(UserAuthenticationType.OWNER)
public ResponseEntity<SuccessResponse> deleteTopic(
@TopicIdPathVariable final Long topicId,
@UserId final Long userId,
@PathVariable("topicId") final String topicUrl
) {
topicService.deleteTopic(userId, topicId);
topicService.deleteTopic(topicId);
return ResponseEntity.ok(SuccessResponse.of(SuccessMessage.TOPIC_DELETE_SUCCESS));
Comment on lines 52 to 60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2
{topicId}로 요청이 들어올 경우 moimId기반으로 owner인지 확인하는 로직에서 에러가 날 것 같은데 아닌가요!?

}

@PutMapping("/{topicId}")
@UserAuthAnnotation(UserAuthenticationType.OWNER)
public ResponseEntity<SuccessResponse> putTopic(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2
위 리뷰와 동일한 내용입니다!

@RequestBody @Valid final TopicPutRequest topicPutRequest,
@TopicIdPathVariable final Long topicId,
@UserId final Long userId,
@PathVariable("topicId") final String topicUrl
) {
topicService.putTopic(userId, topicId, topicPutRequest);
topicService.putTopic(topicId, topicPutRequest);
return ResponseEntity.ok(SuccessResponse.of(SuccessMessage.TOPIC_PUT_SUCCESS));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ ResponseEntity<SuccessResponse<TopicDetailResponse>> getTopicDetail(
)
ResponseEntity<SuccessResponse> deleteTopic(
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) final Long topicId,
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) @UserId final Long userId,
@PathVariable("topicId") final String topicUrl
);

Expand All @@ -95,7 +94,6 @@ ResponseEntity<SuccessResponse> deleteTopic(
ResponseEntity<SuccessResponse> putTopic(
@RequestBody final TopicPutRequest topicPutRequest,
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) final Long topicId,
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) @UserId final Long userId,
@PathVariable("topicId") final String topicUrl
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mile.controller.writername;

import com.mile.common.auth.annotation.UserAuthAnnotation;
import com.mile.common.auth.annotation.UserAuthenticationType;
import com.mile.common.resolver.user.UserId;
import com.mile.dto.SuccessResponse;
import com.mile.exception.message.SuccessMessage;
Expand All @@ -26,11 +28,11 @@ public class WriterNameController implements WriterNameControllerSwagger {

@Override
@DeleteMapping("/{writerNameId}")
@UserAuthAnnotation(UserAuthenticationType.OWNER)
public ResponseEntity<SuccessResponse> deleteMember(
@PathVariable("writerNameId") final Long writerNameId,
@UserId final Long userId
@PathVariable("writerNameId") final Long writerNameId
) {
writerNameService.deleteWriterNameById(writerNameId, userId);
writerNameService.deleteWriterNameById(writerNameId);
return ResponseEntity.ok(SuccessResponse.of(SuccessMessage.MOIM_MEMBER_DELETE_SUCCESS));
Comment on lines +31 to 36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2
위 리뷰와 동일한 내용입니다!

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public interface WriterNameControllerSwagger {
}
)
ResponseEntity<SuccessResponse> deleteMember(
@PathVariable("writerNameId") final Long writerNameId,
@UserId final Long userId
@PathVariable("writerNameId") final Long writerNameId
);

@Operation(summary = "필명, 소개글 조회")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public boolean isMoimOwnerEqualsUser(
return moim.getOwner().getWriter().getId().equals(userId);
}

public boolean isMoimOwnerEqualsWriterName(
final Moim moim,
final Long writerNameId
) {
return moim.getOwner().getId().equals(writerNameId);
}

public List<Moim> findBestMoims() {
LocalDateTime endOfWeek = LocalDateTime.now();
LocalDateTime startOfWeek = endOfWeek.minusDays(7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public WriterNameInformationResponse getWriterNameOfUser(
return writerNameRetriever.findWriterNameInfo(writerNameId);
}


public WriterNameConflictCheckResponse checkConflictOfWriterName(Long moimId, String writerName) {
if (writerName.length() > WRITER_NAME_MAX_VALUE) {
throw new BadRequestException(ErrorMessage.WRITER_NAME_LENGTH_WRONG);
Expand Down Expand Up @@ -357,12 +358,9 @@ public MoimPublicStatusResponse getPublicStatusOfMoim(
}

public void deleteMoim(
final Long moimId,
final Long userId
final Long moimId
) {

Moim moim = moimRetriever.findById(moimId);
moimRetriever.authenticateOwnerOfMoim(moim, userRetriever.findById(userId));
moimRemover.deleteRelatedData(moim);
writerNameRemover.deleteWriterNamesByMoim(moim);
topicRemover.deleteTopicsByMoim(moim);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,18 @@ public PostAuthenticateResponse getAuthenticateWriter(
@Transactional
public void deletePost(
final Long postId,
final Long userId
final HashMap<Long, WriterNameInfo> moimWriteNameMap
) {
Post post = postRetriever.findById(postId);
Long moimId = post.getTopic().getMoim().getId();
WriterName writerName = writerNameRetriever.findByMoimAndUser(moimId, userId);
if (!postRetriever.isWriterOfPost(post, writerName) && !moimRetriever.isMoimOwnerEqualsUser(post.getTopic().getMoim(), userId)) {
Moim moim = post.getTopic().getMoim();
final Long writerNameId = MoimWriterNameMapUtil.getWriterNameIdMoimWriterNameMap(moim.getId(), moimWriteNameMap);
if (!postRetriever.existsPostByWriterWithPost(postId, writerNameId) && !moimRetriever.isMoimOwnerEqualsWriterName(moim, writerNameId)) {
throw new ForbiddenException(ErrorMessage.WRITER_AUTHENTICATE_ERROR);
}
postRemover.delete(post);
}


@Transactional(readOnly = true)
public TemporaryPostGetResponse getTemporaryPost(
final Long postId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,18 @@ public TopicDetailResponse getTopicDetail(

@Transactional
public void deleteTopic(
final Long userId,
final Long topicId
) {
Topic topic = topicRetriever.findById(topicId);
User user = userService.findById(userId);
topicRetriever.authenticateTopicWithUser(topic, user);
topicRetriever.checkSingleTopicDeletion(topic);
topicRemover.deleteTopic(topic);
}

public void putTopic(
final Long userId,
final Long topicId,
final TopicPutRequest topicPutRequest
) {
topicUpdator.putTopic(userId, topicId, topicPutRequest);
topicUpdator.putTopic(topicId, topicPutRequest);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ public class TopicUpdator {

@Transactional
public void putTopic(
final Long userId,
final Long topicId,
final TopicPutRequest topicPutRequest
) {
Topic topic = topicRetriever.findById(topicId);
User user = userService.findById(userId);
topicRetriever.authenticateTopicWithUser(topic, user);
topic.updateTopic(topicPutRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ public void deleteWriterNameByUser(final User user) {


public void deleteWriterNameById(
final Long writerNameId,
final Long userId
final Long writerNameId
) {
WriterName writerName = writerNameRetriever.findById(writerNameId);
moimRetriever.authenticateOwnerOfMoim(writerName.getMoim(), userRetriever.findById(userId));
writerNameRemover.deleteWriterName(writerName);
}

Expand Down
Loading