Set and enforce maximum amount of spaces per plan
MODIFY
.env.example
.env.example
@@ -33,3 +33,7 @@ PUSHER_APP_KEY=
PUSHER_APP_SECRET=
SUGGESTION_BOX_ENABLED=false
+
+PLANS_ENABLED=false
+PLANS_STANDARD_MAXIMUM_SPACES=2
+PLANS_PREMIUM_MAXIMUM_SPACES=null

MODIFY
.env.travis
.env.travis
@@ -33,3 +33,7 @@ PUSHER_APP_KEY=
PUSHER_APP_SECRET=
SUGGESTION_BOX_ENABLED=false
+
+PLANS_ENABLED=true
+PLANS_STANDARD_MAXIMUM_SPACES=2
+PLANS_PREMIUM_MAXIMUM_SPACES=null

MODIFY
app/Helper.php
app/Helper.php
@@ -29,4 +29,9 @@ class Helper
return array_search(max($delimiters), $delimiters);
}
+
+ public static function arePlansEnabled(): bool
+ {
+ return env('PLANS_ENABLED', false);
+ }
}

MODIFY
app/Http/Controllers/SpaceController.php
app/Http/Controllers/SpaceController.php
@@ -32,6 +32,12 @@ class SpaceController extends Controller
'currency_id' => 'required|exists:currencies,id'
]);
+ if (!$request->user()->can('create', Space::class)) {
+ $request->session()->flash('maximum_reached', true);
+
+ return redirect()->route('spaces.create');
+ }
+
(new CreateSpaceAction())->execute($request->name, $request->currency_id, Auth::id());
return redirect()->route('settings.spaces.index');

MODIFY
app/Http/Controllers/SpaceInviteController.php
app/Http/Controllers/SpaceInviteController.php
@@ -39,6 +39,15 @@ class SpaceInviteController extends Controller
abort(410);
}
+ if (!$request->user()->can('accept', SpaceInvite::class)) {
+ $request->session()->flash('maximum_reached', true);
+
+ return redirect()->route('space_invites.show', [
+ 'space' => $space->id,
+ 'invite' => $invite->id
+ ]);
+ }
+
(new AcceptSpaceInviteAction())->execute($invite->id);
return redirect()->route('settings.spaces.index');

MODIFY
app/Policies/SpaceInvitePolicy.php
app/Policies/SpaceInvitePolicy.php
namespace App\Policies;
+use App\Helper;
use App\Models\SpaceInvite;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
@@ -14,4 +15,20 @@ class SpaceInvitePolicy
{
return $invite->invitee_user_id === $user->id;
}
+
+ public function accept(User $user): bool
+ {
+ $maximumSpaces = config('plans.' . $user->plan . '.maximum_spaces');
+
+ if (
+ Helper::arePlansEnabled()
+ && $user->plan === 'standard'
+ && $maximumSpaces
+ && $user->spaces->count() >= $maximumSpaces
+ ) {
+ return false;
+ }
+
+ return true;
+ }
}

MODIFY
app/Policies/SpacePolicy.php
app/Policies/SpacePolicy.php
namespace App\Policies;
+use App\Helper;
use App\Models\Space;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
@@ -10,6 +11,22 @@ class SpacePolicy
{
use HandlesAuthorization;
+ public function create(User $user): bool
+ {
+ $maximumSpaces = config('plans.' . $user->plan . '.maximum_spaces');
+
+ if (
+ Helper::arePlansEnabled()
+ && $user->plan === 'standard'
+ && $maximumSpaces
+ && $user->spaces->count() >= $maximumSpaces
+ ) {
+ return false;
+ }
+
+ return true;
+ }
+
public function edit(User $user, Space $space): bool
{
$usersSpace = $user->spaces

ADD
config/plans.php
+<?php
+
+return [
+ 'standard' => [
+ 'maximum_spaces' => env('PLANS_STANDARD_MAXIMUM_SPACES')
+ ],
+
+ 'premium' => [
+ 'maximum_spaces' => env('PLANS_PREMIUM_MAXIMUM_SPACES')
+ ]
+];

MODIFY
resources/assets/sass/components/typography.scss
resources/assets/sass/components/typography.scss
@@ -48,4 +48,8 @@ a {
&-light {
color: #CCC;
}
+
+ &-red {
+ color: $colors-red;
+ }
}

MODIFY
resources/views/space_invites/show.blade.php
resources/views/space_invites/show.blade.php
@section('body')
<div class="wrapper wrapper--narrow my-3">
<h2>{{ __('general.invite') }}</h2>
+ @if (Session::get('maximum_reached') === true)
+ <div class="mt-3 c-red" style="line-height: 150%;">You have reached the maximum amount of spaces you can be part of.</div>
+ @endif
<div class="box mt-3">
<div class="box__section">
<h3 class="color-dark mb-1">{{ __('general.invited_to') }} "{{ $invite->space->name }}"</h3>

MODIFY
resources/views/spaces/create.blade.php
resources/views/spaces/create.blade.php
@section('body')
<div class="wrapper my-3">
<h2 class="mb-3">{{ __('actions.create') }} {{ __('models.space') }}</h2>
+ @if (Session::get('maximum_reached') === true)
+ <div class="mt-3 c-red" style="line-height: 150%;">You have reached the maximum amount of spaces you can be part of.</div>
+ @endif
<div class="box mt-3">
<form method="POST" action="{{ route('spaces.store') }}" autocomplete="off">
{{ csrf_field() }}

Set and enforce maximum amount of spaces per plan