From f4d1917f32d2ecf60f8bf1dfbd73395e9a70a23a Mon Sep 17 00:00:00 2001 From: = Date: Sun, 7 Mar 2021 21:14:53 +1100 Subject: [PATCH] Hosted feature implementation --- app/Http/Controllers/BaseController.php | 14 ++++++++++++++ app/Http/Controllers/InvoiceController.php | 5 ++++- app/Models/Account.php | 8 ++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 7ebcda5eba..4fa44c019a 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -504,4 +504,18 @@ class BaseController extends Controller return redirect('/setup'); } + + public function checkFeature($feature) + { + + if(auth()->user()->account->hasFeature($feature)) + return true; + + return false; + } + + public function featureFailure() + { + return response()->json(['message' => 'Upgrade to a paid plan for this feature.'], 403); + } } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index a5e99de0b0..77ab97a7d9 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -30,6 +30,7 @@ use App\Jobs\Entity\EmailEntity; use App\Jobs\Invoice\StoreInvoice; use App\Jobs\Invoice\ZipInvoices; use App\Jobs\Util\UnlinkFile; +use App\Models\Account; use App\Models\Client; use App\Models\Invoice; use App\Models\Quote; @@ -906,7 +907,9 @@ class InvoiceController extends BaseController */ public function upload(UploadInvoiceRequest $request, Invoice $invoice) { - + if(!$this->checkFeature(Account::FEATURE_DOCUMENTS)) + return $this->featureFailure(); + if ($request->has('documents')) $this->saveDocuments($request->file('documents'), $invoice); diff --git a/app/Models/Account.php b/app/Models/Account.php index e817f5c4a8..737abe4578 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -167,17 +167,17 @@ class Account extends BaseModel // Enterprise; No Trial allowed; grandfathered for old pro users case self::FEATURE_USERS:// Grandfathered for old Pro users - if ($planDetails && $planDetails['trial']) { + if ($plan_details && $plan_details['trial']) { // Do they have a non-trial plan? - $planDetails = $this->getPlanDetails(false, false); + $plan_details = $this->getPlanDetails(false, false); } - return $self_host || ! empty($planDetails) && ($planDetails['plan'] == self::PLAN_ENTERPRISE); + return $self_host || ! empty($plan_details) && ($plan_details['plan'] == self::PLAN_ENTERPRISE); // Enterprise; No Trial allowed case self::FEATURE_DOCUMENTS: case self::FEATURE_USER_PERMISSIONS: - return $self_host || ! empty($planDetails) && $planDetails['plan'] == self::PLAN_ENTERPRISE && ! $planDetails['trial']; + return $self_host || ! empty($plan_details) && $plan_details['plan'] == self::PLAN_ENTERPRISE && ! $plan_details['trial']; default: return false;