feat: custom server limit
This commit is contained in:
parent
55dd1ab0a1
commit
297b314904
@ -3,6 +3,7 @@
|
||||
namespace App\Livewire\Server;
|
||||
|
||||
use App\Models\PrivateKey;
|
||||
use App\Models\Team;
|
||||
use Livewire\Component;
|
||||
|
||||
class Create extends Component
|
||||
@ -16,11 +17,7 @@ public function mount()
|
||||
$this->limit_reached = false;
|
||||
return;
|
||||
}
|
||||
$team = currentTeam();
|
||||
$servers = $team->servers->count();
|
||||
['serverLimit' => $serverLimit] = $team->limits;
|
||||
|
||||
$this->limit_reached = $servers >= $serverLimit;
|
||||
$this->limit_reached = Team::serverLimitReached();
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
|
@ -5,6 +5,7 @@
|
||||
use App\Enums\ProxyStatus;
|
||||
use App\Enums\ProxyTypes;
|
||||
use App\Models\Server;
|
||||
use App\Models\Team;
|
||||
use Livewire\Component;
|
||||
|
||||
class ByIp extends Component
|
||||
@ -76,6 +77,9 @@ public function submit()
|
||||
if (is_null($this->private_key_id)) {
|
||||
return $this->dispatch('error', 'You must select a private key');
|
||||
}
|
||||
if (Team::serverLimitReached()) {
|
||||
return $this->dispatch('error', 'You have reached the server limit for your subscription.');
|
||||
}
|
||||
$payload = [
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Livewire\Subscription;
|
||||
|
||||
use App\Models\Team;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Component;
|
||||
|
||||
@ -10,9 +11,7 @@ class Actions extends Component
|
||||
public $server_limits = 0;
|
||||
public function mount()
|
||||
{
|
||||
$limits = currentTeam()->limits;
|
||||
$this->server_limits = data_get($limits, 'serverLimit', 0);
|
||||
|
||||
$this->server_limits = Team::serverLimit();
|
||||
}
|
||||
public function cancel()
|
||||
{
|
||||
|
@ -49,6 +49,16 @@ public function getRecepients($notification)
|
||||
return explode(',', $recipients);
|
||||
}
|
||||
|
||||
static public function serverLimitReached() {
|
||||
$serverLimit = Team::serverLimit();
|
||||
$team = currentTeam();
|
||||
$servers = $team->servers->count();
|
||||
return $servers >= $serverLimit;
|
||||
}
|
||||
static public function serverLimit()
|
||||
{
|
||||
return data_get(Team::find(currentTeam()->id), 'limits.serverLimit', 0);
|
||||
}
|
||||
public function limits(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
@ -63,14 +73,19 @@ public function limits(): Attribute
|
||||
$subscription = $subscription->type();
|
||||
}
|
||||
}
|
||||
if ($this->custom_server_limit) {
|
||||
$serverLimit = $this->custom_server_limit;
|
||||
} else {
|
||||
$serverLimit = config('constants.limits.server')[strtolower($subscription)];
|
||||
}
|
||||
$sharedEmailEnabled = config('constants.limits.email')[strtolower($subscription)];
|
||||
return ['serverLimit' => $serverLimit, 'sharedEmailEnabled' => $sharedEmailEnabled];
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
public function environment_variables() {
|
||||
public function environment_variables()
|
||||
{
|
||||
return $this->hasMany(SharedEnvironmentVariable::class)->whereNull('project_id')->whereNull('environment_id');
|
||||
}
|
||||
public function members()
|
||||
@ -130,7 +145,8 @@ public function s3s()
|
||||
{
|
||||
return $this->hasMany(S3Storage::class)->where('is_usable', true);
|
||||
}
|
||||
public function trialEnded() {
|
||||
public function trialEnded()
|
||||
{
|
||||
foreach ($this->servers as $server) {
|
||||
$server->settings()->update([
|
||||
'is_usable' => false,
|
||||
@ -138,7 +154,8 @@ public function trialEnded() {
|
||||
]);
|
||||
}
|
||||
}
|
||||
public function trialEndedButSubscribed() {
|
||||
public function trialEndedButSubscribed()
|
||||
{
|
||||
foreach ($this->servers as $server) {
|
||||
$server->settings()->update([
|
||||
'is_usable' => true,
|
||||
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('teams', function (Blueprint $table) {
|
||||
$table->integer('custom_server_limit')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('teams', function (Blueprint $table) {
|
||||
$table->dropColumn('custom_server_limit');
|
||||
});
|
||||
}
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
<div class="flex flex-col items-center justify-center h-screen">
|
||||
<span class="text-xl font-bold text-white">You have reached the limit of {{ $name }} you can create.</span>
|
||||
<span>Please <a class="text-white underline "href="{{ route('team.index') }}">upgrade your
|
||||
<span>Please <a class="text-white underline "href="{{ route('subscription.show') }}">upgrade your
|
||||
subscription</a> to create more
|
||||
{{ $name }}.</span>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user