diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
6 files changed, 94 insertions, 47 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 4f75511b..91cdcae5 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -11,7 +11,6 @@ use Wallabag\CoreBundle\Entity\Config; | |||
11 | use Wallabag\CoreBundle\Entity\TaggingRule; | 11 | use Wallabag\CoreBundle\Entity\TaggingRule; |
12 | use Wallabag\CoreBundle\Form\Type\ConfigType; | 12 | use Wallabag\CoreBundle\Form\Type\ConfigType; |
13 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; | 13 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; |
14 | use Wallabag\CoreBundle\Form\Type\NewUserType; | ||
15 | use Wallabag\CoreBundle\Form\Type\RssType; | 14 | use Wallabag\CoreBundle\Form\Type\RssType; |
16 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; | 15 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; |
17 | use Wallabag\CoreBundle\Form\Type\UserInformationType; | 16 | use Wallabag\CoreBundle\Form\Type\UserInformationType; |
@@ -106,7 +105,21 @@ class ConfigController extends Controller | |||
106 | 105 | ||
107 | // handle tagging rule | 106 | // handle tagging rule |
108 | $taggingRule = new TaggingRule(); | 107 | $taggingRule = new TaggingRule(); |
109 | $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $this->generateUrl('config').'#set5']); | 108 | $action = $this->generateUrl('config').'#set5'; |
109 | |||
110 | if ($request->query->has('tagging-rule')) { | ||
111 | $taggingRule = $this->getDoctrine() | ||
112 | ->getRepository('WallabagCoreBundle:TaggingRule') | ||
113 | ->find($request->query->get('tagging-rule')); | ||
114 | |||
115 | if ($this->getUser()->getId() !== $taggingRule->getConfig()->getUser()->getId()) { | ||
116 | return $this->redirect($action); | ||
117 | } | ||
118 | |||
119 | $action = $this->generateUrl('config').'?tagging-rule='.$taggingRule->getId().'#set5'; | ||
120 | } | ||
121 | |||
122 | $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]); | ||
110 | $newTaggingRule->handleRequest($request); | 123 | $newTaggingRule->handleRequest($request); |
111 | 124 | ||
112 | if ($newTaggingRule->isValid()) { | 125 | if ($newTaggingRule->isValid()) { |
@@ -122,45 +135,12 @@ class ConfigController extends Controller | |||
122 | return $this->redirect($this->generateUrl('config').'#set5'); | 135 | return $this->redirect($this->generateUrl('config').'#set5'); |
123 | } | 136 | } |
124 | 137 | ||
125 | // handle adding new user | ||
126 | $newUser = $userManager->createUser(); | ||
127 | // enable created user by default | ||
128 | $newUser->setEnabled(true); | ||
129 | $newUserForm = $this->createForm(NewUserType::class, $newUser, [ | ||
130 | 'validation_groups' => ['Profile'], | ||
131 | 'action' => $this->generateUrl('config').'#set6', | ||
132 | ]); | ||
133 | $newUserForm->handleRequest($request); | ||
134 | |||
135 | if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { | ||
136 | $userManager->updateUser($newUser, true); | ||
137 | |||
138 | $config = new Config($newUser); | ||
139 | $config->setTheme($this->getParameter('wallabag_core.theme')); | ||
140 | $config->setItemsPerPage($this->getParameter('wallabag_core.items_on_page')); | ||
141 | $config->setRssLimit($this->getParameter('wallabag_core.rss_limit')); | ||
142 | $config->setLanguage($this->getParameter('wallabag_core.language')); | ||
143 | $config->setReadingSpeed($this->getParameter('wallabag_core.reading_speed')); | ||
144 | |||
145 | $em->persist($config); | ||
146 | |||
147 | $em->flush(); | ||
148 | |||
149 | $this->get('session')->getFlashBag()->add( | ||
150 | 'notice', | ||
151 | $this->get('translator')->trans('flashes.config.notice.user_added', ['%username%' => $newUser->getUsername()]) | ||
152 | ); | ||
153 | |||
154 | return $this->redirect($this->generateUrl('config').'#set6'); | ||
155 | } | ||
156 | |||
157 | return $this->render('WallabagCoreBundle:Config:index.html.twig', [ | 138 | return $this->render('WallabagCoreBundle:Config:index.html.twig', [ |
158 | 'form' => [ | 139 | 'form' => [ |
159 | 'config' => $configForm->createView(), | 140 | 'config' => $configForm->createView(), |
160 | 'rss' => $rssForm->createView(), | 141 | 'rss' => $rssForm->createView(), |
161 | 'pwd' => $pwdForm->createView(), | 142 | 'pwd' => $pwdForm->createView(), |
162 | 'user' => $userForm->createView(), | 143 | 'user' => $userForm->createView(), |
163 | 'new_user' => $newUserForm->createView(), | ||
164 | 'new_tagging_rule' => $newTaggingRule->createView(), | 144 | 'new_tagging_rule' => $newTaggingRule->createView(), |
165 | ], | 145 | ], |
166 | 'rss' => [ | 146 | 'rss' => [ |
@@ -210,9 +190,7 @@ class ConfigController extends Controller | |||
210 | */ | 190 | */ |
211 | public function deleteTaggingRuleAction(TaggingRule $rule) | 191 | public function deleteTaggingRuleAction(TaggingRule $rule) |
212 | { | 192 | { |
213 | if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { | 193 | $this->validateRuleAction($rule); |
214 | throw $this->createAccessDeniedException('You can not access this tagging rule.'); | ||
215 | } | ||
216 | 194 | ||
217 | $em = $this->getDoctrine()->getManager(); | 195 | $em = $this->getDoctrine()->getManager(); |
218 | $em->remove($rule); | 196 | $em->remove($rule); |
@@ -227,6 +205,34 @@ class ConfigController extends Controller | |||
227 | } | 205 | } |
228 | 206 | ||
229 | /** | 207 | /** |
208 | * Edit a tagging rule. | ||
209 | * | ||
210 | * @param TaggingRule $rule | ||
211 | * | ||
212 | * @Route("/tagging-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_tagging_rule") | ||
213 | * | ||
214 | * @return RedirectResponse | ||
215 | */ | ||
216 | public function editTaggingRuleAction(TaggingRule $rule) | ||
217 | { | ||
218 | $this->validateRuleAction($rule); | ||
219 | |||
220 | return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5'); | ||
221 | } | ||
222 | |||
223 | /** | ||
224 | * Validate that a rule can be edited/deleted by the current user. | ||
225 | * | ||
226 | * @param TaggingRule $rule | ||
227 | */ | ||
228 | private function validateRuleAction(TaggingRule $rule) | ||
229 | { | ||
230 | if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { | ||
231 | throw $this->createAccessDeniedException('You can not access this tagging rule.'); | ||
232 | } | ||
233 | } | ||
234 | |||
235 | /** | ||
230 | * Retrieve config for the current user. | 236 | * Retrieve config for the current user. |
231 | * If no config were found, create a new one. | 237 | * If no config were found, create a new one. |
232 | * | 238 | * |
@@ -238,6 +244,7 @@ class ConfigController extends Controller | |||
238 | ->getRepository('WallabagCoreBundle:Config') | 244 | ->getRepository('WallabagCoreBundle:Config') |
239 | ->findOneByUser($this->getUser()); | 245 | ->findOneByUser($this->getUser()); |
240 | 246 | ||
247 | // should NEVER HAPPEN ... | ||
241 | if (!$config) { | 248 | if (!$config) { |
242 | $config = new Config($this->getUser()); | 249 | $config = new Config($this->getUser()); |
243 | } | 250 | } |
diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/CoreBundle/Controller/DeveloperController.php index 63386db0..f3492b74 100644 --- a/src/Wallabag/CoreBundle/Controller/DeveloperController.php +++ b/src/Wallabag/CoreBundle/Controller/DeveloperController.php | |||
@@ -21,7 +21,7 @@ class DeveloperController extends Controller | |||
21 | { | 21 | { |
22 | $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll(); | 22 | $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll(); |
23 | 23 | ||
24 | return $this->render('WallabagCoreBundle:Developer:index.html.twig', [ | 24 | return $this->render('@WallabagCore/themes/common/Developer/index.html.twig', [ |
25 | 'clients' => $clients, | 25 | 'clients' => $clients, |
26 | ]); | 26 | ]); |
27 | } | 27 | } |
@@ -52,14 +52,14 @@ class DeveloperController extends Controller | |||
52 | $this->get('translator')->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()]) | 52 | $this->get('translator')->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()]) |
53 | ); | 53 | ); |
54 | 54 | ||
55 | return $this->render('WallabagCoreBundle:Developer:client_parameters.html.twig', [ | 55 | return $this->render('@WallabagCore/themes/common/Developer/client_parameters.html.twig', [ |
56 | 'client_id' => $client->getPublicId(), | 56 | 'client_id' => $client->getPublicId(), |
57 | 'client_secret' => $client->getSecret(), | 57 | 'client_secret' => $client->getSecret(), |
58 | 'client_name' => $client->getName(), | 58 | 'client_name' => $client->getName(), |
59 | ]); | 59 | ]); |
60 | } | 60 | } |
61 | 61 | ||
62 | return $this->render('WallabagCoreBundle:Developer:client.html.twig', [ | 62 | return $this->render('@WallabagCore/themes/common/Developer/client.html.twig', [ |
63 | 'form' => $clientForm->createView(), | 63 | 'form' => $clientForm->createView(), |
64 | ]); | 64 | ]); |
65 | } | 65 | } |
@@ -96,6 +96,6 @@ class DeveloperController extends Controller | |||
96 | */ | 96 | */ |
97 | public function howtoFirstAppAction() | 97 | public function howtoFirstAppAction() |
98 | { | 98 | { |
99 | return $this->render('WallabagCoreBundle:Developer:howto_app.html.twig'); | 99 | return $this->render('@WallabagCore/themes/common/Developer/howto_app.html.twig'); |
100 | } | 100 | } |
101 | } | 101 | } |
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 40111af0..3b28e635 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -531,7 +531,7 @@ class EntryController extends Controller | |||
531 | } | 531 | } |
532 | 532 | ||
533 | return $this->render( | 533 | return $this->render( |
534 | '@WallabagCore/themes/share.html.twig', | 534 | '@WallabagCore/themes/common/Entry/share.html.twig', |
535 | ['entry' => $entry] | 535 | ['entry' => $entry] |
536 | ); | 536 | ); |
537 | } | 537 | } |
diff --git a/src/Wallabag/CoreBundle/Controller/ExceptionController.php b/src/Wallabag/CoreBundle/Controller/ExceptionController.php new file mode 100644 index 00000000..abfa9c2f --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/ExceptionController.php | |||
@@ -0,0 +1,40 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController; | ||
6 | use Symfony\Component\HttpFoundation\Request; | ||
7 | |||
8 | /** | ||
9 | * This controller allow us to customize the error template. | ||
10 | * The only modified line from the parent template is for "WallabagCoreBundle". | ||
11 | */ | ||
12 | class ExceptionController extends BaseExceptionController | ||
13 | { | ||
14 | protected function findTemplate(Request $request, $format, $code, $showException) | ||
15 | { | ||
16 | $name = $showException ? 'exception' : 'error'; | ||
17 | if ($showException && 'html' == $format) { | ||
18 | $name = 'exception_full'; | ||
19 | } | ||
20 | |||
21 | // For error pages, try to find a template for the specific HTTP status code and format | ||
22 | if (!$showException) { | ||
23 | $template = sprintf('WallabagCoreBundle:Exception:%s.%s.twig', $name, $format); | ||
24 | if ($this->templateExists($template)) { | ||
25 | return $template; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | // try to find a template for the given format | ||
30 | $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format); | ||
31 | if ($this->templateExists($template)) { | ||
32 | return $template; | ||
33 | } | ||
34 | |||
35 | // default to a generic HTML exception | ||
36 | $request->setRequestFormat('html'); | ||
37 | |||
38 | return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name); | ||
39 | } | ||
40 | } | ||
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php index 2118885c..38e3b5a0 100644 --- a/src/Wallabag/CoreBundle/Controller/RssController.php +++ b/src/Wallabag/CoreBundle/Controller/RssController.php | |||
@@ -87,7 +87,7 @@ class RssController extends Controller | |||
87 | $perPage = $user->getConfig()->getRssLimit() ?: $this->getParameter('wallabag_core.rss_limit'); | 87 | $perPage = $user->getConfig()->getRssLimit() ?: $this->getParameter('wallabag_core.rss_limit'); |
88 | $entries->setMaxPerPage($perPage); | 88 | $entries->setMaxPerPage($perPage); |
89 | 89 | ||
90 | return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', [ | 90 | return $this->render('@WallabagCore/themes/common/Entry/entries.xml.twig', [ |
91 | 'type' => $type, | 91 | 'type' => $type, |
92 | 'entries' => $entries, | 92 | 'entries' => $entries, |
93 | ]); | 93 | ]); |
diff --git a/src/Wallabag/CoreBundle/Controller/StaticController.php b/src/Wallabag/CoreBundle/Controller/StaticController.php index 2a57f06f..82714217 100644 --- a/src/Wallabag/CoreBundle/Controller/StaticController.php +++ b/src/Wallabag/CoreBundle/Controller/StaticController.php | |||
@@ -15,7 +15,7 @@ class StaticController extends Controller | |||
15 | $addonsUrl = $this->container->getParameter('addons_url'); | 15 | $addonsUrl = $this->container->getParameter('addons_url'); |
16 | 16 | ||
17 | return $this->render( | 17 | return $this->render( |
18 | 'WallabagCoreBundle:Static:howto.html.twig', | 18 | '@WallabagCore/themes/common/Static/howto.html.twig', |
19 | ['addonsUrl' => $addonsUrl] | 19 | ['addonsUrl' => $addonsUrl] |
20 | ); | 20 | ); |
21 | } | 21 | } |
@@ -26,7 +26,7 @@ class StaticController extends Controller | |||
26 | public function aboutAction() | 26 | public function aboutAction() |
27 | { | 27 | { |
28 | return $this->render( | 28 | return $this->render( |
29 | 'WallabagCoreBundle:Static:about.html.twig', | 29 | '@WallabagCore/themes/common/Static/about.html.twig', |
30 | [ | 30 | [ |
31 | 'version' => $this->getParameter('wallabag_core.version'), | 31 | 'version' => $this->getParameter('wallabag_core.version'), |
32 | 'paypal_url' => $this->getParameter('wallabag_core.paypal_url'), | 32 | 'paypal_url' => $this->getParameter('wallabag_core.paypal_url'), |
@@ -40,7 +40,7 @@ class StaticController extends Controller | |||
40 | public function quickstartAction() | 40 | public function quickstartAction() |
41 | { | 41 | { |
42 | return $this->render( | 42 | return $this->render( |
43 | 'WallabagCoreBundle:Static:quickstart.html.twig', | 43 | '@WallabagCore/themes/common/Static/quickstart.html.twig', |
44 | [] | 44 | [] |
45 | ); | 45 | ); |
46 | } | 46 | } |