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-08-07 13:31:42 +00:00
|
|
|
use App\Models\S3Storage;
|
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-07-14 09:27:08 +00:00
|
|
|
public function subscription()
|
2023-06-22 12:48:47 +00:00
|
|
|
{
|
2023-07-14 10:09:56 +00:00
|
|
|
if (!isCloud()) {
|
|
|
|
abort(404);
|
|
|
|
}
|
2023-07-14 09:27:08 +00:00
|
|
|
return view('subscription', [
|
|
|
|
'settings' => InstanceSettings::get()
|
|
|
|
]);
|
2023-06-22 12:48:47 +00:00
|
|
|
}
|
2023-07-14 10:09:56 +00:00
|
|
|
public function license()
|
|
|
|
{
|
|
|
|
if (!isCloud()) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
return view('settings.license', [
|
|
|
|
'settings' => InstanceSettings::get()
|
|
|
|
]);
|
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
public function dashboard()
|
|
|
|
{
|
|
|
|
$projects = Project::ownedByCurrentTeam()->get();
|
|
|
|
$servers = Server::ownedByCurrentTeam()->get();
|
2023-08-07 13:31:42 +00:00
|
|
|
$s3s = S3Storage::ownedByCurrentTeam()->get();
|
2023-06-07 13:08:35 +00:00
|
|
|
$resources = 0;
|
|
|
|
foreach ($projects as $project) {
|
2023-08-07 16:46:40 +00:00
|
|
|
ray($project->postgresqls);
|
2023-06-07 13:08:35 +00:00
|
|
|
$resources += $project->applications->count();
|
2023-08-07 16:46:40 +00:00
|
|
|
$resources += $project->postgresqls->count();
|
2023-06-07 13:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return view('dashboard', [
|
|
|
|
'servers' => $servers->count(),
|
|
|
|
'projects' => $projects->count(),
|
|
|
|
'resources' => $resources,
|
2023-08-07 13:31:42 +00:00
|
|
|
's3s' => $s3s,
|
2023-06-07 13:08:35 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
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-08-07 13:31:42 +00:00
|
|
|
public function storages() {
|
|
|
|
$s3 = S3Storage::ownedByCurrentTeam()->get();
|
|
|
|
return view('team.storages.all', [
|
|
|
|
's3' => $s3,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
public function storages_show() {
|
|
|
|
$storage = S3Storage::ownedByCurrentTeam()->whereUuid(request()->storage_uuid)->firstOrFail();
|
|
|
|
return view('team.storages.show', [
|
|
|
|
'storage' => $storage,
|
|
|
|
]);
|
|
|
|
}
|
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-08-07 13:31:42 +00:00
|
|
|
}
|