diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-09-06 14:11:02 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-09-06 14:11:02 +0200 |
commit | 27ddfec3c3847f10ab0de246f4a174b751c5f19e (patch) | |
tree | 9fb085dd6f83ad73743950ca0de1549f28eeeef5 | |
parent | 21163a3329ef19dc6ebadb75d6452ac02fd59ab3 (diff) | |
download | Shaarli-27ddfec3c3847f10ab0de246f4a174b751c5f19e.tar.gz Shaarli-27ddfec3c3847f10ab0de246f4a174b751c5f19e.tar.zst Shaarli-27ddfec3c3847f10ab0de246f4a174b751c5f19e.zip |
Fix visibility issue on daily page
This filter (links by day) didn't apply any visibility parameter.
Fixes #1543
-rw-r--r-- | application/bookmark/BookmarkFileService.php | 4 | ||||
-rw-r--r-- | application/bookmark/BookmarkFilter.php | 17 | ||||
-rw-r--r-- | tests/bookmark/BookmarkFileServiceTest.php | 30 | ||||
-rw-r--r-- | tests/bookmark/BookmarkFilterTest.php | 14 |
4 files changed, 56 insertions, 9 deletions
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php index e3a61146..c9ec2609 100644 --- a/application/bookmark/BookmarkFileService.php +++ b/application/bookmark/BookmarkFileService.php | |||
@@ -362,7 +362,9 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
362 | */ | 362 | */ |
363 | public function filterDay($request) | 363 | public function filterDay($request) |
364 | { | 364 | { |
365 | return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request); | 365 | $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; |
366 | |||
367 | return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request, false, $visibility); | ||
366 | } | 368 | } |
367 | 369 | ||
368 | /** | 370 | /** |
diff --git a/application/bookmark/BookmarkFilter.php b/application/bookmark/BookmarkFilter.php index 797a36b8..6636bbfe 100644 --- a/application/bookmark/BookmarkFilter.php +++ b/application/bookmark/BookmarkFilter.php | |||
@@ -115,7 +115,7 @@ class BookmarkFilter | |||
115 | return $this->filterTags($request, $casesensitive, $visibility); | 115 | return $this->filterTags($request, $casesensitive, $visibility); |
116 | } | 116 | } |
117 | case self::$FILTER_DAY: | 117 | case self::$FILTER_DAY: |
118 | return $this->filterDay($request); | 118 | return $this->filterDay($request, $visibility); |
119 | default: | 119 | default: |
120 | return $this->noFilter($visibility); | 120 | return $this->noFilter($visibility); |
121 | } | 121 | } |
@@ -425,21 +425,26 @@ class BookmarkFilter | |||
425 | * print_r($mydb->filterDay('20120125')); | 425 | * print_r($mydb->filterDay('20120125')); |
426 | * | 426 | * |
427 | * @param string $day day to filter. | 427 | * @param string $day day to filter. |
428 | * | 428 | * @param string $visibility return only all/private/public bookmarks. |
429 | |||
429 | * @return array all link matching given day. | 430 | * @return array all link matching given day. |
430 | * | 431 | * |
431 | * @throws Exception if date format is invalid. | 432 | * @throws Exception if date format is invalid. |
432 | */ | 433 | */ |
433 | public function filterDay($day) | 434 | public function filterDay($day, $visibility) |
434 | { | 435 | { |
435 | if (!checkDateFormat('Ymd', $day)) { | 436 | if (!checkDateFormat('Ymd', $day)) { |
436 | throw new Exception('Invalid date format'); | 437 | throw new Exception('Invalid date format'); |
437 | } | 438 | } |
438 | 439 | ||
439 | $filtered = []; | 440 | $filtered = []; |
440 | foreach ($this->bookmarks as $key => $l) { | 441 | foreach ($this->bookmarks as $key => $bookmark) { |
441 | if ($l->getCreated()->format('Ymd') == $day) { | 442 | if ($visibility === static::$PUBLIC && $bookmark->isPrivate()) { |
442 | $filtered[$key] = $l; | 443 | continue; |
444 | } | ||
445 | |||
446 | if ($bookmark->getCreated()->format('Ymd') == $day) { | ||
447 | $filtered[$key] = $bookmark; | ||
443 | } | 448 | } |
444 | } | 449 | } |
445 | 450 | ||
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index 7b1906d3..c59fd443 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php | |||
@@ -1062,6 +1062,36 @@ class BookmarkFileServiceTest extends TestCase | |||
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | /** | 1064 | /** |
1065 | * Test filterDay while logged in | ||
1066 | */ | ||
1067 | public function testFilterDayLoggedIn(): void | ||
1068 | { | ||
1069 | $bookmarks = $this->privateLinkDB->filterDay('20121206'); | ||
1070 | $expectedIds = [4, 9, 1, 0]; | ||
1071 | |||
1072 | static::assertCount(4, $bookmarks); | ||
1073 | foreach ($bookmarks as $bookmark) { | ||
1074 | $i = ($i ?? -1) + 1; | ||
1075 | static::assertSame($expectedIds[$i], $bookmark->getId()); | ||
1076 | } | ||
1077 | } | ||
1078 | |||
1079 | /** | ||
1080 | * Test filterDay while logged out | ||
1081 | */ | ||
1082 | public function testFilterDayLoggedOut(): void | ||
1083 | { | ||
1084 | $bookmarks = $this->publicLinkDB->filterDay('20121206'); | ||
1085 | $expectedIds = [4, 9, 1]; | ||
1086 | |||
1087 | static::assertCount(3, $bookmarks); | ||
1088 | foreach ($bookmarks as $bookmark) { | ||
1089 | $i = ($i ?? -1) + 1; | ||
1090 | static::assertSame($expectedIds[$i], $bookmark->getId()); | ||
1091 | } | ||
1092 | } | ||
1093 | |||
1094 | /** | ||
1065 | * Allows to test LinkDB's private methods | 1095 | * Allows to test LinkDB's private methods |
1066 | * | 1096 | * |
1067 | * @see | 1097 | * @see |
diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index d4c71cb9..91e139c2 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php | |||
@@ -6,7 +6,6 @@ use Exception; | |||
6 | use PHPUnit\Framework\TestCase; | 6 | use PHPUnit\Framework\TestCase; |
7 | use ReferenceLinkDB; | 7 | use ReferenceLinkDB; |
8 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
9 | use Shaarli\Formatter\FormatterFactory; | ||
10 | use Shaarli\History; | 9 | use Shaarli\History; |
11 | 10 | ||
12 | /** | 11 | /** |
@@ -36,7 +35,7 @@ class BookmarkFilterTest extends TestCase | |||
36 | /** | 35 | /** |
37 | * Instantiate linkFilter with ReferenceLinkDB data. | 36 | * Instantiate linkFilter with ReferenceLinkDB data. |
38 | */ | 37 | */ |
39 | public static function setUpBeforeClass() | 38 | public static function setUpBeforeClass(): void |
40 | { | 39 | { |
41 | $conf = new ConfigManager('tests/utils/config/configJson'); | 40 | $conf = new ConfigManager('tests/utils/config/configJson'); |
42 | $conf->set('resource.datastore', self::$testDatastore); | 41 | $conf->set('resource.datastore', self::$testDatastore); |
@@ -190,6 +189,17 @@ class BookmarkFilterTest extends TestCase | |||
190 | } | 189 | } |
191 | 190 | ||
192 | /** | 191 | /** |
192 | * Return bookmarks for a given day | ||
193 | */ | ||
194 | public function testFilterDayRestrictedVisibility(): void | ||
195 | { | ||
196 | $this->assertEquals( | ||
197 | 3, | ||
198 | count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206', false, BookmarkFilter::$PUBLIC)) | ||
199 | ); | ||
200 | } | ||
201 | |||
202 | /** | ||
193 | * 404 - day not found | 203 | * 404 - day not found |
194 | */ | 204 | */ |
195 | public function testFilterUnknownDay() | 205 | public function testFilterUnknownDay() |