Skip to content
Snippets Groups Projects
Commit 7815fc9e authored by Sebastien's avatar Sebastien
Browse files

Merge branch 'tuleap-81-allow-a-new-user-to-access-the-capsule-edition-mode' into 'main'

tuleap-81-allow-a-new-user-to-access-the-capsule-edition-mode

See merge request !45
parents 944a6507 f774819b
Branches
Tags
1 merge request!45tuleap-81-allow-a-new-user-to-access-the-capsule-edition-mode
Pipeline #772 passed
......@@ -18,7 +18,7 @@
</head>
<body class="container col-10 col-md-8 col-lg-6 m-auto">
<body class="container col-10 col-md-8 m-auto">
<div class="position-relative d-flex flex-row align-items-center justify-content-center mb-5">
<a href="/my_capsules" class="align-self-center">
<img id="header-memorekall-logo" class="memorekall-logo" src="{{ asset('build/images/MemoRekall.png') }}">
......
......@@ -11,14 +11,14 @@
{% endfor %}
{{ form_start(registrationForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-column justify-content-center'}}) }}
{{ form_row(registrationForm.firstName, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-6'}}) }}
{{ form_row(registrationForm.lastName, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-6'}}) }}
{{ form_row(registrationForm.email, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-6'}}) }}
{{ form_row(registrationForm.plainPassword.first, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-6'}}) }}
{{ form_row(registrationForm.plainPassword.second, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-6'}}) }}
{{ form_row(registrationForm.captcha, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-5 col-6'}}) }}
{{ form_row(registrationForm.firstName, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-12 col-sm-10 col-md-9 col-lg-8 col-xl-7 col-xxl-5'}}) }}
{{ form_row(registrationForm.lastName, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-12 col-sm-10 col-md-9 col-lg-8 col-xl-7 col-xxl-5'}}) }}
{{ form_row(registrationForm.email, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-12 col-sm-10 col-md-9 col-lg-8 col-xl-7 col-xxl-5'}}) }}
{{ form_row(registrationForm.plainPassword.first, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-12 col-sm-10 col-md-9 col-lg-8 col-xl-7 col-xxl-5'}}) }}
{{ form_row(registrationForm.plainPassword.second, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-12 col-sm-10 col-md-9 col-lg-8 col-xl-7 col-xxl-5'}}) }}
{{ form_row(registrationForm.captcha, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-5 col-12 col-sm-10 col-md-9 col-lg-8 col-xl-7 col-xxl-5'}}) }}
{{ form_row(registrationForm.agreeTerms, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-4 col-auto justify-content-center'}, 'label_attr': { 'class' : 'ms-3'}}) }}
{{ form_row(registrationForm.submit, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-5 col-2'}}) }}
{{ form_row(registrationForm.submit, {'row_attr': {'class' : 'form-group d-flex flex-column m-auto mb-5'}}) }}
{{ form_end(registrationForm) }}
</div>
{% endblock %}
......@@ -5,7 +5,6 @@
{% endblock %}
{% block body %}
<form method="post" class="d-flex flex-column justify-content-center">
{% if error %}
<div class="alert alert-danger col-6 m-auto">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
......@@ -13,13 +12,14 @@
<div class="text-center alert alert-warning col-6 m-auto" role="alert" >{{ flashMessage }}</div>
{% endfor %}
<div class="form-group d-flex flex-column m-auto mb-4 mt-4 col-6">
<form method="post" class="d-flex flex-column justify-content-center">
<div class="form-group d-flex flex-column m-auto mb-4 mt-4 col-12 col-sm-10 col-md-9 col-lg-8 col-xl-7 col-xxl-5">
<label for="inputEmail" class="form-label">
{{ 'general.email'|trans }}
</label>
<input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" autocomplete="email" required autofocus>
</div>
<div class="form-group d-flex flex-column m-auto mb-4 col-6">
<div class="form-group d-flex flex-column m-auto mb-4 col-12 col-sm-10 col-md-9 col-lg-8 col-xl-7 col-xxl-5">
<label for="inputPassword" class="form-label">
{{ 'general.password'|trans }}
</label>
......@@ -45,7 +45,7 @@
{{ 'login.forgot_password_link'|trans }}
</a>
<button class="btn btn-primary col-2 m-auto mt-4" type="submit">
<button class="btn btn-primary m-auto mt-4" type="submit">
{{ 'login.log_in'|trans }}
</button>
</form>
......
......@@ -106,8 +106,6 @@ class CapsuleControllerTest extends WebTestCase
$client = static::createClient();
$client->loginUser($this->verified_user);
$client->request('GET', '/capsule/preview/' . $this->created_capsule->getLinkPath());
$this->assertResponseIsSuccessful('The preview should be allowed for none authenticated user');
}
......@@ -128,8 +126,11 @@ class CapsuleControllerTest extends WebTestCase
$client = static::createClient();
$client->request('GET', '/capsule/edit/' . $this->created_capsule->getLinkPath());
$this->assertResponseRedirects('/login', 302, 'An unauthenticated user '
. 'should no access to capsule edition and should be redirected to the login page');
$this->assertResponseRedirects(
'/login',
302,
'An unauthenticated user should no access to capsule edition and should be redirected to the login page'
);
}
public function testLoggedUserShouldAccessToItsCapsuleEdition(): void
......@@ -138,7 +139,8 @@ class CapsuleControllerTest extends WebTestCase
$client->loginUser($this->verified_user);
$client->request('GET', '/capsule/edit/' . $this->created_capsule->getLinkPath());
$this->assertResponseIsSuccessful('An authenticated user should be able to access to the edition of its '
. ' capsules');
$this->assertResponseIsSuccessful(
'An authenticated user should be able to access to the edition of its capsules'
);
}
}
<?php
namespace App\Tests\functional;
use App\Entity\Capsule;
use App\Entity\User;
use App\Repository\CapsuleRepository;
use App\Repository\UserRepository;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class CapsuleEditorControllerTest extends WebTestCase
{
private KernelBrowser $client;
private ObjectManager $object_manager;
private User $user_author;
private User $editor_non_author;
private UserRepository $user_repository; /** @phpstan-ignore-line */
private CapsuleRepository $capsule_repository; /** @phpstan-ignore-line */
private Capsule $capsule;
protected function setUp(): void
{
self::ensureKernelShutdown();
$this->client = static::createClient();
$this->object_manager = $this->client->getContainer()
->get('doctrine')
->getManager();
$this->user_repository = $this->object_manager->getRepository(User::class);
$this->capsule_repository = $this->object_manager->getRepository(Capsule::class);
$this->setUsers();
$this->setCapsule();
}
protected function tearDown(): void
{
parent::tearDown();
self::ensureKernelShutdown();
}
public function testAuthorShouldBeAbleToDeleteACapsule(): void
{
$this->client->loginUser($this->user_author);
$this->client->request('GET', '/capsule/delete/' . $this->capsule->getId());
$this->assertResponseIsSuccessful();
}
public function testEditorNonAuthorShouldNotBeAbleToDeleteACapsule(): void
{
$this->client->loginUser($this->editor_non_author);
$this->client->request('GET', '/capsule/delete/' . $this->capsule->getId());
$this->assertResponseRedirects('/my_capsules', 302);
}
public function testAuthorShouldBeAbleToAddANewEditorForACapsule(): void
{
$uri = '/capsule/' . $this->capsule->getId() . '/editors';
$this->client->loginUser($this->user_author);
$crawler = $this->client->request('GET', $uri);
$this->assertResponseIsSuccessful();
$this->client->enableProfiler();
$submit_button = $crawler->selectButton('Validate');
$form = $submit_button->form();
$form['capsule_editors_form[email]'] = $this->editor_non_author->getEmail();
$this->client->submit($form);
$this->assertResponseRedirects($uri, 302);
$this->client->followRedirect();
$this->assertResponseIsSuccessful($uri);
$capsule_refreshed = $this->capsule_repository->findOneBy(['id' => $this->capsule->getId()]);
if (! $capsule_refreshed instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
$editor = $this->user_repository->findOneBy(['id' => $this->editor_non_author->getId()]);
$this->assertSame($editor, $capsule_refreshed->getEditors()->last());
}
public function testEditorShouldBeAbleToAccessTheCapsuleEditorsPage(): void
{
$this->capsule->addEditor($this->editor_non_author);
$uri = '/capsule/' . $this->capsule->getId() . '/editors';
$this->client->loginUser($this->editor_non_author);
$this->client->request('GET', $uri);
$this->assertResponseIsSuccessful();
}
public function testNonRegisteredUserAddedAsEditorShouldReceiveAnEmail(): void
{
$uri = '/capsule/' . $this->capsule->getId() . '/editors';
$this->client->loginUser($this->user_author);
$crawler = $this->client->request('GET', $uri);
$this->assertResponseIsSuccessful();
$this->client->enableProfiler();
$submit_button = $crawler->selectButton('Validate');
$non_registered_user_email = "non_registered_user@email.fr";
$form = $submit_button->form();
$form['capsule_editors_form[email]'] = $non_registered_user_email;
$this->client->submit($form);
$this->assertResponseRedirects($uri, 302);
$this->assertEmailCount(1);
$emailMessage = $this->getMailerMessage(0);
if (null === $emailMessage) {
throw new \Exception("Email message could not be found");
}
$this->assertEmailAddressContains(
$emailMessage,
'To',
$non_registered_user_email
);
$this->client->followRedirect();
$this->assertResponseIsSuccessful($uri);
}
public function testRegisteredUserShouldReceiveAnEmailWithCapsuleEditionLink(): void
{
$uri = '/capsule/' . $this->capsule->getId() . '/editors';
$this->client->loginUser($this->user_author);
$crawler = $this->client->request('GET', $uri);
$this->assertResponseIsSuccessful();
$this->client->enableProfiler();
$submit_button = $crawler->selectButton('Validate');
$form = $submit_button->form();
$form['capsule_editors_form[email]'] = $this->editor_non_author->getEmail();
$this->client->submit($form);
$this->assertResponseRedirects($uri, 302);
$this->assertEmailCount(1);
$emailMessage = $this->getMailerMessage(0);
if (null === $emailMessage) {
throw new \Exception("Email message could not be found");
}
$this->assertEmailAddressContains(
$emailMessage,
'To',
$this->editor_non_author->getEmail()
);
$this->client->followRedirect();
$this->assertResponseIsSuccessful($uri);
}
public function testAlreadyAddedEditorShouldNotReceiveAnEmail(): void
{
$this->capsule->addEditor($this->editor_non_author);
$this->object_manager->persist($this->capsule);
$this->object_manager->flush();
$this->assertContains($this->editor_non_author, $this->capsule->getEditors()->toArray());
$uri = '/capsule/' . $this->capsule->getId() . '/editors';
$this->client->loginUser($this->user_author);
$crawler = $this->client->request('GET', $uri);
$this->assertResponseIsSuccessful();
$this->client->enableProfiler();
$submit_button = $crawler->selectButton('Validate');
$form = $submit_button->form();
$form['capsule_editors_form[email]'] = $this->editor_non_author->getEmail();
$this->client->submit($form);
$this->assertEmailCount(0);
$this->assertResponseRedirects($uri, 302);
$this->client->followRedirect();
$this->assertResponseIsSuccessful($uri);
}
private function setUsers(): void
{
$verified_user_1 = $this->user_repository
->findOneBy(['email' => 'defaultUser@localhost.com']);
if (! $verified_user_1 instanceof User) {
throw new \Exception("User does not exist.");
}
$this->user_author = $verified_user_1;
$verified_user_2 = $this->user_repository
->findOneBy(['email' => 'defaultUser2@localhost.com']);
if (! $verified_user_2 instanceof User) {
throw new \Exception("User does not exist.");
}
$this->editor_non_author = $verified_user_2;
}
private function setCapsule(): void
{
$capsule = $this->capsule_repository->findOneBy(['name' => 'Pomme']);
if (! $capsule instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
$this->capsule = $capsule;
}
}
......@@ -62,13 +62,14 @@ capsule:
video_url: Youtube or Vimeo video URL
created_success: Capsule capsule_name was created successfully
no_edition_access: No edition access
edition_not_allowed: You are not allowed to edit this capsule
contact_capsule_author_for_access: Please contact the author to gain access the edition mode
not_found: The project doesn't exist
edit_permissions:
link: Edit permissions
edit:
link: Edit capsule
not_allowed: You are not allowed to edit this capsule
not_found: The capsule was not found
duplicate:
link: Duplicate capsule
title: Duplicate capsule
......@@ -107,3 +108,31 @@ user:
updated_success: The password has been updated
edit_profile: Edit my profile
edit_password: Edit my password
editors:
title: Editors
title_name: Editors of capsule %capsule_name%
add_email_address: Add new editor with email address
current_editors_title: Current editors
pending_editors_title: Pending editors
user_not_editor_error: You are not editor of the capsule
add:
pending_editor:
success: The user user_email has been added to pending editor list.
He will receive an email to invite him register on MemoRekall and to inform him he has been added as an editor of this capsule.
already_added: The user user_email has already been added to pending editor list
email:
title: Invitation to edit a MemoRekall capsule
text: You have been added by %user_name% as editor of the capsule "%capsule_name%".
In order to access and edit it, you first need to register on MemoRekall. Please follow this link to
link: https://project.memorekall.com/register/
link_name: register
user:
success: The user user_email is now an editor of the capsule capsule_name.
He will receive an email to inform him he has been added as an editor of this capsule.
already_added: The user user_email is already an editor of this capsule
email:
title: New capsule on your list
text: You have been add by %user_name% as editor of the capsule "%capsule_name%".
You can now access and edit it. You will find the capsule in your capsule list.
link: Go to capsule edition page
......@@ -60,12 +60,13 @@ capsule:
video_url: URL de la video Youtube ou Vimeo
created_success: La capsule capsule_name a été créée
no_edition_access: Pas d'accès au mode édition
edition_not_allowed: Vous n'êtes pas autorisé a modifier cette capsule
contact_capsule_author_for_access: Veuillez contacter l'auteur de la capsule pour lui demander son accès en mode édition
edit_permissions:
link: Modifier les permissions
edit:
link: Modifier la capsule
not_allowed: Vous n'êtes pas autorisé a modifier cette capsule
not_found: La capsule n'existe pas
duplicate:
link: Dupliquer la capsule
title: Dupliquer la capsule
......@@ -105,3 +106,31 @@ user:
updated_success: Votre mot de passe a bien été modifié
edit_profile: Modifier mon mot de passe
edit_password: Modifier mon mot de passe
editors:
title: Editeurs d'une capsule
title_name: Editeurs de la capsule %capsule_name%
add_email_address: Ajouter un nouvel editeur avec son adresse e-mail
current_editors_title: Editeurs actuels
pending_editors_title: Editeurs en attente de confirmation
user_not_editor_error: Vous n'êtes pas éditeur de la capsule
add:
pending_editor:
success: L'utilisateur user_email a bien été ajouté à la liste des editeurs en attente
Il recevera un e-mail l'invitant à créer un compte MemoRekall et l'informant qu'il a été ajouté en tant qu'éditeur de la capsule.
already_added: L'utilisateur user_email a déjà été ajouté à la liste des éditeurs en attente
email:
title: Invitation pour éditer une capsule sur MemoRekall
text: Vous avez été ajouté par %user_name% en tant qu'éditeur de la capsule %capsule_name%.
Avant de pouvoir y accéder et la modifier, vous devez d'abord créer un compte sur MemoRekall. Veuillez suivre ce lien pour
link: https://project.memorekall.com/register/
link_name: créer votre compte
user:
success: L'utilisateur user_email est maintenant éditeur de la capsule capsule_name.
Il recevera un e-mail l'informant qu'il a été ajouté en tant qu'éditeur de la capsule.
already_added: L'utilisateur user_email est déjà editeur de la capsule
email:
title: Nouvelle capsule dans votre liste
text: Vous avez été ajouté par %user_name% en tant qu'éditeur de la capsule "%capsule_name%".
Vous pouvez maintenant y accéder et l'éditer. Vous la retrouverez dans la liste de vos capsules.
link: Se rendre sur la page d'édition de la capsule
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment