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

Public photos hidden #932

Merged
merged 3 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions app/Actions/Photo/Prepare.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function do(Photo $photo): array
$return['share_button_visible'] = Configs::get_value('share_button_visible', '0');
}
} else {
if ($photo->album_id != null && $photo->album->is_public()) {
$return['public'] = '2';
}
$return['downloadable'] = '1';
$return['share_button_visible'] = '1';
}
Expand Down
17 changes: 10 additions & 7 deletions app/Actions/Search/PhotoSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AccessControl;
use App\Actions\Albums\Extensions\PublicIds;
use App\ModelFunctions\SymLinkFunctions;
use App\Models\Configs;
use App\Models\Photo;
use Illuminate\Database\Eloquent\Builder;

Expand All @@ -24,27 +25,29 @@ public function __construct(
$this->symLinkFunctions = $symLinkFunctions;
}

private function unsorted(Builder $query)
private function unsorted_or_public(Builder $query)
{
if (!AccessControl::is_logged_in()) {
return $query;
}

if (AccessControl::is_admin()) {
return $query->orWhere('album_id', '=', null);
}

if (AccessControl::can_upload()) {
return $query->orWhere(fn ($q) => $q->where('album_id', '=', null)->where('owner_id', '=', AccessControl::id()));
$query = $query->orWhere(fn ($q) => $q->where('album_id', '=', null)->where('owner_id', '=', AccessControl::id()));
}

if (Configs::get_value('public_photos_hidden', '1') === '0') {
$query = $query->orWhere('public', '=', 1);
}

return $query;
}

public function query(array $terms)
{
$albumIDs = resolve(PublicIds::class)->getPublicAlbumsId();

$query = Photo::with('album')
->where(fn ($q) => $this->unsorted($q->whereIn('album_id', $albumIDs)));
->where(fn ($q) => $this->unsorted_or_public($q->whereIn('album_id', $albumIDs)));

foreach ($terms as $escaped_term) {
$query->where(
Expand Down
5 changes: 5 additions & 0 deletions app/SmartAlbums/BareSmartAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AccessControl;
use App\Models\Album;
use App\Models\Configs;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection as BaseCollection;

Expand Down Expand Up @@ -55,6 +56,10 @@ public function filter($query)
$query = $query->whereIn('album_id', $this->albumIds);
}

if (Configs::get_value('public_photos_hidden', '1') === '0') {
$query = $query->orWhere('public', '=', 1);
}

return $query;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use App\Models\Configs;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class ConfigPublicPhotosHidden extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
defined('BOOL') or define('BOOL', '0|1');

DB::table('configs')->insert([
[
'key' => 'public_photos_hidden',
'value' => '1',
'confidentiality' => 2,
'cat' => 'config',
'type_range' => BOOL,
],
]);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Configs::where('key', '=', 'public_photos_hidden')->delete();
}
}
2 changes: 1 addition & 1 deletion public/Lychee-front
6 changes: 3 additions & 3 deletions public/dist/frame.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/dist/landing.js

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions public/dist/main.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions public/dist/view.js

Large diffs are not rendered by default.