aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/GroupBundle/Controller/ManageController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/GroupBundle/Controller/ManageController.php')
-rw-r--r--src/Wallabag/GroupBundle/Controller/ManageController.php90
1 files changed, 82 insertions, 8 deletions
diff --git a/src/Wallabag/GroupBundle/Controller/ManageController.php b/src/Wallabag/GroupBundle/Controller/ManageController.php
index 7015a465..94196040 100644
--- a/src/Wallabag/GroupBundle/Controller/ManageController.php
+++ b/src/Wallabag/GroupBundle/Controller/ManageController.php
@@ -2,11 +2,20 @@
2 2
3namespace Wallabag\GroupBundle\Controller; 3namespace Wallabag\GroupBundle\Controller;
4 4
5use Pagerfanta\Adapter\DoctrineORMAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Pagerfanta\Pagerfanta;
8use Strut\StrutBundle\Service\Sha256Salted;
5use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller; 10use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; 11use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 12use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
13use Symfony\Component\HttpFoundation\Response;
9use Wallabag\GroupBundle\Entity\Group; 14use Wallabag\GroupBundle\Entity\Group;
15use Wallabag\GroupBundle\Entity\UserGroup;
16use Wallabag\GroupBundle\Form\GroupType;
17use Wallabag\GroupBundle\Form\NewGroupType;
18use Wallabag\UserBundle\Entity\User;
10 19
11/** 20/**
12 * Group controller. 21 * Group controller.
@@ -14,19 +23,32 @@ use Wallabag\GroupBundle\Entity\Group;
14class ManageController extends Controller 23class ManageController extends Controller
15{ 24{
16 /** 25 /**
17 * Lists all Group entities. 26 * Lists all public Group entities.
18 * 27 *
19 * @Route("/", name="group_index") 28 * @Route("/{page}", name="group_index", defaults={"page" = "1"})
20 * @Method("GET") 29 * @Method("GET")
21 */ 30 */
22 public function indexAction() 31 public function indexAction($page = 1)
23 { 32 {
24 $em = $this->getDoctrine()->getManager(); 33 $em = $this->getDoctrine()->getManager();
25 34
26 $groups = $em->getRepository('WallabagGroupBundle:Group')->findAll(); 35 $groups = $em->getRepository('WallabagGroupBundle:Group')->findPublicGroups();
36
37 $pagerAdapter = new DoctrineORMAdapter($groups->getQuery(), true, false);
38 $pagerFanta = new Pagerfanta($pagerAdapter);
39 $pagerFanta->setMaxPerPage(1);
40
41 try {
42 $pagerFanta->setCurrentPage($page);
43 } catch (OutOfRangeCurrentPageException $e) {
44 if ($page > 1) {
45 return $this->redirect($this->generateUrl('group_index', ['page' => $pagerFanta->getNbPages()]), 302);
46 }
47 }
27 48
28 return $this->render('WallabagGroupBundle:Manage:index.html.twig', array( 49 return $this->render('WallabagGroupBundle:Manage:index.html.twig', array(
29 'groups' => $groups, 50 'groups' => $pagerFanta,
51 'currentPage' => $page,
30 )); 52 ));
31 } 53 }
32 54
@@ -38,14 +60,26 @@ class ManageController extends Controller
38 */ 60 */
39 public function newAction(Request $request) 61 public function newAction(Request $request)
40 { 62 {
41 $group = new Group(''); 63 $group = new Group();
42 64
43 $form = $this->createForm('Wallabag\GroupBundle\Form\NewGroupType', $group); 65 $form = $this->createForm(NewGroupType::class, $group);
44 $form->handleRequest($request); 66 $form->handleRequest($request);
45 67
46 if ($form->isSubmitted() && $form->isValid()) { 68 if ($form->isSubmitted() && $form->isValid()) {
47 $em = $this->getDoctrine()->getManager(); 69 $em = $this->getDoctrine()->getManager();
70
71 if ($group->getAcceptSystem() == Group::ACCESS_PASSWORD) {
72 /** @var Sha256Salted $encoder */
73 $encoder = $this->get('sha256salted_encoder');
74 $password = $encoder->encodePassword($group->getPassword(), $this->getParameter('secret'));
75 $group->setPassword($password);
76 }
77
48 $em->persist($group); 78 $em->persist($group);
79
80 $groupUser = new UserGroup($this->getUser(), $group, Group::ROLE_ADMIN);
81 $groupUser->setAccepted(true);
82 $em->persist($groupUser);
49 $em->flush(); 83 $em->flush();
50 84
51 $this->get('session')->getFlashBag()->add( 85 $this->get('session')->getFlashBag()->add(
@@ -70,12 +104,23 @@ class ManageController extends Controller
70 */ 104 */
71 public function editAction(Request $request, Group $group) 105 public function editAction(Request $request, Group $group)
72 { 106 {
107 if ($this->getUser()->getGroupRoleForUser($group) < Group::ROLE_ADMIN) {
108 $this->createAccessDeniedException();
109 }
110
73 $deleteForm = $this->createDeleteForm($group); 111 $deleteForm = $this->createDeleteForm($group);
74 $editForm = $this->createForm('Wallabag\GroupBundle\Form\GroupType', $group); 112 $editForm = $this->createForm(GroupType::class, $group);
75 $editForm->handleRequest($request); 113 $editForm->handleRequest($request);
76 114
77 if ($editForm->isSubmitted() && $editForm->isValid()) { 115 if ($editForm->isSubmitted() && $editForm->isValid()) {
78 $em = $this->getDoctrine()->getManager(); 116 $em = $this->getDoctrine()->getManager();
117
118 if ($group->getAcceptSystem() === Group::ACCESS_PASSWORD) {
119 $encoder = $this->get('sha256salted_encoder');
120 $password = $encoder->encodePassword($group->getPlainPassword(), $this->getParameter('secret'));
121 $group->setPassword($password);
122 }
123
79 $em->persist($group); 124 $em->persist($group);
80 $em->flush(); 125 $em->flush();
81 126
@@ -134,4 +179,33 @@ class ManageController extends Controller
134 ->getForm() 179 ->getForm()
135 ; 180 ;
136 } 181 }
182
183 /**
184 * @Route("/group-user-exclude/{group}/{user}", name="group-user-exclude")
185 * @param Group $group
186 * @param User $user
187 * @return Response
188 */
189 public function excludeMemberAction(Group $group, User $user)
190 {
191 $logger = $this->get('logger');
192 $logger->info('User ' . $this->getUser()->getUsername() . ' wants to exclude user ' . $user->getUsername() . ' from group ' . $group->getName());
193
194 if (!$this->getUser()->inGroup($group) || $this->getUser()->getGroupRoleForUser($group) < Group::ROLE_MANAGE_USERS) {
195 $logger->info('User ' . $this->getUser()->getUsername() . ' has not enough rights on group ' . $group->getName() . ' to exclude user ' . $user->getUsername());
196 throw $this->createAccessDeniedException();
197 }
198
199 if ($user->inGroup($group) && $user->getGroupRoleForUser($group) < Group::ROLE_ADMIN) {
200 $em = $this->getDoctrine()->getManager();
201
202 $logger->info('Removing user ' . $this->getUser()->getUsername() . ' from group ' . $group->getName());
203 $em->remove($this->getUser()->getUserGroupFromGroup($group));
204
205 $em->flush();
206
207 return $this->redirectToRoute('group-manage', ['group' => $group->getId()]);
208 }
209 throw $this->createAccessDeniedException();
210 }
137} 211}