1313use App \Models \Configs ;
1414use App \Policies \AlbumPolicy ;
1515use Illuminate \Support \Facades \Gate ;
16+ use LycheeVerify \Verify ;
1617use Spatie \LaravelData \Data ;
1718use Spatie \TypeScriptTransformer \Attributes \TypeScript ;
1819
@@ -30,6 +31,7 @@ class AlbumRightsResource extends Data
3031 public bool $ can_access_original = false ;
3132 public bool $ can_pasword_protect = false ;
3233 public bool $ can_import_from_server = false ;
34+ public bool $ can_make_purchasable = false ;
3335
3436 /**
3537 * Given an album, returns the access rights associated to it.
@@ -47,5 +49,28 @@ public function __construct(?AbstractAlbum $abstract_album)
4749 $ this ->can_access_original = Gate::check (AlbumPolicy::CAN_ACCESS_FULL_PHOTO , [AbstractAlbum::class, $ abstract_album ]);
4850 $ this ->can_pasword_protect = !Configs::getValueAsBool ('cache_enabled ' );
4951 $ this ->can_import_from_server = Gate::check (AlbumPolicy::CAN_IMPORT_FROM_SERVER , [AbstractAlbum::class]);
52+ $ this ->can_make_purchasable = $ this ->canMakePurchasable ($ abstract_album );
53+ }
54+
55+ /**
56+ * Check if the user can make the album purchasable.
57+ * This requires the user to be a supporter and have the relevant permission.
58+ *
59+ * @param AbstractAlbum|null $abstract_album
60+ *
61+ * @return bool
62+ */
63+ public function canMakePurchasable (?AbstractAlbum $ abstract_album ): bool
64+ {
65+ if (!$ abstract_album instanceof Album) {
66+ return false ;
67+ }
68+
69+ $ verify = resolve (Verify::class);
70+ if (!$ verify ->is_supporter ()) {
71+ return false ;
72+ }
73+
74+ return Gate::check (AlbumPolicy::CAN_MAKE_PURCHASABLE , [AbstractAlbum::class]);
5075 }
5176}
0 commit comments