Fix visibility issue on daily page
This filter (links by day) didn't apply any visibility parameter. Fixes #1543
This commit is contained in:
parent
21163a3329
commit
27ddfec3c3
4 changed files with 56 additions and 9 deletions
|
@ -362,7 +362,9 @@ public function days()
|
||||||
*/
|
*/
|
||||||
public function filterDay($request)
|
public function filterDay($request)
|
||||||
{
|
{
|
||||||
return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request);
|
$visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC;
|
||||||
|
|
||||||
|
return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request, false, $visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -115,7 +115,7 @@ public function filter($type, $request, $casesensitive = false, $visibility = 'a
|
||||||
return $this->filterTags($request, $casesensitive, $visibility);
|
return $this->filterTags($request, $casesensitive, $visibility);
|
||||||
}
|
}
|
||||||
case self::$FILTER_DAY:
|
case self::$FILTER_DAY:
|
||||||
return $this->filterDay($request);
|
return $this->filterDay($request, $visibility);
|
||||||
default:
|
default:
|
||||||
return $this->noFilter($visibility);
|
return $this->noFilter($visibility);
|
||||||
}
|
}
|
||||||
|
@ -425,21 +425,26 @@ public function filterUntagged($visibility)
|
||||||
* print_r($mydb->filterDay('20120125'));
|
* print_r($mydb->filterDay('20120125'));
|
||||||
*
|
*
|
||||||
* @param string $day day to filter.
|
* @param string $day day to filter.
|
||||||
*
|
* @param string $visibility return only all/private/public bookmarks.
|
||||||
|
|
||||||
* @return array all link matching given day.
|
* @return array all link matching given day.
|
||||||
*
|
*
|
||||||
* @throws Exception if date format is invalid.
|
* @throws Exception if date format is invalid.
|
||||||
*/
|
*/
|
||||||
public function filterDay($day)
|
public function filterDay($day, $visibility)
|
||||||
{
|
{
|
||||||
if (!checkDateFormat('Ymd', $day)) {
|
if (!checkDateFormat('Ymd', $day)) {
|
||||||
throw new Exception('Invalid date format');
|
throw new Exception('Invalid date format');
|
||||||
}
|
}
|
||||||
|
|
||||||
$filtered = [];
|
$filtered = [];
|
||||||
foreach ($this->bookmarks as $key => $l) {
|
foreach ($this->bookmarks as $key => $bookmark) {
|
||||||
if ($l->getCreated()->format('Ymd') == $day) {
|
if ($visibility === static::$PUBLIC && $bookmark->isPrivate()) {
|
||||||
$filtered[$key] = $l;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($bookmark->getCreated()->format('Ymd') == $day) {
|
||||||
|
$filtered[$key] = $bookmark;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1061,6 +1061,36 @@ public function testCountTagsNoMarkdown()
|
||||||
$this->assertEquals($expected, $tags, var_export($tags, true));
|
$this->assertEquals($expected, $tags, var_export($tags, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test filterDay while logged in
|
||||||
|
*/
|
||||||
|
public function testFilterDayLoggedIn(): void
|
||||||
|
{
|
||||||
|
$bookmarks = $this->privateLinkDB->filterDay('20121206');
|
||||||
|
$expectedIds = [4, 9, 1, 0];
|
||||||
|
|
||||||
|
static::assertCount(4, $bookmarks);
|
||||||
|
foreach ($bookmarks as $bookmark) {
|
||||||
|
$i = ($i ?? -1) + 1;
|
||||||
|
static::assertSame($expectedIds[$i], $bookmark->getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test filterDay while logged out
|
||||||
|
*/
|
||||||
|
public function testFilterDayLoggedOut(): void
|
||||||
|
{
|
||||||
|
$bookmarks = $this->publicLinkDB->filterDay('20121206');
|
||||||
|
$expectedIds = [4, 9, 1];
|
||||||
|
|
||||||
|
static::assertCount(3, $bookmarks);
|
||||||
|
foreach ($bookmarks as $bookmark) {
|
||||||
|
$i = ($i ?? -1) + 1;
|
||||||
|
static::assertSame($expectedIds[$i], $bookmark->getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to test LinkDB's private methods
|
* Allows to test LinkDB's private methods
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use ReferenceLinkDB;
|
use ReferenceLinkDB;
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\Formatter\FormatterFactory;
|
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +35,7 @@ class BookmarkFilterTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* Instantiate linkFilter with ReferenceLinkDB data.
|
* Instantiate linkFilter with ReferenceLinkDB data.
|
||||||
*/
|
*/
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
$conf = new ConfigManager('tests/utils/config/configJson');
|
$conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$conf->set('resource.datastore', self::$testDatastore);
|
$conf->set('resource.datastore', self::$testDatastore);
|
||||||
|
@ -189,6 +188,17 @@ public function testFilterDay()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return bookmarks for a given day
|
||||||
|
*/
|
||||||
|
public function testFilterDayRestrictedVisibility(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
3,
|
||||||
|
count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206', false, BookmarkFilter::$PUBLIC))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 404 - day not found
|
* 404 - day not found
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue