Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #162657 chore: Public access to UCM list and Item view #368

Open
wants to merge 2 commits into
base: release-1.2.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/components/com_tjucm/site/views/item/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,27 +43,33 @@ 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');
$this->item = $this->get('Data');
$model = $this->getModel("Item");
$this->model = $this->getModel("Item");
$this->params = $app->getParams('com_tjucm');
$this->ucmTypeId = $model->getState('ucmType.id');

if (!$user->id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KishoriBKarale Do we need to check this especially for public users?
We can check if any kind of user has access to the page.

{
// Check public user permission for view all items
if (empty($user->authorise('core.type.viewitem', 'com_tjucm.type.' . $this->ucmTypeId)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KishoriBKarale Use TjucmAccess class to check ACL and permission

{
$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';
Expand All @@ -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)
Expand Down Expand Up @@ -118,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)
);

Expand Down
54 changes: 33 additions & 21 deletions src/components/com_tjucm/site/views/items/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
Expand All @@ -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)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KishoriBKarale Check the same as mentioned in the above comments

{
$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))
{
Expand Down