Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart album - On This Day - new feature #1607

Merged
merged 19 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Factories/AlbumFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\Extensions\BaseAlbum;
use App\Models\TagAlbum;
use App\SmartAlbums\BaseSmartAlbum;
use App\SmartAlbums\OnThisDayAlbum;
use App\SmartAlbums\PublicAlbum;
use App\SmartAlbums\RecentAlbum;
use App\SmartAlbums\StarredAlbum;
Expand All @@ -24,6 +25,7 @@ class AlbumFactory
StarredAlbum::ID => StarredAlbum::class,
PublicAlbum::ID => PublicAlbum::class,
RecentAlbum::ID => RecentAlbum::class,
OnThisDayAlbum::ID => OnThisDayAlbum::class,
];

/**
Expand Down
1 change: 1 addition & 0 deletions app/Locale/ChineseSimplified.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => '星标',
'RECENT' => '最新',
'PUBLIC' => '公开',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => '照片',

'CREATE_ALBUM' => '创建相册',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/ChineseTraditional.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => '我的最愛',
'RECENT' => '最新',
'PUBLIC' => '公開',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => '照片',

'CREATE_ALBUM' => '創建相簿',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Czech.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Oblíbené',
'RECENT' => 'Poslední',
'PUBLIC' => 'Veřejné',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'fotografií',

'CREATE_ALBUM' => 'Vytvořit album',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Dutch.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Met ster',
'RECENT' => 'Recentelijk',
'PUBLIC' => 'Publiekelijk',
'ON_THIS_DAY' => 'Deze Dag',
'NUM_PHOTOS' => 'Foto’s',

'CREATE_ALBUM' => 'Maak Album',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/English.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Starred',
'RECENT' => 'Recent',
'PUBLIC' => 'Public',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Photos',

'CREATE_ALBUM' => 'Create Album',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/French.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Favoris',
'RECENT' => 'Récent',
'PUBLIC' => 'Public',
'ON_THIS_DAY' => 'Ce jour-là',
'NUM_PHOTOS' => 'Photos',

'CREATE_ALBUM' => 'Créer un album',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/German.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Favoriten',
'RECENT' => 'Zuletzt benutzt',
'PUBLIC' => 'Öffentlich',
'ON_THIS_DAY' => 'An diesem Tag',
'NUM_PHOTOS' => 'Fotos',

'CREATE_ALBUM' => 'Album erstellen',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Greek.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Με Αστέρι',
'RECENT' => 'Πρόσφατα',
'PUBLIC' => 'Δημόσια',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Φωτογραφίες',

'CREATE_ALBUM' => 'Δημιουργία Λευκώματος',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Italian.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Speciali',
'RECENT' => 'Recenti',
'PUBLIC' => 'Pubbliche',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Foto',

'CREATE_ALBUM' => 'Crea Album',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/NorwegianBokmal.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Favoritter',
'RECENT' => 'Nylige',
'PUBLIC' => 'Offentlige',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Bilder',

'CREATE_ALBUM' => 'Lag Album',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Polish.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Oznaczone',
'RECENT' => 'Ostatnie',
'PUBLIC' => 'Publiczne',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Zdjęć',

'CREATE_ALBUM' => 'Utwórz album',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Portuguese.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Favoritas',
'RECENT' => 'Recentes',
'PUBLIC' => 'Públicas',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Fotografias',

'CREATE_ALBUM' => 'Criar Álbum',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Russian.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Отмеченные',
'RECENT' => 'Последние',
'PUBLIC' => 'Общие',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'фотографий',

'CREATE_ALBUM' => 'Создать альбом',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Slovak.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Obľúbený',
'RECENT' => 'Naposledy použitý',
'PUBLIC' => 'Verejný',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'obrázkov',

'CREATE_ALBUM' => 'Album vytvoriť',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Spanish.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Destacado',
'RECENT' => 'Reciente',
'PUBLIC' => 'Público',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Fotos',

'CREATE_ALBUM' => 'Crear Álbum',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Swedish.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Stjärnmärkta',
'RECENT' => 'Nyligen',
'PUBLIC' => 'Publika',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Fotografier',

'CREATE_ALBUM' => 'Skapa album',
Expand Down
1 change: 1 addition & 0 deletions app/Locale/Vietnamese.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function get_locale(): array
'STARRED' => 'Được dánh dấu sao',
'RECENT' => 'Gần đây',
'PUBLIC' => 'Công cộng',
'ON_THIS_DAY' => 'On This Day',
'NUM_PHOTOS' => 'Hình ảnh',

'CREATE_ALBUM' => 'Tạo album',
Expand Down
43 changes: 43 additions & 0 deletions app/SmartAlbums/OnThisDayAlbum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\SmartAlbums;

use App\Exceptions\ConfigurationKeyMissingException;
use App\Exceptions\Internal\FrameworkException;
use Carbon\Exceptions\InvalidFormatException;
use Carbon\Exceptions\InvalidTimeZoneException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;

class OnThisDayAlbum extends BaseSmartAlbum
{
private static ?self $instance = null;
public const ID = 'on_this_day';
public const TITLE = 'On This Day';

/**
* @throws InvalidFormatException
* @throws InvalidTimeZoneException
* @throws ConfigurationKeyMissingException
* @throws FrameworkException
*/
protected function __construct()
{
$today = Carbon::today();

parent::__construct(
self::ID,
self::TITLE,
false,
function (Builder $query) use ($today) {
$query->whereMonth('photos.taken_at', '=', $today->month)
->whereDay('photos.taken_at', '=', $today->day);
}
);
}

public static function getInstance(): self
{
return self::$instance ??= new self();
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ parameters:
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Extensions\\FixedQueryBuilder)(<.*>)?::insert\(\).#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Extensions\\FixedQueryBuilder)(<.*>)?::select\(\).#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Extensions\\FixedQueryBuilder)(<.*>)?::orderBy\(\)#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Extensions\\FixedQueryBuilder)(<.*>)?::where(Not)?(Null|In|Between|Exists|Column)?\(\).#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Extensions\\FixedQueryBuilder)(<.*>)?::where(Not)?(Null|In|Between|Exists|Column|Year|Month|Day)?\(\).#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Extensions\\FixedQueryBuilder)(<.*>)?::delete\(\)#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Extensions\\FixedQueryBuilder)(<.*>)?::without\(\)#'
- '#Dynamic call to static method (Illuminate\\Database\\Query\\Builder|Illuminate\\Database\\Eloquent\\(Builder|Relations\\.*)|App\\Models\\Extensions\\FixedQueryBuilder)(<.*>)?::count\(\).#'
Expand Down
3 changes: 3 additions & 0 deletions tests/Feature/AlbumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Tests\Feature;

use App\Models\Configs;
use App\SmartAlbums\OnThisDayAlbum;
use App\SmartAlbums\PublicAlbum;
use App\SmartAlbums\RecentAlbum;
use App\SmartAlbums\StarredAlbum;
Expand Down Expand Up @@ -79,6 +80,7 @@ public function testAddNotLogged(): void
$this->albums_tests->get(StarredAlbum::ID, 401);
$this->albums_tests->get(PublicAlbum::ID, 401);
$this->albums_tests->get(UnsortedAlbum::ID, 401);
$this->albums_tests->get(OnThisDayAlbum::ID, 401);

// Ensure that we get proper 404 (not found) response for a
// non-existing album, not a false 403 (forbidden) response
Expand All @@ -94,6 +96,7 @@ public function testAddReadLogged(): void
$this->albums_tests->get(StarredAlbum::ID);
$this->albums_tests->get(PublicAlbum::ID);
$this->albums_tests->get(UnsortedAlbum::ID);
$this->albums_tests->get(OnThisDayAlbum::ID);

$albumID1 = $this->albums_tests->add(null, 'test_album')->offsetGet('id');
$albumID2 = $this->albums_tests->add(null, 'test_album2')->offsetGet('id');
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/GeoDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public function testThumbnailsInsideHiddenAlbum(): void
'unsorted' => null,
'starred' => null,
'public' => null,
'on_this_day' => null,
'recent' => ['thumb' => null],
],
'tag_albums' => [],
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Traits/InteractWithSmartAlbums.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Tests\Feature\Traits;

use App\SmartAlbums\OnThisDayAlbum;
use App\SmartAlbums\PublicAlbum;
use App\SmartAlbums\RecentAlbum;
use App\SmartAlbums\StarredAlbum;
Expand All @@ -33,6 +34,7 @@ protected function clearCachedSmartAlbums(): void
RecentAlbum::class,
StarredAlbum::class,
UnsortedAlbum::class,
OnThisDayAlbum::class,
] as $smartAlbumClass) {
$reflection = new \ReflectionClass($smartAlbumClass);
$reflection->setStaticPropertyValue('instance', null);
Expand Down
67 changes: 36 additions & 31 deletions tests/Feature/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Legacy\AdminAuthentication;
use App\Models\Configs;
use App\Models\User;
use App\SmartAlbums\OnThisDayAlbum;
use App\SmartAlbums\PublicAlbum;
use App\SmartAlbums\StarredAlbum;
use App\SmartAlbums\UnsortedAlbum;
Expand Down Expand Up @@ -90,25 +91,26 @@ public function testUsers(): void
* 19. try access shared pictures (public)
* 20. try access starred pictures
* 21. try access recent pictures
* 22. change password without old password => should fail
* 23. change password with wrong password => should fail
* 24. change username & password with duplicate username => should fail
* 25. change username & password
* 26. log out
* 22. try access on_this_day pictures
* 23. change password without old password => should fail
* 24. change password with wrong password => should fail
* 25. change username & password with duplicate username => should fail
* 26. change username & password
* 27. log out
*
* 27. log as 'test_abcde'
* 28. log out
* 28. log as 'test_abcde'
* 29. log out
*
* 29. log as admin
* 30. delete user
* 31. log out
* 30. log as admin
* 31. delete user
* 32. log out
*
* 32. log as admin
* 33 get email => should be blank
* 34. update email
* 35. get email
* 36 update email to blank
* 37. log out
* 33. log as admin
* 34 get email => should be blank
* 35. update email
* 36. get email
* 37. update email to blank
* 38. log out
*/

// 1
Expand Down Expand Up @@ -187,30 +189,33 @@ public function testUsers(): void
$album_tests->get(UnsortedAlbum::ID, 403);

// 22
$sessions_test->update_login('test_abcde', 'password_testing2', '', 422, 'The old password field is required.');
$album_tests->get(OnThisDayAlbum::ID, 403);

// 23
$sessions_test->update_login('test_abcde', 'password_testing2', 'password_testing2', 401, 'Previous password is invalid');
$sessions_test->update_login('test_abcde', 'password_testing2', '', 422, 'The old password field is required.');

// 24
$sessions_test->update_login('test_abcd2', 'password_testing2', 'password_testing', 409, 'Username already exists');
$sessions_test->update_login('test_abcde', 'password_testing2', 'password_testing2', 401, 'Previous password is invalid');

// 25
$sessions_test->update_login('test_abcdef', 'password_testing2', 'password_testing');
$sessions_test->update_login('test_abcd2', 'password_testing2', 'password_testing', 409, 'Username already exists');

// 26
$sessions_test->logout();
$sessions_test->update_login('test_abcdef', 'password_testing2', 'password_testing');

// 27
$sessions_test->login('test_abcdef', 'password_testing2');
$sessions_test->logout();

// 28
$sessions_test->logout();
$sessions_test->login('test_abcdef', 'password_testing2');

// 29
Auth::loginUsingId(0);
$sessions_test->logout();

// 30
Auth::loginUsingId(0);

// 31
$users_test->delete($id);
$users_test->delete($id2);

Expand All @@ -220,33 +225,33 @@ public function testUsers(): void
$users_test->delete('-1', 422);
$users_test->save('-1', 'toto', 'test', false, true, 422);

// 31
// 32
$sessions_test->logout();

// 32
// 33
Auth::loginUsingId(0);

$configs = Configs::get();
$store_new_photos_notification = $configs['new_photos_notification'];
Configs::set('new_photos_notification', '1');

// 33
// 34
$users_test->get_email();

// 34
// 35
// Note, this must be a proper email address for an existing mail
// domain, as the Laravel validator runs a DNS lookup.
// This means, `[email protected]` though syntactically being
// correct will trigger an error response.
$users_test->update_email('[email protected]');

// 35
// 36
$users_test->get_email();

// 36
// 37
$users_test->update_email(null);

// 37
// 38
$sessions_test->logout();
Configs::set('new_photos_notification', $store_new_photos_notification);
}
Expand Down