diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 7ebcda5eba44..4fa44c019a2a 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 a5e99de0b00e..77ab97a7d900 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/Http/Controllers/TwoFactorController.php b/app/Http/Controllers/TwoFactorController.php index 2fddbe371491..cbee6da80188 100644 --- a/app/Http/Controllers/TwoFactorController.php +++ b/app/Http/Controllers/TwoFactorController.php @@ -24,7 +24,7 @@ class TwoFactorController extends BaseController return response()->json(['message' => '2FA already enabled'], 400); elseif(! $user->phone) return response()->json(['message' => ctrans('texts.set_phone_for_two_factor')], 400); - elseif(! $user->confirmed) + elseif(! $user->isVerified()) return response()->json(['message' => 'Please confirm your account first'], 400); $google2fa = new Google2FA(); diff --git a/app/Http/Controllers/WebCronController.php b/app/Http/Controllers/WebCronController.php new file mode 100644 index 000000000000..29dd13c05f6e --- /dev/null +++ b/app/Http/Controllers/WebCronController.php @@ -0,0 +1,75 @@ +json(['message' => 'Web cron has not been configured'], 403); + + if($request->has('secret') && (config('ninja.webcron_secret') == $request->query('secret'))) + { + Artisan::call('schedule:run'); + + return response()->json(['message' => 'Executing web cron'], 200); + } + + return response()->json(['message' => 'Invalid secret'], 403); + + } +} diff --git a/app/Models/Account.php b/app/Models/Account.php index e817f5c4a866..737abe457853 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; diff --git a/config/ninja.php b/config/ninja.php index a0634910d285..7599c029b53c 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -141,4 +141,5 @@ return [ 'snappdf_chromium_path' => env('SNAPPDF_CHROMIUM_PATH', false), 'v4_migration_version' => '4.5.31', 'flutter_canvas_kit' => env('FLUTTER_CANVAS_KIT', false), + 'webcron_secret' => env('WEBCRON_SECRET', false), ]; diff --git a/routes/api.php b/routes/api.php index 45d6d5683b4e..a503f03d9765 100644 --- a/routes/api.php +++ b/routes/api.php @@ -182,5 +182,5 @@ Route::match(['get', 'post'], 'payment_webhook/{company_key}/{company_gateway_id Route::post('api/v1/postmark_webhook', 'PostMarkController@webhook'); Route::get('token_hash_router', 'OneTimeTokenController@router'); - +Route::get('webcron', 'WebCronController@index'); Route::fallback('BaseController@notFound');