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

Feature/publication state #274

Open
wants to merge 19 commits into
base: master-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
26d79b6
Add states Draft, Scheduled, Published to events only first to test
PhilippeFerreiraDeSousa Oct 14, 2017
57dcede
Déplacement de l'état de publication sur Post. Arrangement formulaire…
PhilippeFerreiraDeSousa Oct 15, 2017
8be81e6
Creation and modification of events work, cannot modify to inferior s…
PhilippeFerreiraDeSousa Oct 15, 2017
adf716a
Publications with ribbon, draft events from other club members don't …
PhilippeFerreiraDeSousa Oct 17, 2017
dbcd096
La modification des events/news se fait directement à l'endroit des p…
PhilippeFerreiraDeSousa Oct 19, 2017
4d40da7
add cancelation of publication edit
PhilippeFerreiraDeSousa Oct 19, 2017
d3187ad
remove alertify ask for mail
PhilippeFerreiraDeSousa Oct 19, 2017
ab5969a
Add ClubUser fixture, remove deprecated doctrine assertion constraint
PhilippeFerreiraDeSousa Oct 19, 2017
0e72392
Change publication ticket color to publication state color
PhilippeFerreiraDeSousa Oct 19, 2017
e81e438
Fix multiple pagination, add /events/check-dates/{slug} to check for …
PhilippeFerreiraDeSousa Oct 20, 2017
ca0a65a
Small front factorization
PhilippeFerreiraDeSousa Oct 21, 2017
4a70526
Back propre sur les requêtes d'events/newsitems qui ne sont pas des b…
PhilippeFerreiraDeSousa Oct 21, 2017
e0928be
Adaptation aux users de l'administration
PhilippeFerreiraDeSousa Oct 21, 2017
469d085
Oops typos
PhilippeFerreiraDeSousa Oct 21, 2017
cc330f1
change style
PhilippeFerreiraDeSousa Oct 29, 2017
daad1bc
migrate data send_mail into publicationState, move getEventCheckDates…
PhilippeFerreiraDeSousa Oct 30, 2017
c1627b8
fix unregistered repos, bfix bug changing a publication slug twice in…
PhilippeFerreiraDeSousa Oct 30, 2017
a82e2fc
fix data migration down
PhilippeFerreiraDeSousa Oct 30, 2017
a2ce603
Not working version on /club/slug/newsitems but checking totalpages i…
PhilippeFerreiraDeSousa Oct 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions back/app/DoctrineMigrations/Version20171015200834.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20171015200834 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE Post ADD publicationState VARCHAR(255) DEFAULT \'Published\', DROP send_mail');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce qu'on a pas envie d'attribuer le bon publishedState suivant la valeur actuelle de send_mail lors de la migration ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui oui, faut faire des boucles php ici avec des addSql partout ? o:)

}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE Post ADD send_mail TINYINT(1) DEFAULT NULL, DROP publicationState');
}
}
4 changes: 2 additions & 2 deletions back/src/KI/CoreBundle/Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class ResourceController extends LikeableController
* @param boolean $auth Un override éventuel pour le check des permissions
* @return Response
*/
public function getAll($auth = false)
public function getAll($auth = false, array $findBy = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi un $findBy sur le getAll des resources ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je l'utilise pour requêter les messages à /newsitems?name=message

if ($request->query->get('name') == 'message') {
      $findBy = array('name' => 'message');
      return $this->getAll($this->is('EXTERIEUR'), $findBy);
}

En soi donner "message" comme titre de news aux messages de l'accueil est très douteux

{
$this->trust(!$this->is('EXTERIEUR') || $auth);

$paginateHelper = $this->get('ki_core.helper.paginate');
extract($paginateHelper->paginateData($this->repository));
extract($paginateHelper->paginateData($this->repository, $findBy));

list($results, $links, $count) = $paginateHelper->paginateView($results, $limit, $page, $totalPages, $count);

Expand Down
5 changes: 0 additions & 5 deletions back/src/KI/CoreBundle/Helper/PaginateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public function paginateData(EntityRepository $repository, array $findBy = [])
$queryBuilder = $repository->createQueryBuilder('o');
$request = $this->request->query;

// On s'assure de bien recevoir des arrays
foreach ($findBy as $key => $value) {
$findBy[$key] = array($value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

À garder avec un truc du genre $aRecords = is_array($aRecords) ? $aRecords : array($aRecords);

}

// On récupère les paramètres de la requête
$page = $request->has('page') ? $request->get('page') : 1;
$limit = $request->has('limit') ? $request->get('limit') : 100;
Expand Down
43 changes: 41 additions & 2 deletions back/src/KI/PublicationBundle/Controller/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ public function setContainer(ContainerInterface $container = null)
* @Route("/events")
* @Method("GET")
*/
public function getEventsAction()
public function getEventsAction(Request $request)
{
return $this->getAll();
$events = $this->repository->getAllowedEvents(
$this->getUser()->getId(),
$request->query->get('publicationState'),
$request->query->get('limit'),
$request->query->get('page'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problème d'indentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarde bien, les lignes doublements indentées sont en argument de getAllowedEvents


return $this->json($events);
}

/**
Expand All @@ -63,6 +69,9 @@ public function getEventsAction()
public function getEventAction($slug)
{
$event = $this->getOne($slug);
if ($event->getPublicationState() == 'Draft' && !$this->isClubMember($event->getAuthorClub())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le publicationState devrait être slug si possible -> draft

Du coup, si c'est scheduled, tout le monde peut accéder à la fiche de l'événement ? Quelle différence avec published ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui, je vais les mettre en slug. C'était comme ça à la base par cohérence avec l'entryMethod des Events 'Shotgun', 'Libre', 'Ferie' mais c'est plus très justifié maintenant

Ce qui est published est sur le newsfeed et le calendrier, ce qui est scheduled n'est que sur le newsfeed des membre de l'asso qui peuvent l'éditer et sur le calendrier (mais accessible par recherche dans la topbar et par requête au back)

return $this->json('Tu n\'es pas autorisé à lire ce brouillon !', 403);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw $this->createAccessDeniedException('You cannot access this page!');

}

return $this->json($event);
}
Expand Down Expand Up @@ -159,6 +168,36 @@ public function deleteEventAction($slug)
return $this->json(null, 204);
}

/**
* @ApiDoc(
* description="Renvoie la liste des événements qui chevauchent un créneau horaire",
* statusCodes={
* 200="Requête traitée avec succès",
* 401="Une authentification est nécessaire pour effectuer cette action",
* 503="Service temporairement indisponible ou en maintenance",
* },
* section="Publications"
* )
* @Route("/events/{slug}/check-dates")
* @Method("GET")
*/
public function getEventCheckDatesAction(Request $request, $slug)
{
$startDate = $request->query->get('startDate');
$endDate = $request->query->get('endDate');
$events = $this->repository->findBy(array('publicationState' => array('Scheduled', 'Published', 'Emailed')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

la notation array est dépréciée, utilise [] et indente

$matchedEvents = array();
foreach ($events as $event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qui a dit que c'était une bonne idée de boucler sur l'intégralité des entrées de la base de données ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui, il faut mettre cette logique dans une requête DQL dans le repository

$eventStartDate = $event->getStartDate();
$eventEndDate = $event->getEndDate();
if ($startDate < $eventEndDate && $eventStartDate < $endDate && $slug != $event->getSlug()) {
$matchedEvents[] = $event;
}
}
return $this->json($matchedEvents);

}

/**
* @ApiDoc(
* description="Shotgunne un événement",
Expand Down
21 changes: 19 additions & 2 deletions back/src/KI/PublicationBundle/Controller/NewsitemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

class NewsitemsController extends ResourceController
{
Expand All @@ -32,9 +34,21 @@ public function setContainer(ContainerInterface $container = null)
* @Route("/newsitems")
* @Method("GET")
*/
public function getNewsitemsAction()
public function getNewsitemsAction(Request $request)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce que tous les newsitems ne seraient pas des événements ? Pourquoi s'emmerder à dupliquer le code partout ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca aurait été trop logique, Newsitem et Event héritent tous deux de Post

{
return $this->getAll($this->is('EXTERIEUR'));
if ($request->query->get('name') == 'message') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce que les messages sont vraiment utiles sur uPont ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non effectivement, on aurait pu en faire quelque chose mais ils n'ont même pas d'existence réel dans la bdd. Mais bon ils ne font de mal à personne où ils sont

$findBy = array('name' => 'message');
return $this->getAll($this->is('EXTERIEUR'), $findBy);
}
else {
$newsitems = $this->repository->getAllowedNewsitems(
$this->getUser()->getId(),
$request->query->get('publicationState'),
$request->query->get('limit'),
$request->query->get('page'));

return $this->json($newsitems);
}
}

/**
Expand All @@ -56,6 +70,9 @@ public function getNewsitemsAction()
public function getNewsitemAction($slug)
{
$newsitem = $this->getOne($slug, $this->is('EXTERIEUR'));
if ($newsitem->getPublicationState() == 'Draft' && !$this->isClubMember($newsitem->getAuthorClub())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

return $this->json('Tu n\'es pas autorisé à lire ce brouillon !', 403);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

}

return $this->json($newsitem);
}
Expand Down
14 changes: 7 additions & 7 deletions back/src/KI/PublicationBundle/DataFixtures/ORM/LoadEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public function load(ObjectManager $manager)
$event->setAuthorClub($this->getReference('club-ki'));
$event->setAuthorUser($this->getReference('user-trancara'));
$event->setEntryMethod('Libre');
$event->setPublicationState('Emailed');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify

$event->setStartDate(mktime(0, 0, 0) + 36*3600);
$event->setEndDate(mktime(0, 0, 0) + 37.5*3600);
$event->setPlace('P102');
$event->setSendMail(true);
$event->addAttendee($this->getReference('user-taquet-c'));
$event->addAttendee($this->getReference('user-de-boisc'));
$event->setLikes([$this->getReference('user-taquet-c')]);
Expand All @@ -35,10 +35,10 @@ public function load(ObjectManager $manager)
$event->setAuthorClub($this->getReference('club-ki'));
$event->setAuthorUser($this->getReference('user-muzardt'));
$event->setEntryMethod('Libre');
$event->setPublicationState('Scheduled');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify

$event->setStartDate(mktime(0, 0, 0) + 36*3600);
$event->setEndDate(mktime(0, 0, 0) + 36.5*3600);
$event->setPlace('P402');
$event->setSendMail(true);
$event->addAttendee($this->getReference('user-taquet-c'));
$event->addAttendee($this->getReference('user-de-boisc'));
$event->addAttendee($this->getReference('user-muzardt'));
Expand All @@ -51,11 +51,11 @@ public function load(ObjectManager $manager)
$event->setAuthorClub($this->getReference('club-mediatek'));
$event->setAuthorUser($this->getReference('user-trancara'));
$event->setEntryMethod('Shotgun');
$event->setPublicationState('Emailed');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify

$event->setStartDate(1413918000);
$event->setEndDate(1413930600);
$event->setShotgunDate(1413396000);
$event->setPlace('P102');
$event->setSendMail(false);
$event->addAttendee($this->getReference('user-taquet-c'));
$event->addAttendee($this->getReference('user-trancara'));
$event->addAttendee($this->getReference('user-guerinh'));
Expand All @@ -68,10 +68,10 @@ public function load(ObjectManager $manager)
$event->setAuthorClub($this->getReference('club-pep'));
$event->setAuthorUser($this->getReference('user-guerinh'));
$event->setEntryMethod('Libre');
$event->setPublicationState('Draft');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify

$event->setStartDate(1413999000);
$event->setEndDate(1414009800);
$event->setPlace('Amphi Navier');
$event->setSendMail(false);
$event->addAttendee($this->getReference('user-taquet-c'));
$event->addAttendee($this->getReference('user-guerinh'));
$manager->persist($event);
Expand All @@ -83,10 +83,10 @@ public function load(ObjectManager $manager)
$event->setAuthorClub($this->getReference('club-bde'));
$event->setAuthorUser($this->getReference('user-dziris'));
$event->setEntryMethod('Libre');
$event->setPublicationState('Published');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify

$event->setStartDate(mktime(0, 0, 0) + 9*3600);
$event->setEndDate(mktime(0, 0, 0) + 15*3600);
$event->setPlace('Salle Polyvalente');
$event->setSendMail(false);
$event->addAttendee($this->getReference('user-taquet-c'));
$event->addAttendee($this->getReference('user-trancara'));
$event->addAttendee($this->getReference('user-guerinh'));
Expand All @@ -102,11 +102,11 @@ public function load(ObjectManager $manager)
$event->setAuthorClub($this->getReference('club-bda'));
$event->setAuthorUser($this->getReference('user-donat-bb'));
$event->setEntryMethod('Shotgun');
$event->setPublicationState('Scheduled');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify

$event->setStartDate(mktime(0, 0, 0) + 40*3600);
$event->setEndDate(mktime(0, 0, 0) + 44*3600);
$event->setShotgunDate(time() + 3600);
$event->setPlace('Opéra Bastille');
$event->setSendMail(true);
$event->setShotgunLimit(12);
$event->setShotgunText('Viens chercher la place chez moi');
$manager->persist($event);
Expand All @@ -115,11 +115,11 @@ public function load(ObjectManager $manager)
$event->setName('Vacances de Noël');
$event->setText('I\'m fucking Santa Claus bitchies!');
$event->setPlace('Ta mère');
$event->setSendMail(false);
$event->setDate(1421778600);
$event->setAuthorClub($this->getReference('club-ki'));
$event->setAuthorUser($this->getReference('user-trancara'));
$event->setEntryMethod('Ferie');
$event->setPublicationState('Draft');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify

$event->setStartDate(time() - 400*3600);
$event->setEndDate(time() + 600*3600);
$manager->persist($event);
Expand Down
33 changes: 21 additions & 12 deletions back/src/KI/PublicationBundle/DataFixtures/ORM/LoadNewsitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function load(ObjectManager $manager)
$newsitem->setDate(1414242424);
$newsitem->setAuthorClub($this->getReference('club-ki'));
$newsitem->setAuthorUser($this->getReference('user-taquet-c'));
$newsitem->setPublicationState('Published');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slugify

$newsitem->setLikes([$this->getReference('user-taquet-c')]);
$newsitem->setDislikes([$this->getReference('user-trancara')]);
$manager->persist($newsitem);
Expand All @@ -27,6 +28,7 @@ public function load(ObjectManager $manager)
$newsitem->setDate(1418325122);
$newsitem->setAuthorClub($this->getReference('club-ki'));
$newsitem->setAuthorUser($this->getReference('user-trancara'));
$newsitem->setPublicationState('Draft');
$newsitem->setImage($this->getReference('image-newsitem-git'));
$manager->persist($newsitem);

Expand All @@ -36,6 +38,7 @@ public function load(ObjectManager $manager)
$newsitem->setDate(1417532897);
$newsitem->setAuthorClub($this->getReference('club-ki'));
$newsitem->setAuthorUser($this->getReference('user-trancara'));
$newsitem->setPublicationState('Scheduled');
$manager->persist($newsitem);

$newsitem = new Newsitem();
Expand All @@ -44,6 +47,7 @@ public function load(ObjectManager $manager)
$newsitem->setDate(1412831521);
$newsitem->setAuthorClub($this->getReference('club-bde'));
$newsitem->setAuthorUser($this->getReference('user-dziris'));
$newsitem->setPublicationState('Emailed');
$newsitem->setDislikes([$this->getReference('user-trancara'), $this->getReference('user-dziris')]);
$newsitem->addComment($this->getReference('comment-genial'));
$newsitem->addComment($this->getReference('comment-rage'));
Expand All @@ -56,6 +60,7 @@ public function load(ObjectManager $manager)
$newsitem->setDate(1414462150);
$newsitem->setAuthorClub($this->getReference('club-pep'));
$newsitem->setAuthorUser($this->getReference('user-guerinh'));
$newsitem->setPublicationState('Draft');
$manager->persist($newsitem);

$newsitem = new Newsitem();
Expand All @@ -65,6 +70,20 @@ public function load(ObjectManager $manager)
$newsitem->setAuthorClub($this->getReference('club-bde'));
$newsitem->setAuthorUser($this->getReference('user-dziris'));
$newsitem->setImage($this->getReference('image-newsitem-pulls'));
$newsitem->setPublicationState('Published');
$manager->persist($newsitem);

$newsitem = new Newsitem();
$newsitem->setName('Le béton c\'est bon.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilise des guillemets double au lieu de tout échapper...

$newsitem->setText('L\'acier aussi, c\'est complètement METAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL.');
$newsitem->setDate(time() - 21*3600);
$newsitem->setAuthorUser($this->getReference('user-gcc'));
$newsitem->setAuthorClub($this->getReference('club-gcc'));
$newsitem->setLikes([$this->getReference('user-taquet-c')]);
$newsitem->setDislikes([$this->getReference('user-trancara'), $this->getReference('user-dziris')]);
$newsitem->setPublicationState('Emailed');
$newsitem->addComment($this->getReference('comment-rage'));
$newsitem->addComment($this->getReference('comment-arret'));
$manager->persist($newsitem);

// Messages persos
Expand All @@ -74,25 +93,15 @@ public function load(ObjectManager $manager)
$newsitem->setDate(time() - 3600);
$newsitem->setAuthorUser($this->getReference('user-trancara'));
$newsitem->setImage($this->getReference('image-game-age-of-empires-2'));
$newsitem->setPublicationState('Published');
$manager->persist($newsitem);

$newsitem = new Newsitem();
$newsitem->setName('message');
$newsitem->setText('[Le rêve de Jeanine]<br>Est ce que vous voyez la pluie tomber sur notre calme Champs sur Marne? Vous êtes vous seulement posés la question, ne serait-ce qu\'une fois, de ce que toute cette eau devenait? Cette nonchalance de votre part est permise seulement par la puissance de nouveaux radars qui mesurent précisément la minute et la rue où va se déverser le prochain orage sur les villes d\'Ile de France.');
$newsitem->setDate(time() - 42*3600);
$newsitem->setAuthorUser($this->getReference('user-dziris'));
$manager->persist($newsitem);

$newsitem = new Newsitem();
$newsitem->setName('Le béton c\'est bon.');
$newsitem->setText('L\'acier aussi, c\'est complètement METAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL.');
$newsitem->setDate(time() - 21*3600);
$newsitem->setAuthorUser($this->getReference('user-gcc'));
$newsitem->setAuthorClub($this->getReference('club-gcc'));
$newsitem->setLikes([$this->getReference('user-taquet-c')]);
$newsitem->setDislikes([$this->getReference('user-trancara'), $this->getReference('user-dziris')]);
$newsitem->addComment($this->getReference('comment-rage'));
$newsitem->addComment($this->getReference('comment-arret'));
$newsitem->setPublicationState('Published');
$manager->persist($newsitem);

$manager->flush();
Expand Down
Loading