Commit a6401cfe by Yvon

comptoir access : instead of allowing all requests from UserAdmin object, only…

comptoir access : instead of allowing all requests from UserAdmin object, only allow to show password in general user form, which is sufficient to change it ; add tav_env condition
parent 2b840831
...@@ -194,7 +194,10 @@ class UserAdmin extends BaseUserAdmin ...@@ -194,7 +194,10 @@ class UserAdmin extends BaseUserAdmin
->add('username') ->add('username')
->add('email') ->add('email')
; ;
if ('dev' == $_ENV['APP_ENV'] && $this->isGranted('ROLE_SUPER_ADMIN')) { if (
'dev' == $_ENV['APP_ENV'] && ($this->isGranted('ROLE_SUPER_ADMIN')
|| $this->getSecurityHandler()->grantChangeAdherentPasswordToNonSuperAdmin('ROLE_CHANGE_ADHERENT_PERSONAL_DATA'))
) {
$formMapper $formMapper
->add('plainPassword', RepeatedType::class, [ ->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class, 'type' => PasswordType::class,
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace App\Security\Handler; namespace App\Security\Handler;
use App\Application\Sonata\UserBundle\Admin\UserAdmin;
use App\Entity\GlobalParameter; use App\Entity\GlobalParameter;
use App\Entity\User; use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
...@@ -46,7 +45,7 @@ class VoterSecurityHandler extends RoleSecurityHandler ...@@ -46,7 +45,7 @@ class VoterSecurityHandler extends RoleSecurityHandler
return $this->isAnyGranted($this->superAdminRoles) return $this->isAnyGranted($this->superAdminRoles)
|| $this->isAnyGranted($attributes, $object) || $this->isAnyGranted($attributes, $object)
|| $this->isAnyGranted([$allRole], $object) || $this->isAnyGranted([$allRole], $object)
|| $this->allowToChangeAdherentPersonalData($object); || $this->allowToModifyAdherentPersonalData($object);
} catch (AuthenticationCredentialsNotFoundException $e) { } catch (AuthenticationCredentialsNotFoundException $e) {
return false; return false;
} }
...@@ -68,11 +67,15 @@ class VoterSecurityHandler extends RoleSecurityHandler ...@@ -68,11 +67,15 @@ class VoterSecurityHandler extends RoleSecurityHandler
return false; return false;
} }
private function allowToChangeAdherentPersonalData($object): bool private function allowToModifyAdherentPersonalData($object): bool
{ {
//var_dump(get_class($object)); return $_ENV['TAV_ENV']
$res = (($object instanceof User && $object->getAdherent()) || ($object instanceof UserAdmin)) && $this->authorizationChecker->isGranted('ROLE_CHANGE_ADHERENT_PERSONAL_DATA'); && $object instanceof User && $object->getAdherent()
//var_dump($res); && $this->authorizationChecker->isGranted('ROLE_CHANGE_ADHERENT_PERSONAL_DATA');
return $res; }
public function grantChangeAdherentPasswordToNonSuperAdmin($str): bool
{
return $_ENV['TAV_ENV'] && ($str === 'ROLE_CHANGE_ADHERENT_PERSONAL_DATA');
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment