From 5a79e89fed1b515782bfe66441498d413acb2d1a Mon Sep 17 00:00:00 2001 From: Kishori Date: Wed, 22 Jul 2020 18:27:03 +0530 Subject: [PATCH 1/2] Task #162657 chore: Public access to UCM list and Item view --- .../com_tjucm/site/views/item/view.html.php | 35 +++++++----- .../com_tjucm/site/views/items/view.html.php | 54 +++++++++++-------- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/components/com_tjucm/site/views/item/view.html.php b/src/components/com_tjucm/site/views/item/view.html.php index 4921e994..a0a1cca3 100644 --- a/src/components/com_tjucm/site/views/item/view.html.php +++ b/src/components/com_tjucm/site/views/item/view.html.php @@ -12,6 +12,10 @@ defined('_JEXEC') or die; jimport('joomla.application.component.view'); +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Router\Route; /** * View to edit @@ -39,20 +43,11 @@ class TjucmViewItem extends JViewLegacy */ public function display($tpl = null) { - $app = JFactory::getApplication(); - - if (!JFactory::getUser()->id) - { - $msg = JText::_('COM_TJUCM_LOGIN_MSG'); - - // Get current url. - $current = JUri::getInstance()->toString(); - $url = base64_encode($current); - JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . $url, false), $msg); - } + $app = Factory::getApplication(); + $user = Factory::getUser(); // Load tj-fields language file - $lang = JFactory::getLanguage(); + $lang = Factory::getLanguage(); $lang->load('com_tjfields', JPATH_SITE); $this->state = $this->get('State'); @@ -60,6 +55,21 @@ public function display($tpl = null) $model = $this->getModel("Item"); $this->model = $this->getModel("Item"); $this->params = $app->getParams('com_tjucm'); + $this->ucmTypeId = $model->getState('ucmType.id'); + + if (!$user->id) + { + // Check public user permission for view all items + if (empty($user->authorise('core.type.viewitem', 'com_tjucm.type.' . $this->ucmTypeId))) + { + $msg = Text::_('COM_TJUCM_LOGIN_MSG'); + + // Get current url. + $current = Uri::getInstance()->toString(); + $url = base64_encode($current); + $app->redirect(Route::_('index.php?option=com_users&view=login&return=' . $url, false), $msg); + } + } // Load tj-fields helper helper $path = JPATH_SITE . '/components/com_tjfields/helpers/tjfields.php'; @@ -71,7 +81,6 @@ public function display($tpl = null) } $this->tjFieldsHelper = new TjfieldsHelper; - $this->ucmTypeId = $model->getState('ucmType.id'); // Check the view access to the article (the model has already computed the values). if ($this->item->params->get('access-view') == false) diff --git a/src/components/com_tjucm/site/views/items/view.html.php b/src/components/com_tjucm/site/views/items/view.html.php index 44424768..8388d758 100644 --- a/src/components/com_tjucm/site/views/items/view.html.php +++ b/src/components/com_tjucm/site/views/items/view.html.php @@ -12,6 +12,9 @@ defined('_JEXEC') or die; jimport('joomla.application.component.view'); +use Joomla\CMS\Factory; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Language\Text; /** * View class for a list of Tjucm. @@ -65,27 +68,8 @@ class TjucmViewItems extends JViewLegacy */ public function display($tpl = null) { - $app = JFactory::getApplication(); - $user = JFactory::getUser(); - - if (!$user->id) - { - $msg = JText::_('COM_TJUCM_LOGIN_MSG'); - - // Get current url. - $current = JUri::getInstance()->toString(); - $url = base64_encode($current); - JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . $url, false), $msg); - } - - // Check the view access to the items. - if (!$user->id) - { - $app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error'); - $app->setHeader('status', 403, true); - - return false; - } + $app = Factory::getApplication(); + $user = Factory::getUser(); $this->state = $this->get('State'); $this->items = $this->get('Items'); @@ -100,6 +84,34 @@ public function display($tpl = null) $this->canImport = TjucmAccess::canImport($this->ucmTypeId); $this->draft = array("" => JText::_('COM_TJUCM_DATA_STATUS_SELECT_OPTION'), "0" => JText::_("COM_TJUCM_DATA_STATUS_SAVE"), "1" => JText::_('COM_TJUCM_DATA_STATUS_DRAFT')); + + if (!$user->id) + { + // Check public user permission for view all items + if (empty($user->authorise('core.type.viewitem', 'com_tjucm.type.' . $this->ucmTypeId))) + { + $msg = Text::_('COM_TJUCM_LOGIN_MSG'); + + // Get current url. + $current = Uri::getInstance()->toString(); + $url = base64_encode($current); + $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . $url, false), $msg); + } + } + + // Check the view access to the items. + if (!$user->id) + { + // Check public user permission for view all items + if (empty($user->authorise('core.type.viewitem', 'com_tjucm.type.' . $this->ucmTypeId))) + { + $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); + $app->setHeader('status', 403, true); + + return false; + } + } + // If did not get the client from url then get if from menu param if (empty($this->client)) { From 2ad182ba0409e56bb4f04e1c32abf8dc2a16f424 Mon Sep 17 00:00:00 2001 From: Kishori Date: Wed, 22 Jul 2020 18:34:25 +0530 Subject: [PATCH 2/2] Task #162657 chore: Public access to UCM list and Item view --- src/components/com_tjucm/site/views/item/view.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/com_tjucm/site/views/item/view.html.php b/src/components/com_tjucm/site/views/item/view.html.php index a0a1cca3..7bd6e67a 100644 --- a/src/components/com_tjucm/site/views/item/view.html.php +++ b/src/components/com_tjucm/site/views/item/view.html.php @@ -127,7 +127,7 @@ public function display($tpl = null) "clientComponent" => 'com_tjucm', "client" => $this->client, "view" => $view[1], - "layout" => 'edit', + "layout" => 'default', "content_id" => $this->id) );