From 5847dd3572caf06c0e0d5e307241c3b6bc3f8611 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 27 Apr 2017 19:17:19 +0200 Subject: MOAR WIP Signed-off-by: Thomas Citharel --- .../CoreBundle/Controller/EntryController.php | 89 ++++++++++ .../CoreBundle/Controller/ExportController.php | 2 +- src/Wallabag/CoreBundle/Entity/Entry.php | 18 +- .../CoreBundle/Form/Type/EditGroupSharesType.php | 43 +++++ .../CoreBundle/Repository/EntryRepository.php | 13 ++ .../Resources/translations/messages.en.yml | 26 +++ .../Resources/translations/messages.fr.yml | 27 +++ .../themes/material/Entry/_share_groups.html.twig | 24 +++ .../views/themes/material/Entry/entry.html.twig | 11 ++ .../views/themes/material/layout.html.twig | 6 +- .../GroupBundle/Controller/ManageController.php | 184 +++++++++++++++++++++ src/Wallabag/GroupBundle/Form/UserGroupType.php | 6 +- .../GroupBundle/Resources/config/services.yml | 7 +- .../Resources/views/Manage/edit_user.html.twig | 26 +++ .../Resources/views/Manage/index.html.twig | 29 +++- .../Resources/views/Manage/manage.html.twig | 102 ++++++++++++ .../Resources/views/Manage/requests.html.twig | 31 ++++ src/Wallabag/UserBundle/Entity/User.php | 9 + .../UserBundle/Repository/UserRepository.php | 10 +- .../Resources/views/Manage/index.html.twig | 2 +- 20 files changed, 651 insertions(+), 14 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Form/Type/EditGroupSharesType.php create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_share_groups.html.twig create mode 100644 src/Wallabag/GroupBundle/Resources/views/Manage/edit_user.html.twig create mode 100644 src/Wallabag/GroupBundle/Resources/views/Manage/manage.html.twig create mode 100644 src/Wallabag/GroupBundle/Resources/views/Manage/requests.html.twig diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index fafa49f1..f1376f43 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -4,11 +4,15 @@ namespace Wallabag\CoreBundle\Controller; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; +use Pagerfanta\Pagerfanta; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Form\Type\EditGroupSharesType; use Wallabag\CoreBundle\Form\Type\EntryFilterType; use Wallabag\CoreBundle\Form\Type\EditEntryType; use Wallabag\CoreBundle\Form\Type\NewEntryType; @@ -16,6 +20,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; use Wallabag\CoreBundle\Event\EntrySavedEvent; use Wallabag\CoreBundle\Event\EntryDeletedEvent; use Wallabag\CoreBundle\Form\Type\SearchEntryType; +use Wallabag\GroupBundle\Entity\Group; class EntryController extends Controller { @@ -604,4 +609,88 @@ class EntryController extends Controller { return $this->showEntries('untagged', $request, $page); } + + /** + * @Route("/group-articles/{group}/{page}", name="group-presentations", defaults={"page" = "1"}, requirements={"page": "\d+", "group": "\d+"}) + * + * @param Request $request + * @param Group $group + * @param int $page + * @return Response + */ + public function showGroupSharedTemplatesAction(Request $request, Group $group, int $page) + { + if (!$this->getUser()->inGroup($group)) { + throw $this->createAccessDeniedException(); + } + + $repository = $this->get('wallabag_core.entry_repository'); + + /** @var QueryBuilder $entries */ + $entries = $repository->findByGroup($group->getId()); + + $pagerAdapter = new DoctrineORMAdapter($entries->getQuery(), true, false); + $pagerFanta = new Pagerfanta($pagerAdapter); + $pagerFanta->setMaxPerPage(9); + + $form = $this->createForm(EntryFilterType::class); + + if ($request->query->has($form->getName())) { + // manually bind values from the request + $form->submit($request->query->get($form->getName())); + + // build the query from the given form object + $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb); + } + + $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); + + try { + $pagerFanta->setCurrentPage($page); + } catch (OutOfRangeCurrentPageException $e) { + if ($page > 1) { + return $this->redirect($this->generateUrl('group-presentations', [ + 'page' => $pagerFanta->getNbPages(), + 'group' => $group->getId() + ]), 302); + } + } + + return $this->render('WallabagCoreBundle:Entry:entries.html.twig', [ + 'form' => $form->createView(), + 'entries' => $pagerFanta, + 'currentPage' => $page, + 'searchTerm' => $searchTerm, + ]); + } + + /** + * + * @Route("/entry/group-shares/{entry}", name="group-shares-entry") + * + * @param Request $request + * @param Entry $entry + * @return Response + */ + public function groupShareAction(Request $request, Entry $entry) + { + $this->checkUserAction($entry); + + $form = $this->createForm(EditGroupSharesType::class, $entry, ['groups' => $this->getUser()->getGroups()]); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); + } + + return $this->render('WallabagCoreBundle:Entry:_share_groups.html.twig', [ + 'form' => $form->createView(), + 'entry' => $entry, + ]); + } } diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index fda04cfb..4bb2b706 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php @@ -47,7 +47,7 @@ class ExportController extends Controller * * @Route("/export/{category}.{format}", name="export_entries", requirements={ * "format": "epub|mobi|pdf|json|xml|txt|csv", - * "category": "all|unread|starred|archive|tag_entries|untagged|search" + * "category": "all|unread|starred|archive|tag_entries|untagged|search|group-presentations" * }) * * @return \Symfony\Component\HttpFoundation\Response diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 84555b36..028eeb52 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -235,7 +235,7 @@ class Entry /** * @var ArrayCollection - * @ORM\ManyToMany(targetEntity="Wallabag\GroupBundle\Entity\Group", inversedBy="presentations", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="Wallabag\GroupBundle\Entity\Group", inversedBy="entries", cascade={"persist"}) */ private $groupShares; @@ -784,4 +784,20 @@ class Entry return $this; } + + /** + * @return ArrayCollection + */ + public function getGroupShares() + { + return $this->groupShares; + } + + /** + * @param ArrayCollection $groupShares + */ + public function setGroupShares($groupShares) + { + $this->groupShares = $groupShares; + } } diff --git a/src/Wallabag/CoreBundle/Form/Type/EditGroupSharesType.php b/src/Wallabag/CoreBundle/Form/Type/EditGroupSharesType.php new file mode 100644 index 00000000..2c2e3b36 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/EditGroupSharesType.php @@ -0,0 +1,43 @@ +add('groupshares', EntityType::class, [ + 'required' => true, + 'class' => Group::class, + 'choices' => $options['groups'], + 'multiple' => true, + 'expanded' => true, + ]) + ->add('save', SubmitType::class, [ + 'label' => 'Share', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Entry::class, + ]); + $resolver->setRequired('groups'); + } + + public function getBlockPrefix() + { + return 'group_shares'; + } +} diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 9bda4e15..ade3d6bc 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -414,4 +414,17 @@ class EntryRepository extends EntityRepository ->getQuery() ->getResult(); } + + /** + * Find all entries for a group + * + * @param $groupId + * @return \Doctrine\ORM\QueryBuilder + */ + public function findByGroup($groupId) + { + return $this->createQueryBuilder('p') + ->innerJoin('p.groupShares', 'g', 'WITH', 'g.id = :group') + ->setParameter(':group', $groupId); + } } diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 8f507c40..94bce434 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -224,6 +224,7 @@ entry: delete_public_link: 'delete public link' export: 'Export' print: 'Print' + groups: Groups problem: label: 'Problems?' description: 'Does this article appear wrong?' @@ -515,6 +516,31 @@ group: delete: Delete delete_confirm: Are you sure? back_to_list: Back to list + role_label: Default roles + access_label: Access + password_label: Password (if applicable) + + roles: + readonly: Read only + write: Write access + manage_entries: Managing articles + manage_users: Managing members + admin: Administrator + access: + open: Open + request: On request + password: With password + invitation: Upon invitation + hidden: Upon invitation and private + tab_menu: + public: Public groups + own: My groups + manage: + label: Manage this group + entries: + label: Entries shared with this group + leave: + label: Leave user: page_title: Users management diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index d909cf15..007d5b2a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -240,6 +240,7 @@ entry: delete_public_link: "Supprimer le lien public" export: "Exporter" print: "Imprimer" + groups: Groupes problem: label: "Un problème ?" description: "Est-ce que cet article s’affiche mal ?" @@ -549,6 +550,32 @@ group: tab_menu: public: Groupes publics own: Mes groupes + requests: + list: Liste des requêtes + sent: Requête envoyée + username: Utilisateur + action: Action + manage: + label: Gérer le groupe + title: Gérer le groupe + entries: + label: Liste des articles partagés avec ce groupe + leave: + label: Sortir de ce groupe + user: + inGroup: "{0}Il n'y a personne dans ce groupe|{1}Vous êtes tout seul dans ce groupe|]1,Inf[Vous êtes %count% utilisateurs dans ce groupe" + notInGroup: "{0}Il n'y a personne dans ce groupe|{1}Il y a un seul utilisateur dans ce groupe|]1,Inf[%count% utilisateurs dans ce groupe" + members: + empty: Le groupe est vide + name: Nom d'utilisateur + role: Rôle + action: Action + edit: Modifier les droits de l'utilisateur + exclude: Exclure l'utilisateur + edit_user: + title: Édition des droits de l'utilisateur + role: Rôle + cancel: Annuler user: page_title: "Gestion des utilisateurs" diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_share_groups.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_share_groups.html.twig new file mode 100644 index 00000000..5c81ccc2 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_share_groups.html.twig @@ -0,0 +1,24 @@ + + diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 4cff7bf2..05f51aa8 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig @@ -170,6 +170,15 @@ + {#{% if craue_setting('groups') %}#} +
  • + + group + {{ 'entry.view.left_menu.groups'|trans }} + +
  • + {#{% endif %}#} + {% if craue_setting('show_printlink') %}
  • @@ -287,6 +296,8 @@ + {{ render(controller( "WallabagCoreBundle:Entry:GroupShare", { 'entry': entry.id } )) }} +