diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
4 files changed, 231 insertions, 5 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index d4170d39..23af98e5 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -10,12 +10,16 @@ use Symfony\Component\HttpFoundation\Request; | |||
10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | 10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
11 | use Wallabag\CoreBundle\Entity\Config; | 11 | use Wallabag\CoreBundle\Entity\Config; |
12 | use Wallabag\CoreBundle\Entity\TaggingRule; | 12 | use Wallabag\CoreBundle\Entity\TaggingRule; |
13 | use Wallabag\CoreBundle\Event\Activity\Actions\User\UserDeletedEvent; | ||
14 | use Wallabag\CoreBundle\Event\Activity\Actions\User\UserEditedEvent; | ||
13 | use Wallabag\CoreBundle\Form\Type\ConfigType; | 15 | use Wallabag\CoreBundle\Form\Type\ConfigType; |
14 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; | 16 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; |
15 | use Wallabag\CoreBundle\Form\Type\RssType; | 17 | use Wallabag\CoreBundle\Form\Type\RssType; |
16 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; | 18 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; |
17 | use Wallabag\CoreBundle\Form\Type\UserInformationType; | 19 | use Wallabag\CoreBundle\Form\Type\UserInformationType; |
18 | use Wallabag\CoreBundle\Tools\Utils; | 20 | use Wallabag\CoreBundle\Tools\Utils; |
21 | use Wallabag\FederationBundle\Form\Type\AccountType; | ||
22 | use Wallabag\UserBundle\Entity\User; | ||
19 | 23 | ||
20 | class ConfigController extends Controller | 24 | class ConfigController extends Controller |
21 | { | 25 | { |
@@ -82,6 +86,50 @@ class ConfigController extends Controller | |||
82 | if ($userForm->isSubmitted() && $userForm->isValid()) { | 86 | if ($userForm->isSubmitted() && $userForm->isValid()) { |
83 | $userManager->updateUser($user, true); | 87 | $userManager->updateUser($user, true); |
84 | 88 | ||
89 | $this->get('event_dispatcher')->dispatch(UserEditedEvent::NAME, new UserEditedEvent($user->getAccount())); | ||
90 | |||
91 | $this->get('session')->getFlashBag()->add( | ||
92 | 'notice', | ||
93 | 'flashes.config.notice.user_updated' | ||
94 | ); | ||
95 | |||
96 | return $this->redirect($this->generateUrl('config').'#set3'); | ||
97 | } | ||
98 | |||
99 | // handle account information | ||
100 | $account = $user->getAccount(); | ||
101 | $accountForm = $this->createForm(AccountType::class, $account, [ | ||
102 | 'action' => $this->generateUrl('config').'#set3', | ||
103 | ]); | ||
104 | $accountForm->handleRequest($request); | ||
105 | |||
106 | if ($accountForm->isSubmitted() && $accountForm->isValid()) { | ||
107 | |||
108 | $avatar = $account->getAvatar(); | ||
109 | $banner = $account->getBanner(); | ||
110 | |||
111 | if (null !== $avatar) { | ||
112 | $avatarFileName = md5(uniqid('', true)) . '.' . $avatar->guessExtension(); | ||
113 | |||
114 | $avatar->move( | ||
115 | $this->getParameter('media_directory') . '/avatar', | ||
116 | $avatarFileName | ||
117 | ); | ||
118 | $account->setAvatar($avatarFileName); | ||
119 | } | ||
120 | |||
121 | if (null != $banner) { | ||
122 | $bannerFileName = md5(uniqid('', true)) . '.' . $banner->guessExtension(); | ||
123 | |||
124 | $banner->move( | ||
125 | $this->get('media_directory') . '/banner', | ||
126 | $bannerFileName | ||
127 | ); | ||
128 | $account->setBanner($bannerFileName); | ||
129 | } | ||
130 | |||
131 | $this->get('event_dispatcher')->dispatch(UserEditedEvent::NAME, new UserEditedEvent($user)); | ||
132 | |||
85 | $this->get('session')->getFlashBag()->add( | 133 | $this->get('session')->getFlashBag()->add( |
86 | 'notice', | 134 | 'notice', |
87 | 'flashes.config.notice.user_updated' | 135 | 'flashes.config.notice.user_updated' |
@@ -145,6 +193,7 @@ class ConfigController extends Controller | |||
145 | 'pwd' => $pwdForm->createView(), | 193 | 'pwd' => $pwdForm->createView(), |
146 | 'user' => $userForm->createView(), | 194 | 'user' => $userForm->createView(), |
147 | 'new_tagging_rule' => $newTaggingRule->createView(), | 195 | 'new_tagging_rule' => $newTaggingRule->createView(), |
196 | 'account' => $accountForm->createView(), | ||
148 | ], | 197 | ], |
149 | 'rss' => [ | 198 | 'rss' => [ |
150 | 'username' => $user->getUsername(), | 199 | 'username' => $user->getUsername(), |
@@ -400,9 +449,13 @@ class ConfigController extends Controller | |||
400 | $this->get('security.token_storage')->setToken(null); | 449 | $this->get('security.token_storage')->setToken(null); |
401 | $request->getSession()->invalidate(); | 450 | $request->getSession()->invalidate(); |
402 | 451 | ||
452 | $account = $user->getAccount(); | ||
453 | |||
403 | $em = $this->get('fos_user.user_manager'); | 454 | $em = $this->get('fos_user.user_manager'); |
404 | $em->deleteUser($user); | 455 | $em->deleteUser($user); |
405 | 456 | ||
457 | $this->get('event_dispatcher')->dispatch(UserDeletedEvent::NAME, new UserDeletedEvent($account)); | ||
458 | |||
406 | return $this->redirect($this->generateUrl('fos_user_security_login')); | 459 | return $this->redirect($this->generateUrl('fos_user_security_login')); |
407 | } | 460 | } |
408 | 461 | ||
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index fafa49f1..5e4462ed 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -9,12 +9,14 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 10 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
11 | use Wallabag\CoreBundle\Entity\Entry; | 11 | use Wallabag\CoreBundle\Entity\Entry; |
12 | use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryEditedEvent; | ||
13 | use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryFavouriteEvent; | ||
14 | use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryReadEvent; | ||
15 | use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntrySavedEvent; | ||
12 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; | 16 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; |
13 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | 17 | use Wallabag\CoreBundle\Form\Type\EditEntryType; |
14 | use Wallabag\CoreBundle\Form\Type\NewEntryType; | 18 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
15 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; | 19 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; |
16 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | ||
17 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; | ||
18 | use Wallabag\CoreBundle\Form\Type\SearchEntryType; | 20 | use Wallabag\CoreBundle\Form\Type\SearchEntryType; |
19 | 21 | ||
20 | class EntryController extends Controller | 22 | class EntryController extends Controller |
@@ -405,6 +407,8 @@ class EntryController extends Controller | |||
405 | $entry->toggleArchive(); | 407 | $entry->toggleArchive(); |
406 | $this->getDoctrine()->getManager()->flush(); | 408 | $this->getDoctrine()->getManager()->flush(); |
407 | 409 | ||
410 | $this->get('event_dispatcher')->dispatch(EntryReadEvent::NAME, new EntryReadEvent($entry)); | ||
411 | |||
408 | $message = 'flashes.entry.notice.entry_unarchived'; | 412 | $message = 'flashes.entry.notice.entry_unarchived'; |
409 | if ($entry->isArchived()) { | 413 | if ($entry->isArchived()) { |
410 | $message = 'flashes.entry.notice.entry_archived'; | 414 | $message = 'flashes.entry.notice.entry_archived'; |
@@ -437,6 +441,8 @@ class EntryController extends Controller | |||
437 | $entry->toggleStar(); | 441 | $entry->toggleStar(); |
438 | $this->getDoctrine()->getManager()->flush(); | 442 | $this->getDoctrine()->getManager()->flush(); |
439 | 443 | ||
444 | $this->get('event_dispatcher')->dispatch(EntryFavouriteEvent::NAME, new EntryFavouriteEvent($entry)); | ||
445 | |||
440 | $message = 'flashes.entry.notice.entry_unstarred'; | 446 | $message = 'flashes.entry.notice.entry_unstarred'; |
441 | if ($entry->isStarred()) { | 447 | if ($entry->isStarred()) { |
442 | $message = 'flashes.entry.notice.entry_starred'; | 448 | $message = 'flashes.entry.notice.entry_starred'; |
@@ -473,9 +479,6 @@ class EntryController extends Controller | |||
473 | UrlGeneratorInterface::ABSOLUTE_PATH | 479 | UrlGeneratorInterface::ABSOLUTE_PATH |
474 | ); | 480 | ); |
475 | 481 | ||
476 | // entry deleted, dispatch event about it! | ||
477 | $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); | ||
478 | |||
479 | $em = $this->getDoctrine()->getManager(); | 482 | $em = $this->getDoctrine()->getManager(); |
480 | $em->remove($entry); | 483 | $em->remove($entry); |
481 | $em->flush(); | 484 | $em->flush(); |
diff --git a/src/Wallabag/CoreBundle/Controller/ShareController.php b/src/Wallabag/CoreBundle/Controller/ShareController.php new file mode 100644 index 00000000..d6f83ebc --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/ShareController.php | |||
@@ -0,0 +1,165 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
7 | use Symfony\Component\HttpFoundation\RedirectResponse; | ||
8 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
9 | use Symfony\Component\Security\Core\Exception\InvalidArgumentException; | ||
10 | use Wallabag\CoreBundle\Entity\Entry; | ||
11 | use Wallabag\CoreBundle\Entity\Notification; | ||
12 | use Wallabag\CoreBundle\Entity\Share; | ||
13 | use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntrySavedEvent; | ||
14 | use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareAcceptedEvent; | ||
15 | use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareCancelledEvent; | ||
16 | use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareCreatedEvent; | ||
17 | use Wallabag\CoreBundle\Event\Activity\Actions\Share\ShareDeniedEvent; | ||
18 | use Wallabag\CoreBundle\Notifications\NoAction; | ||
19 | use Wallabag\CoreBundle\Notifications\YesAction; | ||
20 | use Wallabag\UserBundle\Entity\User; | ||
21 | |||
22 | class ShareController extends Controller | ||
23 | { | ||
24 | /** | ||
25 | * @Route("/share-user/{entry}/{destination}", name="share-entry-user", requirements={"entry" = "\d+", "destination" = "\d+"}) | ||
26 | * @param Entry $entry | ||
27 | * @param User $destination | ||
28 | * @throws AccessDeniedException | ||
29 | * @throws InvalidArgumentException | ||
30 | */ | ||
31 | public function shareEntryAction(Entry $entry, User $destination) | ||
32 | { | ||
33 | |||
34 | if ($entry->getUser() !== $this->getUser()) { | ||
35 | throw new AccessDeniedException("You can't share this entry"); | ||
36 | } | ||
37 | |||
38 | if ($destination === $this->getUser()) { | ||
39 | throw new InvalidArgumentException("You can't share entries to yourself"); | ||
40 | } | ||
41 | |||
42 | $share = new Share(); | ||
43 | $share->setUserOrigin($this->getUser()) | ||
44 | ->setEntry($entry) | ||
45 | ->setUserDestination($destination); | ||
46 | |||
47 | $em = $this->getDoctrine()->getManager(); | ||
48 | $em->persist($share); | ||
49 | $em->flush(); | ||
50 | |||
51 | $this->get('event_dispatcher')->dispatch(ShareCreatedEvent::NAME, new ShareCancelledEvent($share)); | ||
52 | |||
53 | $accept = new YesAction($this->generateUrl('share-entry-user-accept', ['share' => $share->getId()])); | ||
54 | |||
55 | $deny = new NoAction($this->generateUrl('share-entry-user-refuse', ['share' => $share->getId()])); | ||
56 | |||
57 | $notification = new Notification($destination); | ||
58 | $notification->setType(Notification::TYPE_SHARE) | ||
59 | ->setTitle($this->get('translator')->trans('share.notification.new.title')) | ||
60 | ->addAction($accept) | ||
61 | ->addAction($deny); | ||
62 | |||
63 | $em->persist($notification); | ||
64 | $em->flush(); | ||
65 | |||
66 | $this->redirectToRoute('view', ['id' => $entry->getId()]); | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * @Route("/share-user/accept/{share}", name="share-entry-user-accept") | ||
71 | * | ||
72 | * @param Share $share | ||
73 | * @return RedirectResponse | ||
74 | * @throws AccessDeniedException | ||
75 | */ | ||
76 | public function acceptShareAction(Share $share) | ||
77 | { | ||
78 | if ($share->getUserDestination() !== $this->getUser()) { | ||
79 | throw new AccessDeniedException("You can't accept this entry"); | ||
80 | } | ||
81 | |||
82 | $entry = new Entry($this->getUser()); | ||
83 | $entry->setUrl($share->getEntry()->getUrl()); | ||
84 | |||
85 | $em = $this->getDoctrine()->getManager(); | ||
86 | |||
87 | if (false === $this->checkIfEntryAlreadyExists($entry)) { | ||
88 | $this->updateEntry($entry); | ||
89 | |||
90 | $em->persist($entry); | ||
91 | $em->flush(); | ||
92 | |||
93 | $this->get('event_dispatcher')->dispatch(ShareAcceptedEvent::NAME, new ShareAcceptedEvent($share)); | ||
94 | |||
95 | // entry saved, dispatch event about it! | ||
96 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | ||
97 | } | ||
98 | |||
99 | $em->remove($share); | ||
100 | $em->flush(); // we keep the previous flush above in case the event dispatcher would lead in using the saved entry | ||
101 | |||
102 | return $this->redirect($this->generateUrl('homepage')); | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * @Route("/share-user/refuse/{share}", name="share-entry-user-refuse") | ||
107 | * | ||
108 | * @param Share $share | ||
109 | * @return RedirectResponse | ||
110 | */ | ||
111 | public function refuseShareAction(Share $share) | ||
112 | { | ||
113 | $em = $this->getDoctrine()->getManager(); | ||
114 | $em->remove($share); | ||
115 | $em->flush(); | ||
116 | |||
117 | $this->get('event_dispatcher')->dispatch(ShareDeniedEvent::NAME, new ShareDeniedEvent($share)); | ||
118 | |||
119 | return $this->redirect($this->generateUrl('homepage')); | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * Fetch content and update entry. | ||
124 | * In case it fails, entry will return to avod loosing the data. | ||
125 | * | ||
126 | * @param Entry $entry | ||
127 | * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded | ||
128 | * | ||
129 | * @return Entry | ||
130 | */ | ||
131 | private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved') | ||
132 | { | ||
133 | // put default title in case of fetching content failed | ||
134 | $entry->setTitle('No title found'); | ||
135 | |||
136 | $message = 'flashes.entry.notice.'.$prefixMessage; | ||
137 | |||
138 | try { | ||
139 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); | ||
140 | } catch (\Exception $e) { | ||
141 | $this->get('logger')->error('Error while saving an entry', [ | ||
142 | 'exception' => $e, | ||
143 | 'entry' => $entry, | ||
144 | ]); | ||
145 | |||
146 | $message = 'flashes.entry.notice.'.$prefixMessage.'_failed'; | ||
147 | } | ||
148 | |||
149 | $this->get('session')->getFlashBag()->add('notice', $message); | ||
150 | |||
151 | return $entry; | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * Check for existing entry, if it exists, redirect to it with a message. | ||
156 | * | ||
157 | * @param Entry $entry | ||
158 | * | ||
159 | * @return Entry|bool | ||
160 | */ | ||
161 | private function checkIfEntryAlreadyExists(Entry $entry) | ||
162 | { | ||
163 | return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); | ||
164 | } | ||
165 | } | ||
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index a8b1eadd..6cc78458 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -9,6 +9,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Wallabag\CoreBundle\Entity\Entry; | 10 | use Wallabag\CoreBundle\Entity\Entry; |
11 | use Wallabag\CoreBundle\Entity\Tag; | 11 | use Wallabag\CoreBundle\Entity\Tag; |
12 | use Wallabag\CoreBundle\Event\Activity\Actions\Entry\EntryTaggedEvent; | ||
12 | use Wallabag\CoreBundle\Form\Type\NewTagType; | 13 | use Wallabag\CoreBundle\Form\Type\NewTagType; |
13 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | 14 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
14 | 15 | ||
@@ -37,6 +38,8 @@ class TagController extends Controller | |||
37 | $em->persist($entry); | 38 | $em->persist($entry); |
38 | $em->flush(); | 39 | $em->flush(); |
39 | 40 | ||
41 | $this->get('event_dispatcher')->dispatch(EntryTaggedEvent::NAME, new EntryTaggedEvent($entry, $tags)); | ||
42 | |||
40 | $this->get('session')->getFlashBag()->add( | 43 | $this->get('session')->getFlashBag()->add( |
41 | 'notice', | 44 | 'notice', |
42 | 'flashes.tag.notice.tag_added' | 45 | 'flashes.tag.notice.tag_added' |
@@ -64,6 +67,8 @@ class TagController extends Controller | |||
64 | $em = $this->getDoctrine()->getManager(); | 67 | $em = $this->getDoctrine()->getManager(); |
65 | $em->flush(); | 68 | $em->flush(); |
66 | 69 | ||
70 | $this->get('event_dispatcher')->dispatch(EntryTaggedEvent::NAME, new EntryTaggedEvent($entry, $tag), true); | ||
71 | |||
67 | // remove orphan tag in case no entries are associated to it | 72 | // remove orphan tag in case no entries are associated to it |
68 | if (count($tag->getEntries()) === 0) { | 73 | if (count($tag->getEntries()) === 0) { |
69 | $em->remove($tag); | 74 | $em->remove($tag); |