Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AdherentMessage] Change old Referent space and fix some bugs #3376

Merged
merged 1 commit into from Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion features/republican_silence.feature
Expand Up @@ -16,7 +16,6 @@ Feature:
Examples:
| uri |
| /espace-referent/utilisateurs |
| /espace-referent/utilisateurs/message |
| /espace-referent/evenements/creer |

Scenario Outline: As committee host I cannot access to the committee pages
Expand Down
Expand Up @@ -17,4 +17,9 @@ protected function getMessageType(): string
{
return AdherentMessageTypeEnum::REFERENT;
}

public function disableInProduction(): void
{
// Override parent method for activating this feature in production
}
}
39 changes: 0 additions & 39 deletions src/Controller/EnMarche/ReferentController.php
Expand Up @@ -15,7 +15,6 @@
use AppBundle\Event\EventRegistrationCommand;
use AppBundle\Form\EventCommandType;
use AppBundle\Form\InstitutionalEventCommandType;
use AppBundle\Form\ReferentMessageType;
use AppBundle\Form\ReferentPersonLinkType;
use AppBundle\Form\Jecoute\SurveyFormType;
use AppBundle\InstitutionalEvent\InstitutionalEventCommand;
Expand All @@ -26,8 +25,6 @@
use AppBundle\Referent\ManagedEventsExporter;
use AppBundle\Referent\ManagedInstitutionalEventsExporter;
use AppBundle\Referent\ManagedUsersFilter;
use AppBundle\Referent\ReferentMessage;
use AppBundle\Referent\ReferentMessageNotifier;
use AppBundle\Referent\SurveyExporter;
use AppBundle\Repository\CommitteeRepository;
use AppBundle\Repository\EventRepository;
Expand Down Expand Up @@ -82,42 +79,6 @@ public function usersAction(Request $request): Response
]);
}

/**
* @Route("/utilisateurs/message", name="app_referent_users_message")
* @Method("GET|POST")
*/
public function usersSendMessageAction(Request $request): Response
{
$filter = new ManagedUsersFilter();
$filter->handleRequest($request);

if ($filter->hasToken() && !$this->isCsrfTokenValid(self::TOKEN_ID, $filter->getToken())) {
return $this->redirectToRoute('app_referent_users');
}

$message = ReferentMessage::create($this->getUser(), $filter);

$form = $this->createForm(ReferentMessageType::class, $message);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$this->get(ReferentMessageNotifier::class)->sendMessage($message);
$this->addFlash('info', 'referent.message.success');

return $this->redirect($this->generateUrl('app_referent_users').$filter);
}

$repository = $this->getDoctrine()->getRepository(ReferentManagedUser::class);
$results = $repository->search($this->getUser(), $filter->hasToken() ? $filter : null);

return $this->render('referent/users_message.html.twig', [
'filter' => $filter,
'results_count' => $results->count(),
'message' => $message,
'form' => $form->createView(),
]);
}

/**
* @Route("/evenements", name="app_referent_events")
* @Method("GET")
Expand Down
1 change: 0 additions & 1 deletion src/RepublicanSilence/CheckRepublicanSilenceListener.php
Expand Up @@ -17,7 +17,6 @@ class CheckRepublicanSilenceListener implements EventSubscriberInterface
private const ROUTES = [
// Referent Space
'app_referent_users' => ReferentTagExtractorInterface::ADHERENT_TYPE_REFERENT,
'app_referent_users_message' => ReferentTagExtractorInterface::ADHERENT_TYPE_REFERENT,
'app_referent_events_create' => ReferentTagExtractorInterface::ADHERENT_TYPE_REFERENT,
'app_message_send' => ReferentTagExtractorInterface::ADHERENT_TYPE_REFERENT,

Expand Down
2 changes: 1 addition & 1 deletion templates/referent/_layout.html.twig
Expand Up @@ -47,7 +47,7 @@
},
{
'route': 'app_referent_users',
'label': 'Envoyer un message'
'label': 'Mes adhérents'
},
{
'route': 'app_referent_organizational_chart',
Expand Down
12 changes: 4 additions & 8 deletions templates/referent/users_list.html.twig
Expand Up @@ -181,14 +181,12 @@
</div>

<div class="referent__filters__buttons">
<button type="submit" class="btn b__nudge--bottom-tiny">Filtrer</button>
{% if has_filter %}
<a href="{{ path('app_referent_users') }}" class="btn btn--no-border">
<a href="{{ path('app_referent_users') }}" class="link--blue--dark link--no-decor">
Réinitialiser le filtre
</a>
{% endif %}
<button type="submit" class="btn btn--blue b__nudge--bottom-tiny">
Filtrer pour envoyer un message
</button>
</div>

<input type="hidden" name="{{ constant('PARAMETER_TOKEN', filter) }}" value="{{ filter.token }}" />
Expand All @@ -200,11 +198,9 @@
{% if has_filter %}
<div class="referent__filters__count">
<div class="text--body text--medium-small">{{ results_count }} contact(s) trouvé(s)</div>

<a href="{{ path('app_referent_users_message') ~ filter }}" class="btn btn--primary b__nudge--top-10">
Leur envoyer un message
</a>
</div>
{% else %}
<p>Vous consultez une liste de <b>tous vos adhérents !</b></p>
{% endif %}

<div class="text--center">
Expand Down
72 changes: 0 additions & 72 deletions templates/referent/users_message.html.twig

This file was deleted.

101 changes: 1 addition & 100 deletions tests/Controller/EnMarche/ReferentControllerTest.php
Expand Up @@ -209,7 +209,7 @@ public function testCreateInstitutionalEventFailed()
);
}

public function testSearchUserToSendMail()
public function testSearchAdherent()
{
$this->authenticateAsAdherent($this->client, 'referent@en-marche-dev.fr');

Expand Down Expand Up @@ -312,105 +312,6 @@ public function testSearchUserToSendMail()
$this->assertSame(3, $this->client->getCrawler()->filter('tbody tr.referent__item')->count());
}

public function testCancelSendMail()
{
$this->authenticateAsAdherent($this->client, 'referent@en-marche-dev.fr');

$this->client->request(Request::METHOD_GET, '/espace-referent/utilisateurs');
$data = [
'anc' => 1,
'aic' => 1,
'h' => 1,
's' => 1,
];
$this->client->submit($this->client->getCrawler()->selectButton('Filtrer')->form(), $data);
$this->client->click($this->client->getCrawler()->selectLink('Leur envoyer un message')->link());
$this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse());
$this->assertContains('http://'.$this->hosts['app'].'/espace-referent/utilisateurs/message', $this->client->getRequest()->getUri());

$this->client->click($this->client->getCrawler()->selectLink('Annuler')->link());
$this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse());
$this->assertEquals('http://'.$this->hosts['app'].'/espace-referent/utilisateurs', $this->client->getRequest()->getUri());
}

public function testSendMailFailed()
{
$this->authenticateAsAdherent($this->client, 'referent@en-marche-dev.fr');

$this->client->request(Request::METHOD_GET, '/espace-referent/utilisateurs');
$data = [
'anc' => 1,
'aic' => 1,
'h' => 1,
's' => 1,
];
$this->client->submit($this->client->getCrawler()->selectButton('Filtrer')->form(), $data);
$this->client->click($this->client->getCrawler()->selectLink('Leur envoyer un message')->link());

$data = [];
$this->client->submit($this->client->getCrawler()->selectButton('Envoyer le message')->form(), $data);

$this->assertSame(2, $this->client->getCrawler()->filter('.form__errors')->count());
$this->assertSame('Cette valeur ne doit pas être vide.',
$this->client->getCrawler()->filter('label[for=referent_message_subject] + .form__errors > li')->text());
$this->assertSame('Cette valeur ne doit pas être vide.',
$this->client->getCrawler()->filter('label[for=referent_message_content] + .form__errors > li')->text());
}

public function testSendMailSuccessful()
{
$this->authenticateAsAdherent($this->client, 'referent@en-marche-dev.fr');

$this->client->request(Request::METHOD_GET, '/espace-referent/utilisateurs');
$data = [
'anc' => 1,
'aic' => 1,
'h' => 1,
's' => 1,
];
$this->client->submit($this->client->getCrawler()->selectButton('Filtrer')->form(), $data);
$this->client->click($this->client->getCrawler()->selectLink('Leur envoyer un message')->link());
$this->assertContains('Referent Referent', $this->client->getCrawler()->filter('form')->html());
$this->assertContains('4 marcheur(s)', $this->client->getCrawler()->filter('form')->html());

$data = [];
$data['referent_message']['subject'] = 'Event reminder';
$data['referent_message']['content'] = 'One event is planned.';
$this->client->submit($this->client->getCrawler()->selectButton('Envoyer le message')->form(), $data);

$this->assertResponseStatusCode(Response::HTTP_FOUND, $this->client->getResponse());
$this->client->followRedirect();

$this->assertResponseStatusCode(Response::HTTP_OK, $this->client->getResponse());
$this->assertContains('http://'.$this->hosts['app'].'/espace-referent/utilisateurs?', $this->client->getRequest()->getUri());

$referentMessages = $this
->referentMessageRepository
->createQueryBuilder('m')
->innerJoin('m.from', 'a')
->addSelect('a')
->getQuery()
->getResult()
;

$this->assertCount(1, $referentMessages);

/* @var ReferentManagedUsersMessage */
$message = reset($referentMessages);

$this->assertSame('referent@en-marche-dev.fr', $message->getFrom()->getEmailAddress());
$this->assertSame('Event reminder', $message->getSubject());
$this->assertSame('One event is planned.', $message->getContent());
$this->assertTrue($message->includeAdherentsNoCommittee());
$this->assertTrue($message->includeAdherentsInCommittee());
$this->assertTrue($message->includeHosts());
$this->assertTrue($message->includeSupervisors());
$this->assertEmpty($message->getQueryAreaCode());
$this->assertEmpty($message->getQueryCity());
$this->assertEmpty($message->getQueryId());
$this->assertSame(0, $message->getOffset());
}

public function testFilterAdherents()
{
$this->authenticateAsAdherent($this->client, 'referent@en-marche-dev.fr');
Expand Down