1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Observers and policy scaffold

This commit is contained in:
David Bomba 2021-03-05 21:18:28 +11:00
parent 2a27562f29
commit 1599711dee
9 changed files with 278 additions and 1 deletions

View File

@ -11,6 +11,7 @@
namespace App\Console;
use App\Jobs\Cron\BillingSubscriptionCron;
use App\Jobs\Cron\RecurringInvoicesCron;
use App\Jobs\Ninja\AdjustEmailQuota;
use App\Jobs\Ninja\CompanySizeCheck;
@ -53,6 +54,8 @@ class Kernel extends ConsoleKernel
$schedule->job(new UpdateExchangeRates)->daily()->withoutOverlapping();
$schedule->job(new BillingSubscriptionCron)->daily()->withoutOverlapping();
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping();
/* Run hosted specific jobs */

View File

@ -0,0 +1,52 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Cron;
use App\Libraries\MultiDB;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Carbon;
class BillingSubscriptionCron
{
use Dispatchable;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle() : void
{
/* Get all invoices where the send date is less than NOW + 30 minutes() */
if (! config('ninja.db.multi_db_enabled')) {
} else {
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
}
}
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class BillingSubscription extends BaseModel
{
use HasFactory;
}

View File

@ -0,0 +1,19 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class ClientSubscription extends BaseModel
{
use HasFactory;
}

View File

@ -0,0 +1,72 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Observers;
use App\Models\BillingSubscription;
class BillingSubscriptionObserver
{
/**
* Handle the billing_subscription "created" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function created(BillingSubscription $billing_subscription)
{
//
}
/**
* Handle the billing_subscription "updated" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function updated(BillingSubscription $billing_subscription)
{
//
}
/**
* Handle the billing_subscription "deleted" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function deleted(BillingSubscription $billing_subscription)
{
//
}
/**
* Handle the billing_subscription "restored" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function restored(BillingSubscription $billing_subscription)
{
//
}
/**
* Handle the billing_subscription "force deleted" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function forceDeleted(BillingSubscription $billing_subscription)
{
//
}
}

View File

@ -0,0 +1,72 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Observers;
use App\Models\ClientSubscription;
class ClientSubscriptionObserver
{
/**
* Handle the client_subscription "created" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function created(ClientSubscription $client_subscription)
{
//
}
/**
* Handle the client_subscription "updated" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function updated(ClientSubscription $client_subscription)
{
//
}
/**
* Handle the client_subscription "deleted" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function deleted(ClientSubscription $client_subscription)
{
//
}
/**
* Handle the client_subscription "restored" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function restored(ClientSubscription $client_subscription)
{
//
}
/**
* Handle the client_subscription "force deleted" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function forceDeleted(ClientSubscription $client_subscription)
{
//
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Policies;
use App\Models\User;
/**
* Class BillingSubscriptionPolicy.
*/
class BillingSubscriptionPolicy extends EntityPolicy
{
/**
* Checks if the user has create permissions.
*
* @param User $user
* @return bool
*/
public function create(User $user) : bool
{
return $user->isAdmin() || $user->hasPermission('create_billing_subscription') || $user->hasPermission('create_all');
}
}

View File

@ -12,7 +12,9 @@
namespace App\Providers;
use App\Models\Account;
use App\Models\BillingSubscription;
use App\Models\Client;
use App\Models\ClientSubscription;
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\CompanyToken;
@ -26,7 +28,9 @@ use App\Models\Quote;
use App\Models\Task;
use App\Models\User;
use App\Observers\AccountObserver;
use App\Observers\BillingSubscriptionObserver;
use App\Observers\ClientObserver;
use App\Observers\ClientSubscriptionObserver;
use App\Observers\CompanyGatewayObserver;
use App\Observers\CompanyObserver;
use App\Observers\CompanyTokenObserver;
@ -75,9 +79,10 @@ class AppServiceProvider extends ServiceProvider
Schema::defaultStringLength(191);
User::observe(UserObserver::class);
Account::observe(AccountObserver::class);
BillingSubscription::observe(BillingSubscriptionObserver::class);
Client::observe(ClientObserver::class);
ClientSubscription::observe(ClientSubscriptionObserver::class);
Company::observe(CompanyObserver::class);
CompanyGateway::observe(CompanyGatewayObserver::class);
CompanyToken::observe(CompanyTokenObserver::class);
@ -89,6 +94,7 @@ class AppServiceProvider extends ServiceProvider
Proposal::observe(ProposalObserver::class);
Quote::observe(QuoteObserver::class);
Task::observe(TaskObserver::class);
User::observe(UserObserver::class);
// Queue::before(function (JobProcessing $event) {
// // \Log::info('Event Job '.$event->connectionName);

View File

@ -12,6 +12,7 @@
namespace App\Providers;
use App\Models\Activity;
use App\Models\BillingSubscription;
use App\Models\Client;
use App\Models\Company;
use App\Models\CompanyGateway;
@ -37,6 +38,7 @@ use App\Models\User;
use App\Models\Vendor;
use App\Models\Webhook;
use App\Policies\ActivityPolicy;
use App\Policies\BillingSubscriptionPolicy;
use App\Policies\ClientPolicy;
use App\Policies\CompanyGatewayPolicy;
use App\Policies\CompanyPolicy;
@ -73,6 +75,7 @@ class AuthServiceProvider extends ServiceProvider
*/
protected $policies = [
Activity::class => ActivityPolicy::class,
BillingSubscription::class => BillingSubscriptionPolicy::class,
Client::class => ClientPolicy::class,
Company::class => CompanyPolicy::class,
CompanyToken::class => CompanyTokenPolicy::class,