Fix index page being displayed with 404 code if user requests domain.com/1234 with non-existent document_srl

This commit is contained in:
Kijin Sung 2024-02-04 23:21:18 +09:00
parent 578de6404b
commit bd43950c75
2 changed files with 39 additions and 14 deletions

View file

@ -10,7 +10,8 @@
<action name="dispPageIndex" type="view" standalone="false" index="true"> <action name="dispPageIndex" type="view" standalone="false" index="true">
<route route="$document_srl:int" priority="100" /> <route route="$document_srl:int" priority="100" />
</action> </action>
<action name="dispPageNotFound" type="view" standalone="false" error-handlers="404" />
<action name="dispPageAdminContent" type="view" admin_index="true" menu_name="page" menu_index="true" /> <action name="dispPageAdminContent" type="view" admin_index="true" menu_name="page" menu_index="true" />
<action name="dispPageAdminDelete" type="view" menu_name="page" /> <action name="dispPageAdminDelete" type="view" menu_name="page" />
<action name="dispPageAdminInfo" type="view" permission="manager" check_var="module_srl" setup_index="true" menu_name="page" /> <action name="dispPageAdminInfo" type="view" permission="manager" check_var="module_srl" setup_index="true" menu_name="page" />
@ -21,7 +22,7 @@
<action name="dispPageAdminContentModify" type="view" permission="modify" standalone="false" /> <action name="dispPageAdminContentModify" type="view" permission="modify" standalone="false" />
<action name="dispPageAdminMobileContent" type="view" permission="modify" standalone="false" /> <action name="dispPageAdminMobileContent" type="view" permission="modify" standalone="false" />
<action name="dispPageAdminMobileContentModify" type="view" permission="modify" standalone="false" /> <action name="dispPageAdminMobileContentModify" type="view" permission="modify" standalone="false" />
<action name="procPageAdminInsert" type="controller" ruleset="insertPage" /> <action name="procPageAdminInsert" type="controller" ruleset="insertPage" />
<action name="procPageAdminUpdate" type="controller" permission="manager" check_var="module_srl" ruleset="updatePage" /> <action name="procPageAdminUpdate" type="controller" permission="manager" check_var="module_srl" ruleset="updatePage" />
<action name="procPageAdminDelete" type="controller" ruleset="deletePage" /> <action name="procPageAdminDelete" type="controller" ruleset="deletePage" />

View file

@ -74,24 +74,48 @@ class PageView extends Page
{ {
$page_type_name = 'widget'; $page_type_name = 'widget';
} }
// Check document_srl.
$request_vars = Context::getRequestVars();
if (!empty($request_vars->document_srl))
{
$oDocument = DocumentModel::getDocument($request_vars->document_srl);
if (!$oDocument->isExists())
{
return $this->dispPageNotFound(404, 'msg_not_founded');
}
elseif (!$oDocument->isAccessible())
{
return $this->dispPageNotFound(403, 'msg_not_permitted');
}
elseif (in_array($page_type_name, ['article']))
{
return $this->setRedirectUrl(getNotEncodedUrl(['mid' => $this->mid]));
}
}
// Get page content.
$method = '_get' . ucfirst($page_type_name) . 'Content'; $method = '_get' . ucfirst($page_type_name) . 'Content';
$page_content = $this->{$method}(); $page_content = $this->{$method}();
Context::set('module_info', $this->module_info); Context::set('module_info', $this->module_info);
Context::set('page_content', $page_content); Context::set('page_content', $page_content);
// if the page type is the widget or outside, there might be usable GET entities. $this->setTemplatePath($this->module_path . 'tpl');
$request_vars = Context::getRequestVars(); $this->setTemplateFile($this instanceof pageMobile ? 'mobile' : 'content');
if (!empty($request_vars->document_srl) && in_array($page_type_name, ['article', 'widget'])) }
{
$returnUrl = getUrl(['mid' => Context::get('mid')]); /**
$this->setRedirectUrl($returnUrl); * 404 error handler
} */
else public function dispPageNotFound($code, $message)
{ {
$this->setTemplatePath($this->module_path . 'tpl'); $oMessageObject = $this instanceof PageMobile ? MessageMobile::getInstance() : MessageView::getInstance();
$this->setTemplateFile($this instanceof pageMobile ? 'mobile' : 'content'); $oMessageObject->setMessage($message);
} $oMessageObject->dispMessage();
$this->setTemplatePath($oMessageObject->getTemplatePath());
$this->setTemplateFile($oMessageObject->getTemplateFile());
$this->setHttpStatusCode($code);
} }
function _getWidgetContent() function _getWidgetContent()