Skip to content

Commit a1036de

Browse files
authored
Use the current user in local media adapter (#40745)
* Use the current user in local media adapter * fix test
1 parent 4a60a88 commit a1036de

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

plugins/filesystem/local/src/Adapter/LocalAdapter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Joomla\CMS\Language\Text;
2323
use Joomla\CMS\String\PunycodeHelper;
2424
use Joomla\CMS\Uri\Uri;
25+
use Joomla\CMS\User\CurrentUserTrait;
2526
use Joomla\Component\Media\Administrator\Adapter\AdapterInterface;
2627
use Joomla\Component\Media\Administrator\Exception\FileNotFoundException;
2728
use Joomla\Component\Media\Administrator\Exception\InvalidPathException;
@@ -37,6 +38,8 @@
3738
*/
3839
class LocalAdapter implements AdapterInterface
3940
{
41+
use CurrentUserTrait;
42+
4043
/**
4144
* The root path to gather file information from.
4245
*
@@ -430,7 +433,7 @@ private function getDate($date = null): Date
430433
$dateObj = Factory::getDate($date);
431434

432435
$timezone = Factory::getApplication()->get('offset');
433-
$user = Factory::getUser();
436+
$user = $this->getCurrentUser();
434437

435438
if ($user->id) {
436439
$userTimezone = $user->getParam('timezone');

plugins/filesystem/local/src/Extension/Local.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public function getAdapters()
133133
$directoryEntity->thumbs,
134134
[200, 200]
135135
);
136+
$adapter->setCurrentUser($this->getApplication()->getIdentity());
136137

137138
$adapters[$adapter->getAdapterName()] = $adapter;
138139
}

tests/Unit/Plugin/Filesystem/Local/Extension/LocalPluginTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use InvalidArgumentException;
1414
use Joomla\CMS\Application\CMSApplicationInterface;
1515
use Joomla\CMS\Language\Language;
16+
use Joomla\CMS\User\User;
1617
use Joomla\Component\Media\Administrator\Event\MediaProviderEvent;
1718
use Joomla\Component\Media\Administrator\Provider\ProviderManager;
1819
use Joomla\Event\Dispatcher;
@@ -104,7 +105,11 @@ public function testAdapters()
104105
{
105106
$dispatcher = new Dispatcher();
106107

108+
$app = $this->createStub(CMSApplicationInterface::class);
109+
$app->method('getIdentity')->willReturn(new User());
110+
107111
$plugin = new Local($dispatcher, ['params' => ['directories' => '[{"directory": "tests"}]']], JPATH_ROOT);
112+
$plugin->setApplication($app);
108113
$adapters = $plugin->getAdapters();
109114

110115
$this->assertCount(1, $adapters);

0 commit comments

Comments
 (0)