2023-03-17 14:33:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2023-06-12 10:00:01 +00:00
|
|
|
use App\Http\Livewire\Team\Invitations;
|
2023-06-07 13:08:35 +00:00
|
|
|
use App\Models\InstanceSettings;
|
|
|
|
use App\Models\Project;
|
|
|
|
use App\Models\Server;
|
2023-06-12 10:00:01 +00:00
|
|
|
use App\Models\TeamInvitation;
|
|
|
|
use App\Models\User;
|
2023-03-17 14:33:48 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
|
|
use Illuminate\Routing\Controller as BaseController;
|
2023-06-16 13:56:25 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2023-03-17 14:33:48 +00:00
|
|
|
|
|
|
|
class Controller extends BaseController
|
|
|
|
{
|
|
|
|
use AuthorizesRequests, ValidatesRequests;
|
2023-06-07 13:08:35 +00:00
|
|
|
|
2023-06-22 12:48:47 +00:00
|
|
|
public function license()
|
|
|
|
{
|
|
|
|
return view('license');
|
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
public function dashboard()
|
|
|
|
{
|
|
|
|
$projects = Project::ownedByCurrentTeam()->get();
|
|
|
|
$servers = Server::ownedByCurrentTeam()->get();
|
|
|
|
|
|
|
|
$resources = 0;
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
$resources += $project->applications->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('dashboard', [
|
|
|
|
'servers' => $servers->count(),
|
|
|
|
'projects' => $projects->count(),
|
|
|
|
'resources' => $resources,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
public function settings()
|
|
|
|
{
|
2023-06-08 09:43:14 +00:00
|
|
|
if (auth()->user()->isInstanceAdmin()) {
|
2023-06-07 13:08:35 +00:00
|
|
|
$settings = InstanceSettings::get();
|
2023-06-07 20:07:26 +00:00
|
|
|
return view('settings.configuration', [
|
|
|
|
'settings' => $settings
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function emails()
|
|
|
|
{
|
2023-06-08 09:43:14 +00:00
|
|
|
if (auth()->user()->isInstanceAdmin()) {
|
2023-06-07 20:07:26 +00:00
|
|
|
$settings = InstanceSettings::get();
|
|
|
|
return view('settings.emails', [
|
2023-06-07 13:08:35 +00:00
|
|
|
'settings' => $settings
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
}
|
2023-06-09 13:55:21 +00:00
|
|
|
public function team()
|
|
|
|
{
|
|
|
|
$invitations = [];
|
2023-07-13 20:03:27 +00:00
|
|
|
if (auth()->user()->isAdminFromSession()) {
|
2023-06-12 10:00:01 +00:00
|
|
|
$invitations = TeamInvitation::whereTeamId(auth()->user()->currentTeam()->id)->get();
|
2023-06-09 13:55:21 +00:00
|
|
|
}
|
|
|
|
return view('team.show', [
|
|
|
|
'invitations' => $invitations,
|
|
|
|
]);
|
|
|
|
}
|
2023-07-13 20:03:27 +00:00
|
|
|
public function members()
|
|
|
|
{
|
|
|
|
$invitations = [];
|
|
|
|
if (auth()->user()->isAdminFromSession()) {
|
|
|
|
$invitations = TeamInvitation::whereTeamId(auth()->user()->currentTeam()->id)->get();
|
|
|
|
}
|
|
|
|
return view('team.members', [
|
|
|
|
'invitations' => $invitations,
|
|
|
|
]);
|
|
|
|
}
|
2023-06-15 07:15:41 +00:00
|
|
|
public function acceptInvitation()
|
2023-06-12 10:00:01 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$invitation = TeamInvitation::whereUuid(request()->route('uuid'))->firstOrFail();
|
|
|
|
$user = User::whereEmail($invitation->email)->firstOrFail();
|
|
|
|
if (is_null(auth()->user())) {
|
|
|
|
return redirect()->route('login');
|
|
|
|
}
|
|
|
|
if (auth()->user()->id !== $user->id) {
|
|
|
|
abort(401);
|
|
|
|
}
|
|
|
|
|
2023-06-15 07:15:41 +00:00
|
|
|
$createdAt = $invitation->created_at;
|
|
|
|
$diff = $createdAt->diffInMinutes(now());
|
2023-06-12 10:00:01 +00:00
|
|
|
if ($diff <= config('constants.invitation.link.expiration')) {
|
|
|
|
$user->teams()->attach($invitation->team->id, ['role' => $invitation->role]);
|
|
|
|
$invitation->delete();
|
|
|
|
return redirect()->route('team.show');
|
|
|
|
} else {
|
|
|
|
$invitation->delete();
|
|
|
|
abort(401);
|
|
|
|
}
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
throw $th;
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 07:15:41 +00:00
|
|
|
public function revokeInvitation()
|
2023-06-12 10:00:01 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$invitation = TeamInvitation::whereUuid(request()->route('uuid'))->firstOrFail();
|
|
|
|
$user = User::whereEmail($invitation->email)->firstOrFail();
|
|
|
|
if (is_null(auth()->user())) {
|
|
|
|
return redirect()->route('login');
|
|
|
|
}
|
|
|
|
if (auth()->user()->id !== $user->id) {
|
|
|
|
abort(401);
|
|
|
|
}
|
|
|
|
$invitation->delete();
|
|
|
|
return redirect()->route('team.show');
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
throw $th;
|
|
|
|
}
|
|
|
|
}
|
2023-03-17 14:33:48 +00:00
|
|
|
}
|