Move non-member voting, vote canceling, and report canceling options from Board module to Document & Comment modules

This commit is contained in:
Kijin Sung 2023-07-05 22:27:17 +09:00
parent 103f5ce884
commit 3215631dfc
13 changed files with 454 additions and 192 deletions

View file

@ -30,19 +30,7 @@ class DocumentController extends Document
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$module_info = $this->module_info;
if(!$module_info->module_srl)
{
$module_info = ModuleModel::getModuleInfoByDocumentSrl($document_srl);
}
if($module_info->non_login_vote !== 'Y')
{
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
}
// Check target document.
$oDocument = DocumentModel::getDocument($document_srl, false, false);
if(!$oDocument->isExists())
{
@ -52,11 +40,31 @@ class DocumentController extends Document
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// Check if voting is enabled.
$document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl'));
if($document_config->use_vote_up === 'N')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
if(!Context::get('is_logged'))
{
if (isset($document_config->allow_vote_non_member))
{
if ($document_config->allow_vote_non_member !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
else
{
$module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl'));
if (($module_info->non_login_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
}
$point = 1;
$allow_same_ip = ($document_config->allow_vote_from_same_ip ?? 'N') === 'Y';
@ -77,23 +85,7 @@ class DocumentController extends Document
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$module_info = $this->module_info;
if(!$module_info->module_srl)
{
$module_info = ModuleModel::getModuleInfoByDocumentSrl($document_srl);
}
if($module_info->non_login_vote !== 'Y')
{
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
}
if($module_info->cancel_vote !== 'Y')
{
throw new Rhymix\Framework\Exception('failed_voted_cancel');
}
// Check target document.
$oDocument = DocumentModel::getDocument($document_srl, false, false);
if(!$oDocument->isExists())
{
@ -108,6 +100,41 @@ class DocumentController extends Document
throw new Rhymix\Framework\Exception('failed_voted_canceled');
}
// Check if voting and canceling are enabled.
$document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl'));
$module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl'));
if (isset($document_config->allow_vote_cancel))
{
if ($document_config->allow_vote_cancel !== 'Y')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
}
else
{
if (($module_info->cancel_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
}
if(!Context::get('is_logged'))
{
if (isset($document_config->allow_vote_non_member))
{
if ($document_config->allow_vote_non_member !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
else
{
if (($module_info->non_login_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
}
$point = 1;
$output = $this->updateVotedCountCancel($document_srl, $oDocument, $point);
if(!$output->toBool())
@ -120,44 +147,19 @@ class DocumentController extends Document
return $output;
}
/**
* insert alias
* @param int $module_srl
* @param int $document_srl
* @param string $alias_title
* @return object
*/
function insertAlias($module_srl, $document_srl, $alias_title)
{
$args = new stdClass;
$args->alias_srl = getNextSequence();
$args->module_srl = $module_srl;
$args->document_srl = $document_srl;
$args->alias_title = urldecode($alias_title);
$query = "document.insertAlias";
$output = executeQuery($query, $args);
return $output;
}
/**
* Action to handle vote-up of the post (Down)
* @return Object
*/
function procDocumentVoteDown()
{
if($this->module_info->non_login_vote !== 'Y')
{
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
}
$document_srl = Context::get('target_srl');
if(!$document_srl)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check target document.
$oDocument = DocumentModel::getDocument($document_srl, false, false);
if(!$oDocument->isExists())
{
@ -167,11 +169,31 @@ class DocumentController extends Document
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// Check if voting is enabled.
$document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl'));
if($document_config->use_vote_down === 'N')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
if(!Context::get('is_logged'))
{
if (isset($document_config->allow_vote_non_member))
{
if ($document_config->allow_vote_non_member !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
else
{
$module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl'));
if (($module_info->non_login_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
}
$point = -1;
$allow_same_ip = ($document_config->allow_vote_from_same_ip ?? 'N') === 'Y';
@ -186,23 +208,13 @@ class DocumentController extends Document
function procDocumentVoteDownCancel()
{
if($this->module_info->non_login_vote !== 'Y')
{
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
}
if($this->module_info->cancel_vote !== 'Y')
{
return new Rhymix\Framework\Exception('failed_voted_canceled');
}
$document_srl = Context::get('target_srl');
if(!$document_srl)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check target document.
$oDocument = DocumentModel::getDocument($document_srl, false, false);
if(!$oDocument->isExists())
{
@ -217,6 +229,41 @@ class DocumentController extends Document
throw new Rhymix\Framework\Exception('failed_blamed_canceled');
}
// Check if voting and canceling are enabled.
$document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl'));
$module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl'));
if (isset($document_config->allow_vote_cancel))
{
if ($document_config->allow_vote_cancel !== 'Y')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
}
else
{
if (($module_info->cancel_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\FeatureDisabled;
}
}
if(!Context::get('is_logged'))
{
if (isset($document_config->allow_vote_non_member))
{
if ($document_config->allow_vote_non_member !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
else
{
if (($module_info->non_login_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
}
}
$point = -1;
$output = $this->updateVotedCountCancel($document_srl, $oDocument, $point);
if(!$output->toBool())
@ -367,6 +414,7 @@ class DocumentController extends Document
throw new Rhymix\Framework\Exceptions\MustLogin;
}
// Check if the document exists and is accessible to the current user.
$document_srl = Context::get('target_srl');
if(!$document_srl)
{
@ -381,10 +429,23 @@ class DocumentController extends Document
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$module_info = ModuleModel::getModuleInfoByDocumentSrl($document_srl);
if($module_info->cancel_vote !== 'Y')
// Check if canceling is allowed.
$document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl'));
if (isset($document_config->allow_declare_cancel))
{
throw new Rhymix\Framework\Exception('failed_declared_cancel');
if ($document_config->allow_declare_cancel !== 'Y')
{
throw new Rhymix\Framework\Exception('failed_declared_cancel');
}
}
else
{
$module_info = ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl'));
if (($module_info->cancel_vote ?? 'N') !== 'Y')
{
throw new Rhymix\Framework\Exception('failed_declared_cancel');
}
}
if(Context::get('success_return_url'))
@ -423,6 +484,25 @@ class DocumentController extends Document
}
}
/**
* insert alias
* @param int $module_srl
* @param int $document_srl
* @param string $alias_title
* @return object
*/
function insertAlias($module_srl, $document_srl, $alias_title)
{
$args = new stdClass;
$args->alias_srl = getNextSequence();
$args->module_srl = $module_srl;
$args->document_srl = $document_srl;
$args->alias_title = urldecode($alias_title);
$query = "document.insertAlias";
$output = executeQuery($query, $args);
return $output;
}
/**
* Delete alias when module deleted
* @param int $module_srl
@ -3268,9 +3348,18 @@ Content;
$document_config->allow_vote_from_same_ip = Context::get('allow_vote_from_same_ip');
if(!$document_config->allow_vote_from_same_ip) $document_config->allow_vote_from_same_ip = 'N';
$document_config->allow_vote_cancel = Context::get('allow_vote_cancel');
if(!$document_config->allow_vote_cancel) $document_config->allow_vote_cancel = 'N';
$document_config->allow_vote_non_member = Context::get('allow_vote_non_member');
if(!$document_config->allow_vote_non_member) $document_config->allow_vote_non_member = 'N';
$document_config->allow_declare_from_same_ip = Context::get('allow_declare_from_same_ip');
if(!$document_config->allow_declare_from_same_ip) $document_config->allow_declare_from_same_ip = 'N';
$document_config->allow_declare_cancel = Context::get('allow_declare_cancel');
if(!$document_config->allow_declare_cancel) $document_config->allow_declare_cancel = 'N';
$document_config->declared_message = Context::get('declared_message');
if(!is_array($document_config->declared_message)) $document_config->declared_message = array();
$document_config->declared_message = array_values($document_config->declared_message);

View file

@ -174,10 +174,47 @@ class DocumentView extends Document
{
$document_config = new stdClass();
}
if(!isset($document_config->use_history)) $document_config->use_history = 'N';
if(!isset($document_config->use_history))
{
$document_config->use_history = 'N';
}
if(!isset($document_config->use_vote_up))
{
$document_config->use_vote_up = 'Y';
}
if(!isset($document_config->use_vote_down))
{
$document_config->use_vote_down = 'Y';
}
if(!isset($document_config->allow_vote_from_same_ip))
{
$document_config->allow_vote_from_same_ip = 'N';
}
if(!isset($document_config->allow_declare_from_same_ip))
{
$document_config->allow_declare_from_same_ip = 'N';
}
if ($current_module_srl)
{
$module_info = ModuleModel::getModuleInfoByModuleSrl($current_module_srl);
if (!isset($document_config->allow_vote_cancel))
{
$document_config->allow_vote_cancel = (($module_info->cancel_vote ?? 'N') === 'Y') ? 'Y' : 'N';
}
if (!isset($document_config->allow_vote_non_member))
{
$document_config->allow_vote_non_member = (($module_info->non_login_vote ?? 'N') === 'Y') ? 'Y' : 'N';
}
if (!isset($document_config->allow_declare_cancel))
{
$document_config->allow_declare_cancel = (($module_info->cancel_vote ?? 'N') === 'Y') ? 'Y' : 'N';
}
}
Context::set('document_config', $document_config);
$oTemplate = &TemplateHandler::getInstance();
$oTemplate = TemplateHandler::getInstance();
$tpl = $oTemplate->compile($this->module_path.'tpl', 'document_module_config');
$obj = $tpl . $obj;

View file

@ -118,4 +118,7 @@ $lang->improper_document_reasons['privacy'] = 'Privacy issue.';
$lang->improper_document_reasons['others'] = 'Others (Write your own)';
$lang->about_improper_document_declare = 'Write here why you report this article as an improper document.';
$lang->allow_vote_from_same_ip = 'Allow voting from same IP';
$lang->allow_vote_non_member = 'Allow voting by non-members';
$lang->allow_vote_cancel = 'Allow vote cancellation';
$lang->allow_declare_from_same_ip = 'Allow reporting from same IP';
$lang->allow_declare_cancel = 'Allow report cancellation';

View file

@ -118,4 +118,7 @@ $lang->improper_document_reasons['privacy'] = '민감한 개인정보가 노출
$lang->improper_document_reasons['others'] = '기타(직접작성)';
$lang->about_improper_document_declare = '게시글을 신고하신 이유를 간단히 적어서 제출해주시면 관리자 검토 후 조치하겠습니다.';
$lang->allow_vote_from_same_ip = '동일 IP 추천 허용';
$lang->allow_vote_non_member = '비회원 추천 허용';
$lang->allow_vote_cancel = '추천 취소 허용';
$lang->allow_declare_from_same_ip = '동일 IP 신고 허용';
$lang->allow_declare_cancel = '신고 취소 허용';

View file

@ -38,28 +38,32 @@
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{$lang->allow_vote_from_same_ip}</label>
<label class="x_control-label">{$lang->cmd_vote_config}</label>
<div class="x_controls">
<label for="d_allow_vote_from_same_ip_Y" class="x_inline">
<input type="radio" id="d_allow_vote_from_same_ip_Y" name="allow_vote_from_same_ip" value="Y" checked="checked"|cond="$document_config->allow_vote_from_same_ip === 'Y'">
{$lang->cmd_yes}
<label for="d_allow_vote_from_same_ip" class="x_inline">
<input type="checkbox" id="d_allow_vote_from_same_ip" name="allow_vote_from_same_ip" value="Y" checked="checked"|cond="$document_config->allow_vote_from_same_ip === 'Y'">
{$lang->allow_vote_from_same_ip}
</label>
<label for="d_allow_vote_from_same_ip_N" class="x_inline">
<input type="radio" id="d_allow_vote_from_same_ip_N" name="allow_vote_from_same_ip" value="N" checked="checked"|cond="$document_config->allow_vote_from_same_ip !== 'Y'">
{$lang->cmd_no}
<label for="d_allow_vote_cancel" class="x_inline">
<input type="checkbox" id="d_allow_vote_cancel" name="allow_vote_cancel" value="Y" checked="checked"|cond="$document_config->allow_vote_cancel === 'Y'">
{$lang->allow_vote_cancel}
</label>
<label for="d_allow_vote_non_member" class="x_inline">
<input type="checkbox" id="d_allow_vote_non_member" name="allow_vote_non_member" value="Y" checked="checked"|cond="$document_config->allow_vote_non_member === 'Y'">
{$lang->allow_vote_non_member}
</label>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{$lang->allow_declare_from_same_ip}</label>
<label class="x_control-label">{$lang->cmd_declare_config}</label>
<div class="x_controls">
<label for="d_allow_declare_from_same_ip_Y" class="x_inline">
<input type="radio" id="d_allow_declare_from_same_ip_Y" name="allow_declare_from_same_ip" value="Y" checked="checked"|cond="$document_config->allow_declare_from_same_ip === 'Y'">
{$lang->cmd_yes}
<label for="d_allow_declare_from_same_ip" class="x_inline">
<input type="checkbox" id="d_allow_declare_from_same_ip" name="allow_declare_from_same_ip" value="Y" checked="checked"|cond="$document_config->allow_declare_from_same_ip === 'Y'">
{$lang->allow_declare_from_same_ip}
</label>
<label for="d_allow_declare_from_same_ip_N" class="x_inline">
<input type="radio" id="d_allow_declare_from_same_ip_N" name="allow_declare_from_same_ip" value="N" checked="checked"|cond="$document_config->allow_declare_from_same_ip !== 'Y'">
{$lang->cmd_no}
<label for="d_allow_declare_cancel" class="x_inline">
<input type="checkbox" id="d_allow_declare_cancel" name="allow_declare_cancel" value="Y" checked="checked"|cond="$document_config->allow_declare_cancel === 'Y'">
{$lang->allow_declare_cancel}
</label>
</div>
</div>