coolify/app/Livewire/Team/Member.php

69 lines
2.1 KiB
PHP
Raw Normal View History

2023-06-02 10:34:45 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Team;
2023-06-02 10:34:45 +00:00
use App\Models\User;
2023-09-15 09:19:36 +00:00
use Illuminate\Support\Facades\Cache;
2023-06-02 10:34:45 +00:00
use Livewire\Component;
class Member extends Component
{
public User $member;
2023-06-09 13:55:21 +00:00
public function makeAdmin()
{
try {
if (! auth()->user()->isAdmin()) {
throw new \Exception('You are not authorized to perform this action.');
}
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => 'admin']);
$this->dispatch('reloadWindow');
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
}
2023-06-09 13:55:21 +00:00
}
public function makeOwner()
{
try {
if (! auth()->user()->isOwner()) {
throw new \Exception('You are not authorized to perform this action.');
}
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => 'owner']);
$this->dispatch('reloadWindow');
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
}
}
2024-06-10 20:43:34 +00:00
2023-06-09 13:55:21 +00:00
public function makeReadonly()
{
try {
if (! auth()->user()->isAdmin()) {
throw new \Exception('You are not authorized to perform this action.');
}
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => 'member']);
$this->dispatch('reloadWindow');
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
}
2023-06-09 13:55:21 +00:00
}
2023-06-08 09:43:14 +00:00
public function remove()
2023-06-02 10:34:45 +00:00
{
try {
if (! auth()->user()->isAdmin()) {
throw new \Exception('You are not authorized to perform this action.');
}
$this->member->teams()->detach(currentTeam());
Cache::forget("team:{$this->member->id}");
Cache::remember('team:'.$this->member->id, 3600, function () {
return $this->member->teams()->first();
});
$this->dispatch('reloadWindow');
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
}
2023-06-02 10:34:45 +00:00
}
}