Skip to content

Commit

Permalink
Setting to make On This Day smart album public (#1708)
Browse files Browse the repository at this point in the history
* Setting to make On This Day smart album public
* Share On This Day smart album - tests
  • Loading branch information
aldjordje authored Jan 18, 2023
1 parent 88e2aad commit 7d6dfa1
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 27 deletions.
3 changes: 2 additions & 1 deletion app/SmartAlbums/OnThisDayAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Exceptions\ConfigurationKeyMissingException;
use App\Exceptions\Internal\FrameworkException;
use App\Facades\Lang;
use App\Models\Configs;
use Carbon\Exceptions\InvalidFormatException;
use Carbon\Exceptions\InvalidTimeZoneException;
use Illuminate\Database\Eloquent\Builder;
Expand All @@ -28,7 +29,7 @@ protected function __construct()
parent::__construct(
self::ID,
Lang::get('ON_THIS_DAY'),
false,
Configs::getValueAsBool('public_on_this_day'),
function (Builder $query) use ($today) {
$query->where(fn (Builder $q) => $q
->whereMonth('photos.taken_at', '=', $today->month)
Expand Down
35 changes: 35 additions & 0 deletions database/migrations/2023_01_09_133603_public_on_this_day.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
DB::table('configs')->insert([
[
'key' => 'public_on_this_day',
'value' => '0',
'cat' => 'Smart Albums',
'type_range' => '0|1',
'confidentiality' => '0',
'description' => 'Make "On This Day" smart album accessible to anonymous users',
],
]);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
DB::table('configs')->where('key', '=', 'public_on_this_day')->delete();
}
};
1 change: 1 addition & 0 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ abstract class AbstractTestCase extends BaseTestCase
public const CONFIG_PUBLIC_RECENT = 'public_recent';
public const CONFIG_PUBLIC_SEARCH = 'public_search';
public const CONFIG_PUBLIC_STARRED = 'public_starred';
public const CONFIG_PUBLIC_ON_THIS_DAY = 'public_on_this_day';
public const CONFIG_RAW_FORMATS = 'raw_formats';

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/Base/BaseSharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
namespace Tests\Feature\Base;

use App\Models\Configs;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Tests\AbstractTestCase;
use Tests\Feature\Lib\RootAlbumUnitTest;
use Tests\Feature\Lib\SharingUnitTest;
Expand Down Expand Up @@ -138,6 +140,9 @@ abstract class BaseSharingTest extends BasePhotoTest
/** @var bool the previously configured public visibility for "Starred" */
private bool $isStarredAlbumPublic;

/** @var bool the previously configured public visibility for "On This Day" */
private bool $isOnThisDayAlbumPublic;

public function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -166,6 +171,8 @@ public function setUp(): void
Configs::set(AbstractTestCase::CONFIG_PUBLIC_RECENT, true);
$this->isStarredAlbumPublic = Configs::getValueAsBool(AbstractTestCase::CONFIG_PUBLIC_STARRED);
Configs::set(AbstractTestCase::CONFIG_PUBLIC_STARRED, true);
$this->isOnThisDayAlbumPublic = Configs::getValueAsBool(AbstractTestCase::CONFIG_PUBLIC_ON_THIS_DAY);
Configs::set(AbstractTestCase::CONFIG_PUBLIC_ON_THIS_DAY, true);
$this->clearCachedSmartAlbums();
}

Expand All @@ -178,6 +185,7 @@ public function tearDown(): void

Configs::set(AbstractTestCase::CONFIG_PUBLIC_RECENT, $this->isRecentAlbumPublic);
Configs::set(AbstractTestCase::CONFIG_PUBLIC_STARRED, $this->isStarredAlbumPublic);
Configs::set(AbstractTestCase::CONFIG_PUBLIC_ON_THIS_DAY, $this->isOnThisDayAlbumPublic);
$this->clearCachedSmartAlbums();

$this->tearDownRequiresEmptyPhotos();
Expand Down Expand Up @@ -238,4 +246,18 @@ protected function generateExpectedSmartAlbumJson(
'policy' => ['is_public' => $isPublic],
];
}

protected function ensurePhotosWereTakenOnThisDay(string ...$photoIds): void
{
DB::table('photos')
->whereIn('id', $photoIds)
->update(['taken_at' => (Carbon::today())->subYear()->format('Y-m-d H:i:s.u')]);
}

protected function ensurePhotosWereNotTakenOnThisDay(string ...$photoIds): void
{
DB::table('photos')
->whereIn('id', $photoIds)
->update(['taken_at' => (Carbon::today())->subMonth()->format('Y-m-d H:i:s.u')]);
}
}
Loading

0 comments on commit 7d6dfa1

Please sign in to comment.