mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-10 16:55:00 +00:00
Compare commits
7 Commits
375-notifi
...
issue17_us
Author | SHA1 | Date | |
---|---|---|---|
6f7bda9f0a | |||
c34c8035ea | |||
a3c5cabc9a | |||
0fc3c2eb1f | |||
3ebeda9840 | |||
1453fdcd18 | |||
0a4abe9b8d |
@@ -20,7 +20,7 @@ class DefaultController extends AbstractController
|
|||||||
{
|
{
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
if ($this->isGranted('ROLE_ADMIN')) {
|
if ($this->isGranted('ROLE_ADMIN') && !in_array('ROLE_USER',$this->getUser()->getRoles())) {
|
||||||
return $this->redirectToRoute('chill_main_admin_central', [], 302);
|
return $this->redirectToRoute('chill_main_admin_central', [], 302);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -112,6 +112,11 @@ class User implements AdvancedUserInterface
|
|||||||
*/
|
*/
|
||||||
private string $password = '';
|
private string $password = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="json")
|
||||||
|
*/
|
||||||
|
private array $roles = ['ROLE_USER'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal must be set to null if we use bcrypt
|
* @internal must be set to null if we use bcrypt
|
||||||
*
|
*
|
||||||
@@ -146,36 +151,24 @@ class User implements AdvancedUserInterface
|
|||||||
$this->groupCenters = new ArrayCollection();
|
$this->groupCenters = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function __toString(): string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
{
|
||||||
return $this->getLabel();
|
return $this->getLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function addGroupCenter(GroupCenter $groupCenter): self
|
||||||
* @param \Chill\MainBundle\Entity\GroupCenter $groupCenter
|
|
||||||
*
|
|
||||||
* @return \Chill\MainBundle\Entity\User
|
|
||||||
*/
|
|
||||||
public function addGroupCenter(GroupCenter $groupCenter)
|
|
||||||
{
|
{
|
||||||
$this->groupCenters->add($groupCenter);
|
$this->groupCenters->add($groupCenter);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// empty function... remove?
|
||||||
public function eraseCredentials()
|
public function eraseCredentials()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getAttributes(): ?array
|
||||||
* Get attributes.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getAttributes()
|
|
||||||
{
|
{
|
||||||
if (null === $this->attributes) {
|
if (null === $this->attributes) {
|
||||||
$this->attributes = [];
|
$this->attributes = [];
|
||||||
@@ -189,18 +182,12 @@ class User implements AdvancedUserInterface
|
|||||||
return $this->currentLocation;
|
return $this->currentLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getEmail(): ?string
|
public function getEmail(): ?string
|
||||||
{
|
{
|
||||||
return $this->email;
|
return $this->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getEmailCanonical(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getEmailCanonical()
|
|
||||||
{
|
{
|
||||||
return $this->emailCanonical;
|
return $this->emailCanonical;
|
||||||
}
|
}
|
||||||
@@ -213,12 +200,7 @@ class User implements AdvancedUserInterface
|
|||||||
return $this->groupCenters;
|
return $this->groupCenters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getId(): ?int
|
||||||
* Get id.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getId()
|
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
@@ -243,23 +225,17 @@ class User implements AdvancedUserInterface
|
|||||||
return $this->mainScope;
|
return $this->mainScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getPassword(): string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPassword()
|
|
||||||
{
|
{
|
||||||
return $this->password;
|
return $this->password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRoles(): array
|
public function getRoles(): array
|
||||||
{
|
{
|
||||||
return ['ROLE_USER'];
|
return array_unique($this->roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getSalt(): ?string
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getSalt()
|
|
||||||
{
|
{
|
||||||
return $this->salt;
|
return $this->salt;
|
||||||
}
|
}
|
||||||
@@ -269,50 +245,32 @@ class User implements AdvancedUserInterface
|
|||||||
return $this->userJob;
|
return $this->userJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getUsername(): string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUsername()
|
|
||||||
{
|
{
|
||||||
return $this->username;
|
return $this->username;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getUsernameCanonical(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUsernameCanonical()
|
|
||||||
{
|
{
|
||||||
return $this->usernameCanonical;
|
return $this->usernameCanonical;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isAccountNonExpired(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isAccountNonExpired()
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isAccountNonLocked(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isAccountNonLocked()
|
|
||||||
{
|
{
|
||||||
return $this->locked;
|
return $this->locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isCredentialsNonExpired(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isCredentialsNonExpired()
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function isEnabled(): bool
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isEnabled()
|
|
||||||
{
|
{
|
||||||
return $this->enabled;
|
return $this->enabled;
|
||||||
}
|
}
|
||||||
@@ -363,97 +321,84 @@ class User implements AdvancedUserInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCurrentLocation(?Location $currentLocation): User
|
public function setCurrentLocation(?Location $currentLocation): self
|
||||||
{
|
{
|
||||||
$this->currentLocation = $currentLocation;
|
$this->currentLocation = $currentLocation;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setEmail($email): self
|
||||||
* @param $email
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setEmail($email)
|
|
||||||
{
|
{
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setEmailCanonical($emailCanonical): self
|
||||||
* @param $emailCanonical
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setEmailCanonical($emailCanonical)
|
|
||||||
{
|
{
|
||||||
$this->emailCanonical = $emailCanonical;
|
$this->emailCanonical = $emailCanonical;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEnabled(bool $enabled)
|
public function setEnabled(bool $enabled): self
|
||||||
{
|
{
|
||||||
$this->enabled = $enabled;
|
$this->enabled = $enabled;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLabel(string $label): User
|
public function setLabel(string $label): self
|
||||||
{
|
{
|
||||||
$this->label = $label;
|
$this->label = $label;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMainCenter(?Center $mainCenter): User
|
public function setMainCenter(?Center $mainCenter): self
|
||||||
{
|
{
|
||||||
$this->mainCenter = $mainCenter;
|
$this->mainCenter = $mainCenter;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMainLocation(?Location $mainLocation): User
|
public function setMainLocation(?Location $mainLocation): self
|
||||||
{
|
{
|
||||||
$this->mainLocation = $mainLocation;
|
$this->mainLocation = $mainLocation;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMainScope(?Scope $mainScope): User
|
public function setMainScope(?Scope $mainScope): self
|
||||||
{
|
{
|
||||||
$this->mainScope = $mainScope;
|
$this->mainScope = $mainScope;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setPassword($password): self
|
||||||
* @param $password
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setPassword($password)
|
|
||||||
{
|
{
|
||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setRoles($roles): self
|
||||||
* @param $salt
|
{
|
||||||
*
|
$this->roles = $roles;
|
||||||
* @return $this
|
|
||||||
*/
|
return $this;
|
||||||
public function setSalt($salt)
|
}
|
||||||
|
|
||||||
|
public function setSalt($salt): self
|
||||||
{
|
{
|
||||||
$this->salt = $salt;
|
$this->salt = $salt;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUserJob(?UserJob $userJob): User
|
public function setUserJob(?UserJob $userJob): self
|
||||||
{
|
{
|
||||||
$this->userJob = $userJob;
|
$this->userJob = $userJob;
|
||||||
|
|
||||||
@@ -478,12 +423,7 @@ class User implements AdvancedUserInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setUsernameCanonical($usernameCanonical): self
|
||||||
* @param $usernameCanonical
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setUsernameCanonical($usernameCanonical)
|
|
||||||
{
|
{
|
||||||
$this->usernameCanonical = $usernameCanonical;
|
$this->usernameCanonical = $usernameCanonical;
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\CallbackTransformer;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||||
@@ -59,6 +60,16 @@ class UserType extends AbstractType
|
|||||||
return $qb;
|
return $qb;
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
->add('roles', ChoiceType::class, [
|
||||||
|
'required' => true,
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true,
|
||||||
|
'label' => 'Roles',
|
||||||
|
'choices' => [
|
||||||
|
'Usager' => 'ROLE_USER',
|
||||||
|
'Administrateur' => 'ROLE_ADMIN',
|
||||||
|
],
|
||||||
|
])
|
||||||
->add('mainScope', EntityType::class, [
|
->add('mainScope', EntityType::class, [
|
||||||
'label' => 'Main scope',
|
'label' => 'Main scope',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@@ -94,6 +105,18 @@ class UserType extends AbstractType
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// $builder->get('roles')
|
||||||
|
// ->addModelTransformer(new CallbackTransformer(
|
||||||
|
// function ($rolesArray) {
|
||||||
|
// // transform the array to a string
|
||||||
|
// return count($rolesArray)? $rolesArray[0]: null;
|
||||||
|
// },
|
||||||
|
// function ($rolesString) {
|
||||||
|
// // transform the string back to an array
|
||||||
|
// return [$rolesString];
|
||||||
|
// }
|
||||||
|
// ));
|
||||||
|
|
||||||
if ($options['is_creation']) {
|
if ($options['is_creation']) {
|
||||||
$builder->add('plainPassword', RepeatedType::class, [
|
$builder->add('plainPassword', RepeatedType::class, [
|
||||||
'mapped' => false,
|
'mapped' => false,
|
||||||
|
@@ -22,19 +22,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||||||
*/
|
*/
|
||||||
class SectionMenuBuilder implements LocalMenuBuilderInterface
|
class SectionMenuBuilder implements LocalMenuBuilderInterface
|
||||||
{
|
{
|
||||||
/**
|
protected AuthorizationCheckerInterface $authorizationChecker;
|
||||||
* @var AuthorizationCheckerInterface
|
|
||||||
*/
|
|
||||||
protected $authorizationChecker;
|
|
||||||
|
|
||||||
/**
|
protected TranslatorInterface $translator;
|
||||||
* @var TranslatorInterface
|
|
||||||
*/
|
|
||||||
protected $translator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SectionMenuBuilder constructor.
|
|
||||||
*/
|
|
||||||
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator)
|
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator)
|
||||||
{
|
{
|
||||||
$this->authorizationChecker = $authorizationChecker;
|
$this->authorizationChecker = $authorizationChecker;
|
||||||
@@ -54,6 +45,16 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface
|
|||||||
'order' => 0,
|
'order' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) {
|
||||||
|
$menu->addChild($this->translator->trans('Administration'), [
|
||||||
|
'route' => 'chill_main_admin_central',
|
||||||
|
])
|
||||||
|
->setExtras([
|
||||||
|
'icons' => ['home'],
|
||||||
|
'order' => 5,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$menu->addChild($this->translator->trans('Global timeline'), [
|
$menu->addChild($this->translator->trans('Global timeline'), [
|
||||||
'route' => 'chill_center_timeline',
|
'route' => 'chill_center_timeline',
|
||||||
])
|
])
|
||||||
|
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Main;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20220308104030 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE users DROP roles');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add roles property to user';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE users ADD roles JSONB DEFAULT \'["ROLE_USER"]\' NOT NULL');
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user