Skip to content

Commit 104b321

Browse files
authored
Replaces Factory::getUser() with current user in views and tables (#40422)
1 parent 38b38f0 commit 104b321

File tree

76 files changed

+168
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+168
-137
lines changed

administrator/components/com_actionlogs/src/Plugin/ActionLogPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ abstract class ActionLogPlugin extends CMSPlugin
6464
*/
6565
protected function addLog($messages, $messageLanguageKey, $context, $userId = null)
6666
{
67-
$user = Factory::getUser();
67+
$user = $this->app->getIdentity();
6868

6969
foreach ($messages as $index => $message) {
7070
if (!\array_key_exists('userid', $message)) {

administrator/components/com_admin/src/View/Sysinfo/JsonView.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Joomla\CMS\Factory;
1616
use Joomla\CMS\Language\Text;
1717
use Joomla\CMS\MVC\View\AbstractView;
18+
use Joomla\CMS\User\CurrentUserInterface;
19+
use Joomla\CMS\User\CurrentUserTrait;
1820
use Joomla\Component\Admin\Administrator\Model\SysinfoModel;
1921

2022
// phpcs:disable PSR1.Files.SideEffects
@@ -26,8 +28,10 @@
2628
*
2729
* @since 3.5
2830
*/
29-
class JsonView extends AbstractView
31+
class JsonView extends AbstractView implements CurrentUserInterface
3032
{
33+
use CurrentUserTrait;
34+
3135
/**
3236
* Execute and display a template script.
3337
*
@@ -42,7 +46,7 @@ class JsonView extends AbstractView
4246
public function display($tpl = null): void
4347
{
4448
// Access check.
45-
if (!Factory::getUser()->authorise('core.admin')) {
49+
if (!$this->getCurrentUser()->authorise('core.admin')) {
4650
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
4751
}
4852

administrator/components/com_admin/src/View/Sysinfo/TextView.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Joomla\CMS\Factory;
1616
use Joomla\CMS\Language\Text;
1717
use Joomla\CMS\MVC\View\AbstractView;
18+
use Joomla\CMS\User\CurrentUserInterface;
19+
use Joomla\CMS\User\CurrentUserTrait;
1820
use Joomla\Component\Admin\Administrator\Model\SysinfoModel;
1921

2022
// phpcs:disable PSR1.Files.SideEffects
@@ -26,8 +28,10 @@
2628
*
2729
* @since 3.5
2830
*/
29-
class TextView extends AbstractView
31+
class TextView extends AbstractView implements CurrentUserInterface
3032
{
33+
use CurrentUserTrait;
34+
3135
/**
3236
* Execute and display a template script.
3337
*
@@ -42,7 +46,7 @@ class TextView extends AbstractView
4246
public function display($tpl = null): void
4347
{
4448
// Access check.
45-
if (!Factory::getUser()->authorise('core.admin')) {
49+
if (!$this->getCurrentUser()->authorise('core.admin')) {
4650
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
4751
}
4852

administrator/components/com_associations/tmpl/associations/default.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
defined('_JEXEC') or die;
1212

13-
use Joomla\CMS\Factory;
1413
use Joomla\CMS\HTML\HTMLHelper;
1514
use Joomla\CMS\Language\Text;
1615
use Joomla\CMS\Layout\LayoutHelper;
@@ -25,7 +24,7 @@
2524

2625
$listOrder = $this->escape($this->state->get('list.ordering'));
2726
$listDirn = $this->escape($this->state->get('list.direction'));
28-
$canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin');
27+
$canManageCheckin = $this->getCurrentUser()->authorise('core.manage', 'com_checkin');
2928

3029
$iconStates = [
3130
-2 => 'icon-trash',

administrator/components/com_associations/tmpl/associations/modal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
$function = $app->getInput()->getCmd('function', 'jSelectAssociation');
3333
$listOrder = $this->escape($this->state->get('list.ordering'));
3434
$listDirn = $this->escape($this->state->get('list.direction'));
35-
$canManageCheckin = Factory::getUser()->authorise('core.manage', 'com_checkin');
35+
$canManageCheckin = $this->getCurrentUser()->authorise('core.manage', 'com_checkin');
3636

3737
$iconStates = [
3838
-2 => 'icon-trash',

administrator/components/com_banners/tmpl/banners/default.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
defined('_JEXEC') or die;
1212

13-
use Joomla\CMS\Factory;
1413
use Joomla\CMS\HTML\HTMLHelper;
1514
use Joomla\CMS\Language\Multilanguage;
1615
use Joomla\CMS\Language\Text;
@@ -25,7 +24,7 @@
2524
$wa->useScript('table.columns')
2625
->useScript('multiselect');
2726

28-
$user = Factory::getUser();
27+
$user = $this->getCurrentUser();
2928
$userId = $user->get('id');
3029
$listOrder = $this->escape($this->state->get('list.ordering'));
3130
$listDirn = $this->escape($this->state->get('list.direction'));

administrator/components/com_banners/tmpl/clients/default.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
defined('_JEXEC') or die;
1212

13-
use Joomla\CMS\Factory;
1413
use Joomla\CMS\HTML\HTMLHelper;
1514
use Joomla\CMS\Language\Text;
1615
use Joomla\CMS\Layout\LayoutHelper;
@@ -32,7 +31,7 @@
3231
'5' => 'DAILY',
3332
];
3433

35-
$user = Factory::getUser();
34+
$user = $this->getCurrentUser();
3635
$userId = $user->get('id');
3736
$listOrder = $this->escape($this->state->get('list.ordering'));
3837
$listDirn = $this->escape($this->state->get('list.direction'));

administrator/components/com_categories/tmpl/categories/default.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
defined('_JEXEC') or die;
1212

13-
use Joomla\CMS\Factory;
1413
use Joomla\CMS\HTML\HTMLHelper;
1514
use Joomla\CMS\Language\Multilanguage;
1615
use Joomla\CMS\Language\Text;
@@ -24,7 +23,7 @@
2423
$wa->useScript('table.columns')
2524
->useScript('multiselect');
2625

27-
$user = Factory::getUser();
26+
$user = $this->getCurrentUser();
2827
$userId = $user->get('id');
2928
$extension = $this->escape($this->state->get('filter.extension'));
3029
$listOrder = $this->escape($this->state->get('list.ordering'));

administrator/components/com_contact/src/Table/ContactTable.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Joomla\CMS\Table\Table;
1919
use Joomla\CMS\Tag\TaggableTableInterface;
2020
use Joomla\CMS\Tag\TaggableTableTrait;
21+
use Joomla\CMS\User\CurrentUserInterface;
22+
use Joomla\CMS\User\CurrentUserTrait;
2123
use Joomla\CMS\Versioning\VersionableTableInterface;
2224
use Joomla\Database\DatabaseDriver;
2325
use Joomla\String\StringHelper;
@@ -31,9 +33,10 @@
3133
*
3234
* @since 1.0
3335
*/
34-
class ContactTable extends Table implements VersionableTableInterface, TaggableTableInterface
36+
class ContactTable extends Table implements VersionableTableInterface, TaggableTableInterface, CurrentUserInterface
3537
{
3638
use TaggableTableTrait;
39+
use CurrentUserTrait;
3740

3841
/**
3942
* Indicates that columns fully support the NULL value in the database
@@ -79,7 +82,7 @@ public function __construct(DatabaseDriver $db)
7982
public function store($updateNulls = true)
8083
{
8184
$date = Factory::getDate()->toSql();
82-
$userId = Factory::getUser()->id;
85+
$userId = $this->getCurrentUser()->id;
8386

8487
// Set created date if not set.
8588
if (!(int) $this->created) {

administrator/components/com_contact/tmpl/contacts/default.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
defined('_JEXEC') or die;
1212

13-
use Joomla\CMS\Factory;
1413
use Joomla\CMS\HTML\HTMLHelper;
1514
use Joomla\CMS\Language\Associations;
1615
use Joomla\CMS\Language\Multilanguage;
@@ -24,7 +23,7 @@
2423
$wa->useScript('table.columns')
2524
->useScript('multiselect');
2625

27-
$user = Factory::getUser();
26+
$user = $this->getCurrentUser();
2827
$userId = $user->get('id');
2928
$listOrder = $this->escape($this->state->get('list.ordering'));
3029
$listDirn = $this->escape($this->state->get('list.direction'));

0 commit comments

Comments
 (0)