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