This commit is contained in:
Andras Bacsai
2023-07-13 22:03:27 +02:00
parent e714e87ad6
commit cac59e4873
22 changed files with 405 additions and 234 deletions

View File

@@ -62,13 +62,23 @@ class Controller extends BaseController
public function team()
{
$invitations = [];
if (auth()->user()->isAdmin()) {
if (auth()->user()->isAdminFromSession()) {
$invitations = TeamInvitation::whereTeamId(auth()->user()->currentTeam()->id)->get();
}
return view('team.show', [
'invitations' => $invitations,
]);
}
public function members()
{
$invitations = [];
if (auth()->user()->isAdminFromSession()) {
$invitations = TeamInvitation::whereTeamId(auth()->user()->currentTeam()->id)->get();
}
return view('team.members', [
'invitations' => $invitations,
]);
}
public function acceptInvitation()
{
try {

View File

@@ -22,6 +22,7 @@ class Kernel extends HttpKernel
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\LicenseValid::class,
];
/**
@@ -37,6 +38,8 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\SubscriptionValid::class,
],
'api' => [

View File

@@ -16,10 +16,7 @@ class LicenseValid
*/
public function handle(Request $request, Closure $next): Response
{
if (isCloud()) {
if (isDev()) {
return $next($request);
}
if (isCloud() && !isDev()) {
$value = Cache::get('license_key');
if (!$value) {
ray($request->path());
@@ -30,4 +27,4 @@ class LicenseValid
}
return $next($request);
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Symfony\Component\HttpFoundation\Response;
class SubscriptionValid
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$allowed_paths = [
'team',
'livewire/message/team',
'login',
'register',
'livewire/message/switch-team',
'logout',
];
if (isCloud()) {
if (!$request->user()?->currentTeam()?->subscription && $request->user()?->currentTeam()->subscription?->lemon_status !== 'active') {
if (!in_array($request->path(), $allowed_paths)) {
return redirect('team');
}
}
}
return $next($request);
}
}

View File

@@ -61,8 +61,10 @@ class User extends Authenticatable implements SendsEmail
{
return $this->email;
}
public function isAdmin()
public function isAdmin() {
return $this->pivot->role === 'admin' || $this->pivot->role === 'owner';
}
public function isAdminFromSession()
{
if (auth()->user()->id === 0) {
return true;
@@ -89,6 +91,9 @@ class User extends Authenticatable implements SendsEmail
});
return $found_root_team->count() > 0;
}
public function personalTeam() {
return $this->teams()->where('personal_team', true)->first();
}
public function teams()
{
return $this->belongsToMany(Team::class)->withPivot('role');

View File

@@ -8,4 +8,7 @@ use Illuminate\Database\Eloquent\Model;
class Webhook extends Model
{
protected $guarded = [];
}
protected $casts = [
'payload' => 'encrypted',
];
}

View File

@@ -27,4 +27,4 @@ class Button extends Component
{
return view('components.forms.button');
}
}
}