From d856c34c3f3214c3ba99bcb21fda9ff7a61b9b19 Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Thu, 27 Aug 2020 18:53:13 +0200 Subject: [PATCH] fix subscrpition --- app/Policies/PdfFilePolicy.php | 2 +- app/User.php | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/Policies/PdfFilePolicy.php b/app/Policies/PdfFilePolicy.php index 729719c..8c2d5bc 100644 --- a/app/Policies/PdfFilePolicy.php +++ b/app/Policies/PdfFilePolicy.php @@ -49,7 +49,7 @@ class PdfFilePolicy } - if($pdfFile->is_free || ($user instanceof \App\User ? $user->isSubscribed : false)) { + if($pdfFile->is_free || ($user instanceof \App\User ? $user->hasValidSubscription() : false)) { return true; } diff --git a/app/User.php b/app/User.php index b8d907e..e32fe39 100644 --- a/app/User.php +++ b/app/User.php @@ -204,6 +204,25 @@ class User extends Authenticatable implements MustVerifyEmail return in_array($this->status, $status, true); } + /** + * @return bool + * @todo Add indiv subscription plans + */ + public function hasValidSubscription(): bool + { + return $this->orgIsSubscribed(); + } + + /** + * @return bool + * Checks if affiliated organization has valid subscription + */ + public function orgIsSubscribed(): bool + { + return ($o = $this->organization) === null ? + false: + $o->isSubscribed(); + } @@ -285,13 +304,19 @@ class User extends Authenticatable implements MustVerifyEmail /** * @return bool - * Checks if affiliated organization has valid subscription */ public function getOrgIsSubscribedAttribute(): bool { - return ($o = $this->organization) === null ? - false: - $o->isSubscribed(); + return $this->orgIsSubscribed(); + } + + /** + * @return bool + * Checks if has any valid subscription + */ + public function geHasValidSubscriptionAttribute(): bool + { + return $this->hasValidSubscription(); } -- 2.39.5