Use getCurrentUser() to get current user in models and views

This commit is contained in:
Tuan Pham Ngoc 2022-09-04 23:20:31 +07:00
parent 5103c48c95
commit 4b8cd0c779
8 changed files with 15 additions and 15 deletions

View File

@ -71,7 +71,7 @@ class WeblinkModel extends AdminModel
return false;
}
return Factory::getApplication()->getIdentity()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
return $this->getCurrentUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
}
/**
@ -87,7 +87,7 @@ class WeblinkModel extends AdminModel
{
if (!empty($record->catid))
{
return Factory::getApplication()->getIdentity()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
return $this->getCurrentUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
}
return parent::canEditState($record);
@ -143,7 +143,7 @@ class WeblinkModel extends AdminModel
}
// Don't allow to change the created_by user if not allowed to access com_users.
if (!Factory::getApplication()->getIdentity()->authorise('core.manage', 'com_users'))
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users'))
{
$form->setFieldAttribute('created_by', 'filter', 'unset');
}
@ -243,7 +243,7 @@ class WeblinkModel extends AdminModel
protected function prepareTable($table)
{
$date = Factory::getDate();
$user = Factory::getApplication()->getIdentity();
$user = $this->getCurrentUser();
$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
$table->alias = ApplicationHelper::stringURLSafe($table->alias);
@ -338,7 +338,7 @@ class WeblinkModel extends AdminModel
// Alter the title for save as copy
if ($app->input->get('task') == 'save2copy')
{
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
[$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $name;
$data['alias'] = $alias;
$data['state'] = 0;
@ -438,6 +438,6 @@ class WeblinkModel extends AdminModel
*/
private function canCreateCategory()
{
return Factory::getApplication()->getIdentity()->authorise('core.create', 'com_weblinks');
return $this->getCurrentUser()->authorise('core.create', 'com_weblinks');
}
}

View File

@ -156,7 +156,7 @@ class WeblinksModel extends ListModel
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
$user = Factory::getApplication()->getIdentity();
$user = $this->getCurrentUser();
// Select the required fields from the table.
$query->select(

View File

@ -98,7 +98,7 @@ class HtmlView extends BaseHtmlView
$app = Factory::getApplication();
$app->input->set('hidemainmenu', true);
$user = $app->getIdentity();
$user = $this->getCurrentUser();
$isNew = ($this->item->id == 0);
$checkedOut = $this->item->checked_out && $this->item->checked_out !== $user->get('id');

View File

@ -131,7 +131,7 @@ class HtmlView extends BaseHtmlView
protected function addToolbar()
{
$canDo = ContentHelper::getActions('com_weblinks', 'category', $this->state->get('filter.category_id'));
$user = Factory::getApplication()->getIdentity();
$user = $this->getCurrentUser();
// Get the toolbar object instance
$toolbar = Toolbar::getInstance('toolbar');

View File

@ -139,7 +139,7 @@ class CategoryModel extends ListModel
*/
protected function getListQuery()
{
$viewLevels = Factory::getApplication()->getIdentity()->getAuthorisedViewLevels();
$viewLevels = $this->getCurrentUser()->getAuthorisedViewLevels();
// Create a new query object.
$db = $this->getDatabase();
@ -296,7 +296,7 @@ class CategoryModel extends ListModel
$id = $app->input->get('id', 0, 'int');
$this->setState('category.id', $id);
$user = $app->getIdentity();
$user = $this->getCurrentUser();
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks'))
{

View File

@ -97,7 +97,7 @@ class FormModel extends WeblinkModel
$form = $this->loadForm('com_weblinks.form', 'weblink', array('control' => 'jform', 'load_data' => $loadData));
// Disable the buttons and just allow editor none for not authenticated users
if (Factory::getApplication()->getIdentity()->guest)
if ($this->getCurrentUser()->guest)
{
$form->setFieldAttribute('description', 'editor', 'none');
$form->setFieldAttribute('description', 'buttons', 'no');

View File

@ -63,7 +63,7 @@ class WeblinkModel extends ItemModel
$params = $app->getParams();
$this->setState('params', $params);
$user = $app->getIdentity();
$user = $this->getCurrentUser();
if (!$user->authorise('core.edit.state', 'com_weblinks') && !$user->authorise('core.edit', 'com_weblinks'))
{
@ -83,7 +83,7 @@ class WeblinkModel extends ItemModel
*/
public function getItem($pk = null)
{
$user = Factory::getApplication()->getIdentity();
$user = $this->getCurrentUser();
$pk = (!empty($pk)) ? $pk : (int) $this->getState('weblink.id');

View File

@ -68,7 +68,7 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
$user = Factory::getApplication()->getIdentity();
$user = $this->getCurrentUser();
// Get model data.
$this->state = $this->get('State');