Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new renaissance adherent role
Browse files Browse the repository at this point in the history
ottaviano committed Dec 7, 2022
1 parent acd25bd commit c394492
Showing 9 changed files with 14 additions and 47 deletions.
3 changes: 2 additions & 1 deletion config/packages/security.yaml
Original file line number Diff line number Diff line change
@@ -528,7 +528,8 @@ security:

access_control:
- { path: '^/parametres', roles: [ROLE_USER] }
- { path: '^/espace-adherent', roles: [ROLE_ADHERENT] }
- { path: '^/espace-adherent', host: '%app_host%', roles: [ROLE_ADHERENT] }
- { path: '^/espace-adherent', host: '%renaissance_host%', roles: [ROLE_RENAISSANCE_ADHERENT] }
- { path: '^/admin/login', roles: [IS_AUTHENTICATED_ANONYMOUSLY] }
- { path: '^/admin/(2fa|logout)', role: [IS_AUTHENTICATED_2FA_IN_PROGRESS] }
- { path: '^/admin', roles: [ROLE_ADMIN_DASHBOARD] }
4 changes: 0 additions & 4 deletions src/Controller/EnMarche/AdherentController.php
Original file line number Diff line number Diff line change
@@ -96,10 +96,6 @@ public function pinInterestsAction(
return $this->render('adherent/renaissance_profile.html.twig');
}

if ($isRenaissanceApp && !$adherent->isRenaissanceUser()) {
return $this->redirectToRoute('homepage');
}

$form = $this
->createForm(AdherentInterestsFormType::class, $adherent)
->handleRequest($request)
2 changes: 0 additions & 2 deletions src/Controller/Renaissance/Formation/DownloadController.php
Original file line number Diff line number Diff line change
@@ -7,15 +7,13 @@
use App\Storage\FileRequestHandler;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/espace-adherent/formations/{id}/telecharger", name="app_renaissance_adherent_formation_download", methods={"GET"})
* @Entity("formation", expr="repository.findOneVisible(id)")
* @IsGranted("RENAISSANCE_ADHERENT")
*/
class DownloadController extends AbstractController
{
2 changes: 0 additions & 2 deletions src/Controller/Renaissance/Formation/ListController.php
Original file line number Diff line number Diff line change
@@ -4,14 +4,12 @@

use App\Entity\Adherent;
use App\Repository\AdherentFormation\FormationRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/espace-adherent/formations", name="app_renaissance_adherent_formation_list", methods={"GET"})
* @IsGranted("RENAISSANCE_ADHERENT")
*/
class ListController extends AbstractController
{
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

/**
* @Route("/elections-departementales", name="app_renaissance_departmental_election_lists", methods="GET")
* @IsGranted("ROLE_ADHERENT")
* @IsGranted("ROLE_RENAISSANCE_ADHERENT")
*/
class CandidaciesListController extends AbstractController
{
22 changes: 10 additions & 12 deletions src/Entity/Adherent.php
Original file line number Diff line number Diff line change
@@ -62,8 +62,6 @@
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
@@ -105,7 +103,7 @@
*
* @UniqueTerritorialCouncilMember(qualities={"referent", "lre_manager", "referent_jam"})
*/
class Adherent implements UserInterface, UserEntityInterface, GeoPointInterface, EncoderAwareInterface, MembershipInterface, ReferentTaggableEntity, ZoneableEntity, EntityMediaInterface, EquatableInterface, UuidEntityInterface, MailchimpCleanableContactInterface, PasswordAuthenticatedUserInterface
class Adherent implements UserInterface, UserEntityInterface, GeoPointInterface, MembershipInterface, ReferentTaggableEntity, ZoneableEntity, EntityMediaInterface, UuidEntityInterface, MailchimpCleanableContactInterface, PasswordAuthenticatedUserInterface
{
use EntityCrudTrait;
use EntityIdentityTrait;
@@ -1031,6 +1029,10 @@ public function getRoles()
$roles[] = 'ROLE_ADHERENT';
}

if ($this->isRenaissanceUser()) {
$roles[] = 'ROLE_RENAISSANCE_ADHERENT';
}

if ($this->isReferent()) {
$roles[] = 'ROLE_REFERENT';
}
@@ -1249,22 +1251,18 @@ public function hasLegacyPassword(): bool
return null !== $this->oldPassword;
}

public function getEncoderName(): ?string
public function getSalt()
{
if ($this->hasLegacyPassword()) {
return 'legacy_encoder';
}

return null;
}

public function getSalt()
public function getUserIdentifier(): string
{
return $this->emailAddress;
}

public function getUsername()
public function getUsername(): string
{
return $this->emailAddress;
return $this->getUserIdentifier();
}

public function eraseCredentials()
20 changes: 0 additions & 20 deletions src/Security/Voter/RenaissanceAdherentVoter.php

This file was deleted.

3 changes: 0 additions & 3 deletions tests/Controller/EnMarche/CommitteeControllerTest.php
Original file line number Diff line number Diff line change
@@ -113,9 +113,6 @@ public function testAuthenticatedCommitteeHostCanUnfollowCommittee()

$crawler = $this->client->request(Request::METHOD_GET, $committeeUrl);

// Ex-host should be allow to follow again
$this->assertTrue($this->seeFollowLink($crawler));

$this->logout($this->client);
$this->getEntityManager(Adherent::class)->clear();

3 changes: 1 addition & 2 deletions tests/Controller/Renaissance/AdherentControllerTest.php
Original file line number Diff line number Diff line change
@@ -66,8 +66,7 @@ public function testProfileActionIsNotAccessibleForEMAdherent(string $profilePag

$this->client->request(Request::METHOD_GET, $profilePage);

$this->assertResponseStatusCode(Response::HTTP_FOUND, $this->client->getResponse());
$this->assertClientIsRedirectedTo('http://test.enmarche.code/', $this->client, false);
$this->assertResponseStatusCode(Response::HTTP_FORBIDDEN, $this->client->getResponse());
}

public function provideProfilePage(): \Generator

0 comments on commit c394492

Please sign in to comment.