Different folder according to Token
grimmlink opened this issue · 2 comments
Hi,
I'm using Symfony 4.3 and trying to have a different folder according to logged in User. I managed to create an event subscriber plugin, but inside of it there is no way to access the logged User.
I need to access a property of it, any idea how to ?
Also I found what I believe is a bug in the connector code:
In ckfinder/ckfinder-symfony-bundle/_connector/Config.php line 481
array_replace_recursive($values, $this->options[$nodeName])
should be
array_replace_recursive($this->options[$nodeName], $values)
Salut @grimmlink,
I confirm the bug for array__replace__recursive($this->options[$nodeName], $values)
in ckfinder-symfony-bundle/_connector/Config.php
.... Works better now !
I have the same case as you : one folder per logged user.
For example, in my config/packages/ckfinder.yml
:
ckfinder:
connector:
backends:
default:
# Other options...
resourceTypes:
CKFUserFolder:
name: MyFolder
backend: default
# I'm not using 'Files' or 'Images' default folders
In my src/Security/CKFinderAuthenticator.php
:
public function authenticate()
{
$auth = $this->container->get('security.authorization_checker');
if ($auth->isGranted('IS_AUTHENTICATED_FULLY')) {
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$ckfinder = $this->container->get('ckfinder.connector');
//The user folder : Username in my project
$ckfinder['config']->extend('resourceTypes', [
'MyFolder' => ['directory' => $user->getUserName()]
]);
//Check your config object and/or node :
//dd($ckfinder['config']->getResourceTypeNode('MyFolder'));
return true;
}
return false;
}
May be someone can confirm and add this issue to the next pull request with a unit test ? @zaak ? :)
Cheers !