Skip to content

Commit

Permalink
#311 자신이 작성한 게시글에 대한 답변 작성 가능 여부를 설정할 수 있는 옵션을 추가합니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
xharpenParksuhyeon committed Aug 18, 2021
1 parent b848106 commit 153a1db
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@
</select>
</div>
</div>

<div class="col-sm-6">
<div class="form-group">
<div class="clearfix">
<label>
{{ xe_trans('board::blockAuthorSelf') }}
<small>{{ xe_trans('board::blockAuthorSelfDescription') }}</small>
</label>
</div>
<select id="" name="blockAuthorSelf" class="form-control">
<option value="true" {!! $config->get('blockAuthorSelf', false) == true ? 'selected="selected"' : '' !!} >{{xe_trans('xe::use')}}</option>
<option value="false" {!! $config->get('blockAuthorSelf', false) == false ? 'selected="selected"' : '' !!} >{{xe_trans('xe::disuse')}}</option>
</select>
</div>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@
</select>
</div>
</div>

<div class="col-sm-6">
<div class="form-group">
<div class="clearfix">
<label>
{{ xe_trans('board::blockAuthorSelf') }}
<small>{{ xe_trans('board::blockAuthorSelfDescription') }}</small>
</label>
<div class="checkbox pull-right">
<label>
<input type="checkbox" class="inheritCheck" data-target="blockAuthorSelf" @if($config->getPure('blockAuthorSelf') === null) checked="checked" @endif />{{ xe_trans('xe::inheritMode') }}
</label>
</div>
</div>
<select id="" name="blockAuthorSelf" class="form-control" @if($config->getPure('blockAuthorSelf') === null) disabled="disabled" @endif>
<option value="true" {!! $config->get('blockAuthorSelf', false) == true ? 'selected="selected"' : '' !!} >{{xe_trans('xe::use')}}</option>
<option value="false" {!! $config->get('blockAuthorSelf', false) == false ? 'selected="selected"' : '' !!} >{{xe_trans('xe::disuse')}}</option>
</select>
</div>
</div>
</div>
</div>
</div>
Expand Down
15 changes: 14 additions & 1 deletion components/ToggleMenus/Boards/ReplyItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Xpressengine\Plugins\Board\Components\ToggleMenus\Boards;

use Xpressengine\Plugins\Board\Models\Board;
use Xpressengine\Plugins\Board\ReplyConfigHandler;
use Xpressengine\ToggleMenu\AbstractToggleMenu;

class ReplyItem extends AbstractToggleMenu
Expand Down Expand Up @@ -46,11 +47,23 @@ public function allows(): bool
$configHandler = app('xe.board.config');
$boardPermission = app('xe.board.permission');

// board's config
$config = $configHandler->get($this->instanceId);
if (is_null($config)) {
return false;
}

return $config->get('replyPost', false) ? $boardPermission->checkCreateAction($this->instanceId) : false;
// board reply's config
$replyConfig = $config->get('replyPost', false) ? ReplyConfigHandler::make()->get($this->instanceId) : null;
if (is_null($replyConfig)) {
return false;
}

// block author self
if ($replyConfig->get('blockAuthorSelf', false) && $board->user_id == auth()->id()) {
return false;
}

return $boardPermission->checkCreateAction($this->instanceId);
}
}
12 changes: 12 additions & 0 deletions langs/lang.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

return [
'cantNotReplyOwnBoard' => [
'ko' => '자신이 작성한 게시물에 답글을 작성할 수 없습니다.',
'en' => 'can not reply to board you have created.'
],
'wroteReply' => [
'ko' => '답변을 작성했습니다.',
'en' => 'wrote a reply'
Expand All @@ -13,6 +17,14 @@
'ko' => '답변을 삭제했습니다.',
'en' => 'deleted a reply'
],
'blockAuthorSelf' => [
'ko' => '자신이 작성한 게시물에 답글 차단',
'en' => 'block author self'
],
'blockAuthorSelfDescription' => [
'ko' => '자신의 게시물에 답글을 작성할 수 없습니다.',
'en' => 'block replying to your own posts.'
],
'protectPost' => [
'ko' => '글 보호',
'en' => 'protect post',
Expand Down
19 changes: 19 additions & 0 deletions src/Exceptions/CantNotReplyOwnBoardException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Xpressengine\Plugins\Board\Exceptions;

use Illuminate\Http\Response;
use Xpressengine\Plugins\Board\HttpBoardException;

class CantNotReplyOwnBoardException extends HttpBoardException
{
/**
* @var string
*/
protected $message = 'board::cantNotReplyOwnBoard';

/**
* @var int
*/
protected $statusCode = Response::HTTP_NOT_ACCEPTABLE;
}
21 changes: 16 additions & 5 deletions src/Plugin/Intercepts/ReplyIntercepts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
use Xpressengine\Http\Request;
use Xpressengine\Plugins\Board\Models\Board;
use Xpressengine\Routing\InstanceConfig;
use Xpressengine\User\Models\User;
use Xpressengine\User\UserInterface;
use Xpressengine\Plugins\Board\Exceptions\{
CanNotDeleteHasReplyException,
use Xpressengine\Plugins\Board\Exceptions\{CanNotDeleteHasReplyException,
CanNotReplyNoticeException,
CanNotUpdatedHasReplyException,
DisabledReplyException
};
CantNotReplyOwnBoardException,
DisabledReplyException};
use Xpressengine\Plugins\Board\{
BoardPermissionHandler,
Components\Modules\BoardModule,
Expand Down Expand Up @@ -54,15 +54,26 @@ public static function interceptValidateStored()
{
$function = function ($function, Request $request, UserInterface $user, ConfigEntity $config, IdentifyManager $identifyManager) {
if ($parentId = $request->get('parent_id')) {
if ($config->get('replyPost', false) === false) {
$replyConfig = $config->get('replyPost', false) ? ReplyConfigHandler::make()->get($config->get('boardId')) : null;

if (is_null($replyConfig)) {
throw new DisabledReplyException;
}

$parent = Board::findOrFail($parentId);

// 공지에는 답글을 작성할 수 없습니다.
if ($parent->isNotice()) {
throw new CanNotReplyNoticeException;
}

// 자신이 작성한 게시물에 답글을 작성할 수 없습니다.
if ($replyConfig->get('blockAuthorSelf', false) === true) {
if ($user instanceof User && $user->getId() === $parent->user_id) {
throw new CantNotReplyOwnBoardException;
}
}

// set redirect url
$routeAction = $request->route()->getAction();
if (Arr::get($routeAction, 'module') === BoardModule::getId() && Arr::get($routeAction, 'as') === 'store') {
Expand Down
5 changes: 3 additions & 2 deletions src/ReplyConfigHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class ReplyConfigHandler extends AbstractConfigHandler

/** @var array */
protected $defaultConfig = [
'protectUpdated' => false, // 답글이 있으면 수정 불가
'protectDeleted' => false, // 답글이 있으면 삭제 불가
'protectUpdated' => false, // 답글이 있으면 수정할 수 없도록 합니다. (if, true)
'protectDeleted' => false, // 답글이 있으면 삭제할 수 없도록 합니다. (if, true)
'blockAuthorSelf' => false, // 작성자 스스로 답글을 작성하지 못하도록 합니다. (if, true)
];

public static function boot()
Expand Down

0 comments on commit 153a1db

Please sign in to comment.