|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * Copyright (c) 2017-2018 Tobias Reich |
| 6 | + * Copyright (c) 2018-2026 LycheeOrg. |
| 7 | + */ |
| 8 | + |
| 9 | +namespace App\DTO; |
| 10 | + |
| 11 | +use App\Models\AccessPermission; |
| 12 | +use Illuminate\Support\Collection; |
| 13 | + |
| 14 | +/** |
| 15 | + * Read-only, non-persistable capability snapshot for the current user on an |
| 16 | + * album: the union (logical OR) of every applicable AccessPermission row's |
| 17 | + * grant flags, independent of row order or source (direct-user vs. group). |
| 18 | + */ |
| 19 | +final readonly class EffectiveAccessPermission |
| 20 | +{ |
| 21 | + public function __construct( |
| 22 | + public bool $grants_full_photo_access = false, |
| 23 | + public bool $grants_download = false, |
| 24 | + public bool $grants_upload = false, |
| 25 | + public bool $grants_edit = false, |
| 26 | + public bool $grants_delete = false, |
| 27 | + ) { |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Merge every given AccessPermission row into a single snapshot: each |
| 32 | + * grant flag is true if it is true on at least one row. |
| 33 | + * |
| 34 | + * @param Collection<int,AccessPermission> $permissions |
| 35 | + */ |
| 36 | + public static function merge(Collection $permissions): self |
| 37 | + { |
| 38 | + return new self( |
| 39 | + grants_full_photo_access: $permissions->contains(fn (AccessPermission $p) => $p->grants_full_photo_access), |
| 40 | + grants_download: $permissions->contains(fn (AccessPermission $p) => $p->grants_download), |
| 41 | + grants_upload: $permissions->contains(fn (AccessPermission $p) => $p->grants_upload), |
| 42 | + grants_edit: $permissions->contains(fn (AccessPermission $p) => $p->grants_edit), |
| 43 | + grants_delete: $permissions->contains(fn (AccessPermission $p) => $p->grants_delete), |
| 44 | + ); |
| 45 | + } |
| 46 | +} |
0 commit comments