aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2017-06-12 10:26:01 +0200
committerGitHub <noreply@github.com>2017-06-12 10:26:01 +0200
commit977ac0a1d6c5e42d0bb2cbb13eac6213fefbb175 (patch)
tree820044e9630a1e0db88d9838370b6e50e6e0b376
parent873f6b8e03079d11fab541aa5b0bc6f8fe2d645e (diff)
parentd9da186fb8427ca82d1fd7c4e2ef3f5032781f23 (diff)
downloadwallabag-977ac0a1d6c5e42d0bb2cbb13eac6213fefbb175.tar.gz
wallabag-977ac0a1d6c5e42d0bb2cbb13eac6213fefbb175.tar.zst
wallabag-977ac0a1d6c5e42d0bb2cbb13eac6213fefbb175.zip
Merge pull request #3208 from wallabag/is-public
Add ability to filter public entries & use it in the API
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php27
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php15
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php14
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php11
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.da.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.de.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.en.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.es.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.it.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig5
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig11
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php52
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php14
19 files changed, 165 insertions, 6 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 09b73ccb..768c4fdc 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -77,6 +77,7 @@ class EntryRestController extends WallabagRestController
77 * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, 77 * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."},
78 * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, 78 * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."},
79 * {"name"="since", "dataType"="integer", "required"=false, "format"="default '0'", "description"="The timestamp since when you want entries updated."}, 79 * {"name"="since", "dataType"="integer", "required"=false, "format"="default '0'", "description"="The timestamp since when you want entries updated."},
80 * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by entries with a public link"},
80 * } 81 * }
81 * ) 82 * )
82 * 83 *
@@ -88,6 +89,7 @@ class EntryRestController extends WallabagRestController
88 89
89 $isArchived = (null === $request->query->get('archive')) ? null : (bool) $request->query->get('archive'); 90 $isArchived = (null === $request->query->get('archive')) ? null : (bool) $request->query->get('archive');
90 $isStarred = (null === $request->query->get('starred')) ? null : (bool) $request->query->get('starred'); 91 $isStarred = (null === $request->query->get('starred')) ? null : (bool) $request->query->get('starred');
92 $isPublic = (null === $request->query->get('public')) ? null : (bool) $request->query->get('public');
91 $sort = $request->query->get('sort', 'created'); 93 $sort = $request->query->get('sort', 'created');
92 $order = $request->query->get('order', 'desc'); 94 $order = $request->query->get('order', 'desc');
93 $page = (int) $request->query->get('page', 1); 95 $page = (int) $request->query->get('page', 1);
@@ -96,9 +98,16 @@ class EntryRestController extends WallabagRestController
96 $since = $request->query->get('since', 0); 98 $since = $request->query->get('since', 0);
97 99
98 /** @var \Pagerfanta\Pagerfanta $pager */ 100 /** @var \Pagerfanta\Pagerfanta $pager */
99 $pager = $this->getDoctrine() 101 $pager = $this->get('wallabag_core.entry_repository')->findEntries(
100 ->getRepository('WallabagCoreBundle:Entry') 102 $this->getUser()->getId(),
101 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order, $since, $tags); 103 $isArchived,
104 $isStarred,
105 $isPublic,
106 $sort,
107 $order,
108 $since,
109 $tags
110 );
102 111
103 $pager->setMaxPerPage($perPage); 112 $pager->setMaxPerPage($perPage);
104 $pager->setCurrentPage($page); 113 $pager->setCurrentPage($page);
@@ -111,6 +120,7 @@ class EntryRestController extends WallabagRestController
111 [ 120 [
112 'archive' => $isArchived, 121 'archive' => $isArchived,
113 'starred' => $isStarred, 122 'starred' => $isStarred,
123 'public' => $isPublic,
114 'sort' => $sort, 124 'sort' => $sort,
115 'order' => $order, 125 'order' => $order,
116 'page' => $page, 126 'page' => $page,
@@ -289,6 +299,7 @@ class EntryRestController extends WallabagRestController
289 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"}, 299 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"},
290 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, 300 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
291 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, 301 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
302 * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"},
292 * } 303 * }
293 * ) 304 * )
294 * 305 *
@@ -332,6 +343,7 @@ class EntryRestController extends WallabagRestController
332 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"}, 343 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"},
333 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, 344 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
334 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, 345 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
346 * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"},
335 * } 347 * }
336 * ) 348 * )
337 * 349 *
@@ -623,6 +635,7 @@ class EntryRestController extends WallabagRestController
623 $tags = $request->request->get('tags', []); 635 $tags = $request->request->get('tags', []);
624 $isArchived = $request->request->get('archive'); 636 $isArchived = $request->request->get('archive');
625 $isStarred = $request->request->get('starred'); 637 $isStarred = $request->request->get('starred');
638 $isPublic = $request->request->get('public');
626 $content = $request->request->get('content'); 639 $content = $request->request->get('content');
627 $language = $request->request->get('language'); 640 $language = $request->request->get('language');
628 $picture = $request->request->get('preview_picture'); 641 $picture = $request->request->get('preview_picture');
@@ -666,6 +679,14 @@ class EntryRestController extends WallabagRestController
666 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); 679 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
667 } 680 }
668 681
682 if (!is_null($isPublic)) {
683 if (true === (bool) $isPublic && null === $entry->getUid()) {
684 $entry->generateUid();
685 } elseif (false === (bool) $isPublic) {
686 $entry->cleanUid();
687 }
688 }
689
669 $em = $this->getDoctrine()->getManager(); 690 $em = $this->getDoctrine()->getManager();
670 $em->persist($entry); 691 $em->persist($entry);
671 $em->flush(); 692 $em->flush();
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 9a7dd4e7..a0503c39 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -685,6 +685,21 @@ class Entry
685 } 685 }
686 686
687 /** 687 /**
688 * Used in the entries filter so it's more explicit for the end user than the uid.
689 * Also used in the API.
690 *
691 * @VirtualProperty
692 * @SerializedName("is_public")
693 * @Groups({"entries_for_user"})
694 *
695 * @return bool
696 */
697 public function isPublic()
698 {
699 return null !== $this->uid;
700 }
701
702 /**
688 * @return string 703 * @return string
689 */ 704 */
690 public function getHttpStatus() 705 public function getHttpStatus()
diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
index 556578d1..6a4c485f 100644
--- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
+++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
@@ -150,6 +150,20 @@ class EntryFilterType extends AbstractType
150 }, 150 },
151 'label' => 'entry.filters.preview_picture_label', 151 'label' => 'entry.filters.preview_picture_label',
152 ]) 152 ])
153 ->add('isPublic', CheckboxFilterType::class, [
154 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
155 if (false === $values['value']) {
156 return;
157 }
158
159 // is_public isn't a real field
160 // we should use the "uid" field to determine if the entry has been made public
161 $expression = $filterQuery->getExpr()->isNotNull($values['alias'].'.uid');
162
163 return $filterQuery->createCondition($expression);
164 },
165 'label' => 'entry.filters.is_public_label',
166 ])
153 ->add('language', ChoiceFilterType::class, [ 167 ->add('language', ChoiceFilterType::class, [
154 'choices' => array_flip($this->repository->findDistinctLanguageByUser($this->user->getId())), 168 'choices' => array_flip($this->repository->findDistinctLanguageByUser($this->user->getId())),
155 'label' => 'entry.filters.language_label', 169 'label' => 'entry.filters.language_label',
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 6972e974..9bda4e15 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -135,6 +135,7 @@ class EntryRepository extends EntityRepository
135 * @param int $userId 135 * @param int $userId
136 * @param bool $isArchived 136 * @param bool $isArchived
137 * @param bool $isStarred 137 * @param bool $isStarred
138 * @param bool $isPublic
138 * @param string $sort 139 * @param string $sort
139 * @param string $order 140 * @param string $order
140 * @param int $since 141 * @param int $since
@@ -142,18 +143,22 @@ class EntryRepository extends EntityRepository
142 * 143 *
143 * @return array 144 * @return array
144 */ 145 */
145 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '') 146 public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '')
146 { 147 {
147 $qb = $this->createQueryBuilder('e') 148 $qb = $this->createQueryBuilder('e')
148 ->leftJoin('e.tags', 't') 149 ->leftJoin('e.tags', 't')
149 ->where('e.user =:userId')->setParameter('userId', $userId); 150 ->where('e.user =:userId')->setParameter('userId', $userId);
150 151
151 if (null !== $isArchived) { 152 if (null !== $isArchived) {
152 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived); 153 $qb->andWhere('e.isArchived = :isArchived')->setParameter('isArchived', (bool) $isArchived);
153 } 154 }
154 155
155 if (null !== $isStarred) { 156 if (null !== $isStarred) {
156 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); 157 $qb->andWhere('e.isStarred = :isStarred')->setParameter('isStarred', (bool) $isStarred);
158 }
159
160 if (null !== $isPublic) {
161 $qb->andWhere('e.uid IS '.(true === $isPublic ? 'NOT' : '').' NULL');
157 } 162 }
158 163
159 if ($since > 0) { 164 if ($since > 0) {
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
index 5e7afe27..02dd04f2 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
@@ -186,6 +186,8 @@ entry:
186 unread_label: 'Ulæst' 186 unread_label: 'Ulæst'
187 preview_picture_label: 'Har et vist billede' 187 preview_picture_label: 'Har et vist billede'
188 preview_picture_help: 'Forhåndsvis billede' 188 preview_picture_help: 'Forhåndsvis billede'
189 # is_public_label: 'Has a public link'
190 # is_public_help: 'Public link'
189 language_label: 'Sprog' 191 language_label: 'Sprog'
190 # http_status_label: 'HTTP status' 192 # http_status_label: 'HTTP status'
191 reading_time: 193 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
index 00468575..f6ccdae0 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: 'Ungelesene' 187 unread_label: 'Ungelesene'
188 preview_picture_label: 'Vorschaubild vorhanden' 188 preview_picture_label: 'Vorschaubild vorhanden'
189 preview_picture_help: 'Vorschaubild' 189 preview_picture_help: 'Vorschaubild'
190 # is_public_label: 'Has a public link'
191 # is_public_help: 'Public link'
190 language_label: 'Sprache' 192 language_label: 'Sprache'
191 http_status_label: 'HTTP-Status' 193 http_status_label: 'HTTP-Status'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
index 572084c1..902c3046 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: 'Unread' 187 unread_label: 'Unread'
188 preview_picture_label: 'Has a preview picture' 188 preview_picture_label: 'Has a preview picture'
189 preview_picture_help: 'Preview picture' 189 preview_picture_help: 'Preview picture'
190 is_public_label: 'Has a public link'
191 is_public_help: 'Public link'
190 language_label: 'Language' 192 language_label: 'Language'
191 http_status_label: 'HTTP status' 193 http_status_label: 'HTTP status'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
index 0f2a4a7b..afd6a7b1 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: 'Sin leer' 187 unread_label: 'Sin leer'
188 preview_picture_label: 'Tiene imagen de previsualización' 188 preview_picture_label: 'Tiene imagen de previsualización'
189 preview_picture_help: 'Imagen de previsualización' 189 preview_picture_help: 'Imagen de previsualización'
190 # is_public_label: 'Has a public link'
191 # is_public_help: 'Public link'
190 language_label: 'Idioma' 192 language_label: 'Idioma'
191 http_status_label: 'Código de estado HTTP' 193 http_status_label: 'Código de estado HTTP'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
index a8900489..545514b3 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: 'خوانده‌نشده' 187 unread_label: 'خوانده‌نشده'
188 preview_picture_label: 'دارای عکس پیش‌نمایش' 188 preview_picture_label: 'دارای عکس پیش‌نمایش'
189 preview_picture_help: 'پیش‌نمایش عکس' 189 preview_picture_help: 'پیش‌نمایش عکس'
190 # is_public_label: 'Has a public link'
191 # is_public_help: 'Public link'
190 language_label: 'زبان' 192 language_label: 'زبان'
191 # http_status_label: 'HTTP status' 193 # http_status_label: 'HTTP status'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index 6969b67b..e9e79c67 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: "Non lus" 187 unread_label: "Non lus"
188 preview_picture_label: "A une photo" 188 preview_picture_label: "A une photo"
189 preview_picture_help: "Photo" 189 preview_picture_help: "Photo"
190 is_public_label: 'A un lien public'
191 is_public_help: 'Lien public'
190 language_label: "Langue" 192 language_label: "Langue"
191 http_status_label: "Statut HTTP" 193 http_status_label: "Statut HTTP"
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
index c2007057..0597d3e3 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
@@ -187,6 +187,8 @@ entry:
187 # unread_label: 'Unread' 187 # unread_label: 'Unread'
188 preview_picture_label: "Ha un'immagine di anteprima" 188 preview_picture_label: "Ha un'immagine di anteprima"
189 preview_picture_help: 'Immagine di anteprima' 189 preview_picture_help: 'Immagine di anteprima'
190 # is_public_label: 'Has a public link'
191 # is_public_help: 'Public link'
190 language_label: 'Lingua' 192 language_label: 'Lingua'
191 # http_status_label: 'HTTP status' 193 # http_status_label: 'HTTP status'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
index 3ac472d0..c172a0f6 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: 'Pas legits' 187 unread_label: 'Pas legits'
188 preview_picture_label: 'A un imatge' 188 preview_picture_label: 'A un imatge'
189 preview_picture_help: 'Imatge' 189 preview_picture_help: 'Imatge'
190 # is_public_label: 'Has a public link'
191 # is_public_help: 'Public link'
190 language_label: 'Lenga' 192 language_label: 'Lenga'
191 http_status_label: 'Estatut HTTP' 193 http_status_label: 'Estatut HTTP'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
index fa672387..82d16767 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: 'Nieprzeczytane' 187 unread_label: 'Nieprzeczytane'
188 preview_picture_label: 'Posiada podglÄ…d obrazu' 188 preview_picture_label: 'Posiada podglÄ…d obrazu'
189 preview_picture_help: 'PodglÄ…d obrazu' 189 preview_picture_help: 'PodglÄ…d obrazu'
190 # is_public_label: 'Has a public link'
191 # is_public_help: 'Public link'
190 language_label: 'Język' 192 language_label: 'Język'
191 http_status_label: 'Status HTTP' 193 http_status_label: 'Status HTTP'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
index 896ccb04..b75567d6 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: 'Não Lido' 187 unread_label: 'Não Lido'
188 preview_picture_label: 'Possui uma imagem de preview' 188 preview_picture_label: 'Possui uma imagem de preview'
189 preview_picture_help: 'Imagem de preview' 189 preview_picture_help: 'Imagem de preview'
190 # is_public_label: 'Has a public link'
191 # is_public_help: 'Public link'
190 language_label: 'Idioma' 192 language_label: 'Idioma'
191 # http_status_label: 'HTTP status' 193 # http_status_label: 'HTTP status'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
index c447dc9b..95df573d 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
@@ -187,6 +187,8 @@ entry:
187 unread_label: 'Necitite' 187 unread_label: 'Necitite'
188 preview_picture_label: 'Are o imagine de previzualizare' 188 preview_picture_label: 'Are o imagine de previzualizare'
189 preview_picture_help: 'Previzualizare imagine' 189 preview_picture_help: 'Previzualizare imagine'
190 # is_public_label: 'Has a public link'
191 # is_public_help: 'Public link'
190 language_label: 'Limbă' 192 language_label: 'Limbă'
191 # http_status_label: 'HTTP status' 193 # http_status_label: 'HTTP status'
192 reading_time: 194 reading_time:
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
index 0ba6f4f4..6c26d5bf 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
@@ -127,6 +127,11 @@
127 {{ form_widget(form.previewPicture) }} 127 {{ form_widget(form.previewPicture) }}
128 {{ form_label(form.previewPicture) }} 128 {{ form_label(form.previewPicture) }}
129 </div> 129 </div>
130
131 <div class="input-field">
132 {{ form_widget(form.isPublic) }}
133 {{ form_label(form.isPublic) }}
134 </div>
130 </div> 135 </div>
131 136
132 <div id="filter-language" class="filter-group"> 137 <div id="filter-language" class="filter-group">
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
index 6f657b18..5ba42057 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
@@ -103,6 +103,15 @@
103 </div> 103 </div>
104 104
105 <div class="col s12"> 105 <div class="col s12">
106 <label>{{ 'entry.filters.is_public_help'|trans }}</label>
107 </div>
108
109 <div class="input-field col s12 with-checkbox">
110 {{ form_widget(form.isPublic) }}
111 {{ form_label(form.isPublic) }}
112 </div>
113
114 <div class="col s12">
106 {{ form_label(form.language) }} 115 {{ form_label(form.language) }}
107 </div> 116 </div>
108 117
@@ -121,10 +130,12 @@
121 <div class="col s12"> 130 <div class="col s12">
122 {{ form_label(form.readingTime) }} 131 {{ form_label(form.readingTime) }}
123 </div> 132 </div>
133
124 <div class="input-field col s6"> 134 <div class="input-field col s6">
125 {{ form_widget(form.readingTime.left_number, {'type': 'number'}) }} 135 {{ form_widget(form.readingTime.left_number, {'type': 'number'}) }}
126 <label for="entry_filter_readingTime_left_number">{{ 'entry.filters.reading_time.from'|trans }}</label> 136 <label for="entry_filter_readingTime_left_number">{{ 'entry.filters.reading_time.from'|trans }}</label>
127 </div> 137 </div>
138
128 <div class="input-field col s6"> 139 <div class="input-field col s6">
129 {{ form_widget(form.readingTime.right_number, {'type': 'number'}) }} 140 {{ form_widget(form.readingTime.right_number, {'type': 'number'}) }}
130 <label for="entry_filter_readingTime_right_number">{{ 'entry.filters.reading_time.to'|trans }}</label> 141 <label for="entry_filter_readingTime_right_number">{{ 'entry.filters.reading_time.to'|trans }}</label>
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 4aa60e90..067aed2c 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -128,6 +128,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
128 'perPage' => 2, 128 'perPage' => 2,
129 'tags' => 'foo', 129 'tags' => 'foo',
130 'since' => 1443274283, 130 'since' => 1443274283,
131 'public' => 0,
131 ]); 132 ]);
132 133
133 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 134 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -154,6 +155,53 @@ class EntryRestControllerTest extends WallabagApiTestCase
154 $this->assertContains('order=asc', $content['_links'][$link]['href']); 155 $this->assertContains('order=asc', $content['_links'][$link]['href']);
155 $this->assertContains('tags=foo', $content['_links'][$link]['href']); 156 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
156 $this->assertContains('since=1443274283', $content['_links'][$link]['href']); 157 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
158 $this->assertContains('public=0', $content['_links'][$link]['href']);
159 }
160
161 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
162 }
163
164 public function testGetEntriesPublicOnly()
165 {
166 $entry = $this->client->getContainer()
167 ->get('doctrine.orm.entity_manager')
168 ->getRepository('WallabagCoreBundle:Entry')
169 ->findOneByUser(1);
170
171 if (!$entry) {
172 $this->markTestSkipped('No content found in db.');
173 }
174
175 // generate at least one public entry
176 $entry->generateUid();
177
178 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
179 $em->persist($entry);
180 $em->flush();
181
182 $this->client->request('GET', '/api/entries', [
183 'public' => 1,
184 ]);
185
186 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
187
188 $content = json_decode($this->client->getResponse()->getContent(), true);
189
190 $this->assertGreaterThanOrEqual(1, count($content));
191 $this->assertArrayHasKey('items', $content['_embedded']);
192 $this->assertGreaterThanOrEqual(1, $content['total']);
193 $this->assertEquals(1, $content['page']);
194 $this->assertEquals(30, $content['limit']);
195 $this->assertGreaterThanOrEqual(1, $content['pages']);
196
197 $this->assertArrayHasKey('_links', $content);
198 $this->assertArrayHasKey('self', $content['_links']);
199 $this->assertArrayHasKey('first', $content['_links']);
200 $this->assertArrayHasKey('last', $content['_links']);
201
202 foreach (['self', 'first', 'last'] as $link) {
203 $this->assertArrayHasKey('href', $content['_links'][$link]);
204 $this->assertContains('public=1', $content['_links'][$link]['href']);
157 } 205 }
158 206
159 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 207 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
@@ -348,6 +396,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
348 'language' => 'de', 396 'language' => 'de',
349 'published_at' => '2016-09-08T11:55:58+0200', 397 'published_at' => '2016-09-08T11:55:58+0200',
350 'authors' => 'bob,helen', 398 'authors' => 'bob,helen',
399 'public' => 1,
351 ]); 400 ]);
352 401
353 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 402 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -367,6 +416,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
367 $this->assertCount(2, $content['published_by']); 416 $this->assertCount(2, $content['published_by']);
368 $this->assertContains('bob', $content['published_by']); 417 $this->assertContains('bob', $content['published_by']);
369 $this->assertContains('helen', $content['published_by']); 418 $this->assertContains('helen', $content['published_by']);
419 $this->assertTrue($content['is_public'], 'A public link has been generated for that entry');
370 } 420 }
371 421
372 public function testPostSameEntry() 422 public function testPostSameEntry()
@@ -481,6 +531,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
481 'preview_picture' => 'http://preview.io/picture.jpg', 531 'preview_picture' => 'http://preview.io/picture.jpg',
482 'authors' => 'bob,sponge', 532 'authors' => 'bob,sponge',
483 'content' => 'awesome', 533 'content' => 'awesome',
534 'public' => 0,
484 ]); 535 ]);
485 536
486 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 537 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -497,6 +548,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
497 $this->assertContains('sponge', $content['published_by']); 548 $this->assertContains('sponge', $content['published_by']);
498 $this->assertContains('bob', $content['published_by']); 549 $this->assertContains('bob', $content['published_by']);
499 $this->assertEquals('awesome', $content['content']); 550 $this->assertEquals('awesome', $content['content']);
551 $this->assertFalse($content['is_public'], 'Entry is no more shared');
500 } 552 }
501 553
502 public function testPatchEntryWithoutQuotes() 554 public function testPatchEntryWithoutQuotes()
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 8f5c372d..853f37f2 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -860,6 +860,20 @@ class EntryControllerTest extends WallabagCoreTestCase
860 $this->assertCount(1, $crawler->filter('div[class=entry]')); 860 $this->assertCount(1, $crawler->filter('div[class=entry]'));
861 } 861 }
862 862
863 public function testFilterOnIsPublic()
864 {
865 $this->logInAs('admin');
866 $this->useTheme('baggy');
867 $client = $this->getClient();
868
869 $crawler = $client->request('GET', '/unread/list');
870 $form = $crawler->filter('button[id=submit-filter]')->form();
871 $form['entry_filter[isPublic]']->tick();
872
873 $crawler = $client->submit($form);
874 $this->assertCount(0, $crawler->filter('div[class=entry]'));
875 }
876
863 public function testPreviewPictureFilter() 877 public function testPreviewPictureFilter()
864 { 878 {
865 $this->logInAs('admin'); 879 $this->logInAs('admin');