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

[4.3] Replace Factory::getUser() by $this->getCurrentUser() in components models #38090

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function getListQuery()
}

// Create a new query object.
$user = Factory::getUser();
$user = $this->getCurrentUser();
$db = $this->getDatabase();
$query = $db->getQuery(true);

Expand Down
14 changes: 7 additions & 7 deletions administrator/components/com_banners/src/Model/BannerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BannerModel extends AdminModel
protected function batchClient($value, $pks, $contexts)
{
// Set the variables
$user = Factory::getUser();
$user = $this->getCurrentUser();

/** @var \Joomla\Component\Banners\Administrator\Table\BannerTable $table */
$table = $this->getTable();
Expand Down Expand Up @@ -125,7 +125,7 @@ protected function canDelete($record)

if (!empty($record->catid))
{
return Factory::getUser()->authorise('core.delete', 'com_banners.category.' . (int) $record->catid);
return $this->getCurrentUser()->authorise('core.delete', 'com_banners.category.' . (int) $record->catid);
}

return parent::canDelete($record);
Expand Down Expand Up @@ -164,7 +164,7 @@ protected function canEditState($record)
// Check against the category.
if (!empty($record->catid))
{
return Factory::getUser()->authorise('core.edit.state', 'com_banners.category.' . (int) $record->catid);
return $this->getCurrentUser()->authorise('core.edit.state', 'com_banners.category.' . (int) $record->catid);
}

// Default to component settings if category not known.
Expand Down Expand Up @@ -211,7 +211,7 @@ public function getForm($data = array(), $loadData = true)
}

// Don't allow to change the created_by user if not allowed to access com_users.
if (!Factory::getUser()->authorise('core.manage', 'com_users'))
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users'))
{
$form->setFieldAttribute('created_by', 'filter', 'unset');
}
Expand Down Expand Up @@ -282,7 +282,7 @@ public function stick(&$pks, $value = 1)
}

// Attempt to change the state of the records.
if (!$table->stick($pks, $value, Factory::getUser()->id))
if (!$table->stick($pks, $value, $this->getCurrentUser()->id))
{
$this->setError($table->getError());

Expand Down Expand Up @@ -323,7 +323,7 @@ protected function getReorderConditions($table)
protected function prepareTable($table)
{
$date = Factory::getDate();
$user = Factory::getUser();
$user = $this->getCurrentUser();

if (empty($table->id))
{
Expand Down Expand Up @@ -466,6 +466,6 @@ public function save($data)
*/
private function canCreateCategory()
{
return Factory::getUser()->authorise('core.create', 'com_banners');
return $this->getCurrentUser()->authorise('core.create', 'com_banners');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function canDelete($record)

if (!empty($record->catid))
{
return Factory::getUser()->authorise('core.delete', 'com_banners.category.' . (int) $record->catid);
return $this->getCurrentUser()->authorise('core.delete', 'com_banners.category.' . (int) $record->catid);
}

return parent::canDelete($record);
Expand All @@ -69,7 +69,7 @@ protected function canDelete($record)
*/
protected function canEditState($record)
{
$user = Factory::getUser();
$user = $this->getCurrentUser();

if (!empty($record->catid))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected function getListQuery()
*/
public function delete()
{
$user = Factory::getUser();
$user = $this->getCurrentUser();
$categoryId = (int) $this->getState('category_id');

// Access checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected function getListQuery()
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
$user = Factory::getUser();
$user = $this->getCurrentUser();

// Select the required fields from the table.
$query->select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function canDelete($record)
return false;
}

return Factory::getUser()->authorise('core.delete', $record->extension . '.category.' . (int) $record->id);
return $this->getCurrentUser()->authorise('core.delete', $record->extension . '.category.' . (int) $record->id);
}

/**
Expand All @@ -125,7 +125,7 @@ protected function canDelete($record)
*/
protected function canEditState($record)
{
$user = Factory::getUser();
$user = $this->getCurrentUser();

// Check for existing category.
if (!empty($record->id))
Expand Down Expand Up @@ -286,7 +286,7 @@ public function getForm($data = array(), $loadData = true)
$parts = explode('.', $extension);
$assetKey = $categoryId ? $extension . '.category.' . $categoryId : $parts[0];

if (!Factory::getUser()->authorise('core.edit.state', $assetKey))
if (!$this->getCurrentUser()->authorise('core.edit.state', $assetKey))
{
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
Expand All @@ -299,7 +299,7 @@ public function getForm($data = array(), $loadData = true)
}

// Don't allow to change the created_user_id user if not allowed to access com_users.
if (!Factory::getUser()->authorise('core.manage', 'com_users'))
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users'))
{
$form->setFieldAttribute('created_user_id', 'filter', 'unset');
}
Expand Down Expand Up @@ -385,7 +385,7 @@ protected function loadFormData()
*/
public function validate($form, $data, $group = null)
{
if (!Factory::getUser()->authorise('core.admin', $data['extension']))
if (!$this->getCurrentUser()->authorise('core.admin', $data['extension']))
{
if (isset($data['rules']))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public function save($data)

// Check that we aren't removing our Super User permission
// Need to get groups from database, since they might have changed
$myGroups = Access::getGroupsByUser(Factory::getUser()->get('id'));
$myGroups = Access::getGroupsByUser($this->getCurrentUser()->get('id'));
$myRules = $rules->getData();
$hasSuperAdmin = $myRules['core.admin']->allow($myGroups);

Expand Down Expand Up @@ -982,7 +982,7 @@ private function writeConfigFile(Registry $config)
public function storePermissions($permission = null)
{
$app = Factory::getApplication();
$user = Factory::getUser();
$user = $this->getCurrentUser();

if (is_null($permission))
{
Expand Down Expand Up @@ -1355,7 +1355,7 @@ public function sendTestMail()
{
// Set the new values to test with the current settings
$app = Factory::getApplication();
$user = Factory::getUser();
$user = $this->getCurrentUser();
$input = $app->input->json;
$smtppass = $input->get('smtppass', null, 'RAW');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function save($data)
PluginHelper::importPlugin('extension');

// Check super user group.
if (isset($data['params']) && !Factory::getUser()->authorise('core.admin'))
if (isset($data['params']) && !$this->getCurrentUser()->authorise('core.admin'))
{
$form = $this->getForm(array(), false);

Expand All @@ -185,7 +185,7 @@ public function save($data)
// Save the rules.
if (isset($data['params']) && isset($data['params']['rules']))
{
if (!Factory::getUser()->authorise('core.admin', $data['option']))
if (!$this->getCurrentUser()->authorise('core.admin', $data['option']))
{
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
}
Expand Down
10 changes: 5 additions & 5 deletions administrator/components/com_contact/src/Model/ContactModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function canDelete($record)
return false;
}

return Factory::getUser()->authorise('core.delete', 'com_contact.category.' . (int) $record->catid);
return $this->getCurrentUser()->authorise('core.delete', 'com_contact.category.' . (int) $record->catid);
}

/**
Expand All @@ -152,7 +152,7 @@ protected function canEditState($record)
// Check against the category.
if (!empty($record->catid))
{
return Factory::getUser()->authorise('core.edit.state', 'com_contact.category.' . (int) $record->catid);
return $this->getCurrentUser()->authorise('core.edit.state', 'com_contact.category.' . (int) $record->catid);
}

// Default to component settings if category not known.
Expand Down Expand Up @@ -197,7 +197,7 @@ public function getForm($data = array(), $loadData = true)
}

// Don't allow to change the created_by user if not allowed to access com_users.
if (!Factory::getUser()->authorise('core.manage', 'com_users'))
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users'))
{
$form->setFieldAttribute('created_by', 'filter', 'unset');
}
Expand Down Expand Up @@ -406,7 +406,7 @@ protected function prepareTable($table)
{
// Set the values
$table->modified = $date;
$table->modified_by = Factory::getUser()->id;
$table->modified_by = $this->getCurrentUser()->id;
}

// Increment the content version number.
Expand Down Expand Up @@ -547,6 +547,6 @@ public function featured($pks, $value = 0)
*/
private function canCreateCategory()
{
return Factory::getUser()->authorise('core.create', 'com_contact');
return $this->getCurrentUser()->authorise('core.create', 'com_contact');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function getListQuery()
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
$user = Factory::getUser();
$user = $this->getCurrentUser();

// Select the required fields from the table.
$query->select(
Expand Down
12 changes: 6 additions & 6 deletions administrator/components/com_content/src/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected function batchMove($value, $pks, $contexts)
if (empty($this->batchSet))
{
// Set some needed variables.
$this->user = Factory::getUser();
$this->user = $this->getCurrentUser();
$this->table = $this->getTable();
$this->tableClassName = get_class($this->table);
$this->contentType = new UCMType;
Expand Down Expand Up @@ -309,7 +309,7 @@ protected function canDelete($record)
return false;
}

return Factory::getUser()->authorise('core.delete', 'com_content.article.' . (int) $record->id);
return $this->getCurrentUser()->authorise('core.delete', 'com_content.article.' . (int) $record->id);
}

/**
Expand All @@ -323,7 +323,7 @@ protected function canDelete($record)
*/
protected function canEditState($record)
{
$user = Factory::getUser();
$user = $this->getCurrentUser();

// Check for existing article.
if (!empty($record->id))
Expand Down Expand Up @@ -591,7 +591,7 @@ public function getForm($data = array(), $loadData = true)
}

// Don't allow to change the created_by user if not allowed to access com_users.
if (!Factory::getUser()->authorise('core.manage', 'com_users'))
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users'))
{
$form->setFieldAttribute('created_by', 'filter', 'unset');
}
Expand Down Expand Up @@ -666,7 +666,7 @@ protected function loadFormData()
*/
public function validate($form, $data, $group = null)
{
if (!Factory::getUser()->authorise('core.admin', 'com_content'))
if (!$this->getCurrentUser()->authorise('core.admin', 'com_content'))
{
if (isset($data['rules']))
{
Expand Down Expand Up @@ -1167,7 +1167,7 @@ public function hit()
*/
private function canCreateCategory()
{
return Factory::getUser()->authorise('core.create', 'com_content');
return $this->getCurrentUser()->authorise('core.create', 'com_content');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected function getListQuery()
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
$user = Factory::getUser();
$user = $this->getCurrentUser();

$params = ComponentHelper::getParams('com_content');

Expand Down Expand Up @@ -601,7 +601,7 @@ public function getTransitions()
}

$db = $this->getDatabase();
$user = Factory::getUser();
$user = $this->getCurrentUser();

$items = $this->getItems();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getItems()
return false;
}

$user = Factory::getUser();
$user = $this->getCurrentUser();

// Access check
if (!$user->authorise('core.edit', $table1->item_id) && !$this->canEdit($table1))
Expand Down Expand Up @@ -166,7 +166,7 @@ protected function canEdit($record)
* Make sure user has edit privileges for this content item. Note that we use edit permissions
* for the content item, not delete permissions for the content history row.
*/
$user = Factory::getUser();
$user = $this->getCurrentUser();
$result = $user->authorise('core.edit', $record->item_id);

// Finally try session (this catches edit.own case too)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function canEdit($record)
* Make sure user has edit privileges for this content item. Note that we use edit permissions
* for the content item, not delete permissions for the content history row.
*/
$user = Factory::getUser();
$user = $this->getCurrentUser();

if ($user->authorise('core.edit', $record->item_id))
{
Expand Down Expand Up @@ -209,7 +209,7 @@ public function delete(&$pks)
public function getItems()
{
$items = parent::getItems();
$user = Factory::getUser();
$user = $this->getCurrentUser();

if ($items === false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getItem($pk = null)
return false;
}

$user = Factory::getUser();
$user = $this->getCurrentUser();

// Access check
if (!$user->authorise('core.edit', $table->item_id) && !$this->canEdit($table))
Expand Down Expand Up @@ -129,7 +129,7 @@ protected function canEdit($record)
* Make sure user has edit privileges for this content item. Note that we use edit permissions
* for the content item, not delete permissions for the content history row.
*/
$user = Factory::getUser();
$user = $this->getCurrentUser();
$result = $user->authorise('core.edit', $record->item_id);

// Finally try session (this catches edit.own case too)
Expand Down
Loading