1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Email Quotas for hosted

This commit is contained in:
= 2021-08-07 19:55:18 +10:00
parent 6202762bbf
commit 0f2ed3fe97
3 changed files with 21 additions and 31 deletions

View File

@ -228,7 +228,8 @@ class NinjaMailerJob implements ShouldQueue
return true;
/* On the hosted platform, if the user is over the email quotas, we do not send the email. */
//if(Ninja::isHosted())
if(Ninja::isHosted() && $this->company->account->emailQuotaExceeded())
return true;
return false;

View File

@ -18,6 +18,7 @@ use Carbon\Carbon;
use DateTime;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Laracasts\Presenter\PresentableTrait;
use Illuminate\Support\Facades\Cache;
class Account extends BaseModel
{
@ -341,4 +342,22 @@ class Account extends BaseModel
}
}
public function getDailyEmailLimit()
{
$limit = config('ninja.daily_email_limit');
$limit += Carbon::createFromTimestamp($this->created_at)->diffInMonths() * 100;
return min($limit, 5000);
}
public function emailQuotaExceeded() :bool
{
if(is_null(Cache::get($this->key)))
return false;
return Cache::get($this->key) > $this->getDailyEmailLimit();
}
}

View File

@ -1,30 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddEmailQuotaToAccountsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('accounts', function (Blueprint $table) {
$table->unsignedInteger('email_quota')->nullable()->default(300);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}