Skip to content

Commit

Permalink
#311 put에 대한 intercept 코드를 update에 대한 intercept 코드로 이전했습니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
xharpenParksuhyeon committed Aug 20, 2021
1 parent 1a9590c commit 8e8c307
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 45 deletions.
70 changes: 26 additions & 44 deletions src/Plugin/Intercepts/ReplyIntercepts.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,35 @@ public static function interceptValidateStored()
public static function interceptValidateUpdated()
{
$function = function ($function, Board $item, Request $request, UserInterface $user, ConfigEntity $config, IdentifyManager $identifyManager) {
if ($item->hasParentDoc()) {
if ($request->get('status') == Document::STATUS_NOTICE) {
throw new CanNotReplyNoticeException;
}
$replyConfig = ReplyConfigHandler::make()->getByBoardConfig($item->instance_id);
$isManager = app(BoardPermissionHandler::class)->checkManageAction($item->instance_id);

/** @var Board $parentBoard */
$parentBoard = Board::with('data')->findOrFail($item->parent_id);
if ($replyConfig !== null) {
if($parentBoard = $item->findParentDoc()) {
if ($request->get('status') == Document::STATUS_NOTICE) {
throw new CanNotReplyNoticeException; // 답글은 공지사항으로 설정할 수 없습니다.
}

if ($item->isAdopted($parentBoard) === true) {
throw new CanNotUpdatedAdoptedException; // 채택된 글은 수정할 수 없습니다.
}
if ($item->isAdopted($parentBoard)) {
if ($isManager === false) {
throw new CanNotUpdatedAdoptedException; // 채택된 글은 수정할 수 없습니다.
}
}

// set redirect url
$routeAction = $request->route()->getAction();
// set redirect url
$routeAction = $request->route()->getAction();
if (Arr::get($routeAction, 'module') === BoardModule::getId() && Arr::get($routeAction, 'as') === 'update') {
$request->merge([
'redirect_url' => app(BoardUrlHandler::class)->getShow($parentBoard, $request->query->all()),
'redirect_message' => xe_trans('board::updatedReply')
]);
}
}

if (Arr::get($routeAction, 'module') === BoardModule::getId() && Arr::get($routeAction, 'as') === 'update') {
$request->merge([
'redirect_url' => app(BoardUrlHandler::class)->getShow($parentBoard, $request->query->all()),
'redirect_message' => xe_trans('board::updatedReply')
]);
else if ($item->existsReplies() === true) {
if ($replyConfig->get('protectUpdated', false) === true && $isManager === false) {
throw new CanNotUpdatedHasReplyException; // 답글이 적힌 글은 수정할 수 없습니다.
}
}
}

Expand All @@ -154,7 +163,7 @@ public static function interceptValidateUpdated()
// update
intercept(
sprintf('%s@update', BoardService::class),
sprintf('%s::reply__validateUpdated', BoardPlugin::getId()),
sprintf('%s::reply__updated', BoardPlugin::getId()),
$function
);
}
Expand Down Expand Up @@ -216,33 +225,6 @@ public static function interceptProtectDeleted()
$function
);
}

/**
* intercept protect updated
*/
public static function interceptProtectUpdated()
{
// put
intercept(
sprintf('%s@put', BoardHandler::class),
sprintf('%s::reply__putLimit', BoardPlugin::getId()),
function ($function, Board $board, array $args, ConfigEntity $config) {
if (app(BoardPermissionHandler::class)->checkManageAction($board->instance_id)) {
return $function($board, $args, $config);
}

$replyConfig = ReplyConfigHandler::make()->getByBoardConfig($board->instance_id);

if ($replyConfig !== null && $replyConfig->get('protectUpdated', false)) {
if ($board->existsReplies()) {
throw new CanNotUpdatedHasReplyException;
}
}

return $function($board, $args, $config);
}
);
}
}


1 change: 0 additions & 1 deletion src/Plugin/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ public static function interceptReply()
Plugin\Intercepts\ReplyIntercepts::interceptValidateStored();
Plugin\Intercepts\ReplyIntercepts::interceptValidateUpdated();
Plugin\Intercepts\ReplyIntercepts::interceptProtectDeleted();
Plugin\Intercepts\ReplyIntercepts::interceptProtectUpdated();
}

/**
Expand Down

0 comments on commit 8e8c307

Please sign in to comment.