switch to auth()->user from session
This commit is contained in:
parent
e60ec6c47e
commit
833e45155d
@ -12,7 +12,7 @@ class ApplicationController extends Controller
|
||||
|
||||
public function configuration()
|
||||
{
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
@ -29,7 +29,7 @@ public function configuration()
|
||||
|
||||
public function deployments()
|
||||
{
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
@ -49,7 +49,7 @@ public function deployment()
|
||||
{
|
||||
$deploymentUuid = request()->route('deployment_uuid');
|
||||
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class DatabaseController extends Controller
|
||||
|
||||
public function configuration()
|
||||
{
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
@ -29,7 +29,7 @@ public function configuration()
|
||||
public function executions()
|
||||
{
|
||||
$backup_uuid = request()->route('backup_uuid');
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
@ -56,7 +56,7 @@ public function executions()
|
||||
|
||||
public function backups()
|
||||
{
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public function newProject()
|
||||
{
|
||||
$project = Project::firstOrCreate(
|
||||
['name' => request()->query('name') ?? generate_random_name()],
|
||||
['team_id' => session('currentTeam')->id]
|
||||
['team_id' => auth()->user()->currentTeam()->id]
|
||||
);
|
||||
return response()->json([
|
||||
'project_uuid' => $project->uuid
|
||||
|
@ -18,7 +18,7 @@ public function all()
|
||||
public function edit()
|
||||
{
|
||||
$projectUuid = request()->route('project_uuid');
|
||||
$teamId = session('currentTeam')->id;
|
||||
$teamId = auth()->user()->currentTeam()->id;
|
||||
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
@ -29,7 +29,7 @@ public function edit()
|
||||
public function show()
|
||||
{
|
||||
$projectUuid = request()->route('project_uuid');
|
||||
$teamId = session('currentTeam')->id;
|
||||
$teamId = auth()->user()->currentTeam()->id;
|
||||
|
||||
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
|
||||
if (!$project) {
|
||||
@ -44,7 +44,7 @@ public function new()
|
||||
$type = request()->query('type');
|
||||
$destination_uuid = request()->query('destination');
|
||||
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
@ -67,7 +67,7 @@ public function new()
|
||||
|
||||
public function resources()
|
||||
{
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
$project = auth()->user()->currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public function submit()
|
||||
'name' => $this->name,
|
||||
'network' => $this->network,
|
||||
'server_id' => $this->server_id,
|
||||
'team_id' => session('currentTeam')->id
|
||||
'team_id' => auth()->user()->currentTeam()->id
|
||||
]);
|
||||
}
|
||||
$this->createNetworkAndAttachToProxy();
|
||||
|
@ -26,7 +26,7 @@ public function delete()
|
||||
try {
|
||||
if ($this->private_key->isEmpty()) {
|
||||
$this->private_key->delete();
|
||||
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
||||
auth()->user()->currentTeam()->privateKeys = PrivateKey::where('team_id', auth()->user()->currentTeam()->id)->get();
|
||||
return redirect()->route('private-key.all');
|
||||
}
|
||||
$this->emit('error', 'This private key is in use and cannot be deleted. Please delete all servers, applications, and GitHub/GitLab apps that use this private key before deleting it.');
|
||||
|
@ -32,7 +32,7 @@ public function createPrivateKey()
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'private_key' => $this->value,
|
||||
'team_id' => session('currentTeam')->id
|
||||
'team_id' => auth()->user()->currentTeam()->id
|
||||
]);
|
||||
if ($this->from === 'server') {
|
||||
return redirect()->route('server.create');
|
||||
|
@ -29,7 +29,7 @@ public function mount()
|
||||
|
||||
private function get_private_keys()
|
||||
{
|
||||
$this->private_keys = PrivateKey::whereTeamId(session('currentTeam')->id)->get()->reject(function ($key) {
|
||||
$this->private_keys = PrivateKey::whereTeamId(auth()->user()->currentTeam()->id)->get()->reject(function ($key) {
|
||||
return $key->id == $this->application->private_key_id;
|
||||
});
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public function createEmptyProject()
|
||||
{
|
||||
$project = Project::create([
|
||||
'name' => generate_random_name(),
|
||||
'team_id' => session('currentTeam')->id,
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
]);
|
||||
return redirect()->route('project.show', ['project_uuid' => $project->uuid, 'environment_name' => 'production']);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public function mount()
|
||||
}
|
||||
$this->parameters = get_route_parameters();
|
||||
$this->query = request()->query();
|
||||
$this->private_keys = PrivateKey::where('team_id', session('currentTeam')->id)->where('id', '!=', 0)->get();
|
||||
$this->private_keys = PrivateKey::where('team_id', auth()->user()->currentTeam()->id)->where('id', '!=', 0)->get();
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
|
@ -42,7 +42,7 @@ public function mount()
|
||||
|
||||
public function installDocker()
|
||||
{
|
||||
$activity = resolve(InstallDocker::class)($this->server, session('currentTeam'));
|
||||
$activity = resolve(InstallDocker::class)($this->server, auth()->user()->currentTeam());
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ public function submit()
|
||||
'ip' => $this->ip,
|
||||
'user' => $this->user,
|
||||
'port' => $this->port,
|
||||
'team_id' => session('currentTeam')->id,
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'private_key_id' => $this->private_key_id,
|
||||
]);
|
||||
$server->settings->is_part_of_swarm = $this->is_part_of_swarm;
|
||||
|
@ -40,7 +40,7 @@ public function createGitHubApp()
|
||||
'custom_user' => $this->custom_user,
|
||||
'custom_port' => $this->custom_port,
|
||||
'is_system_wide' => $this->is_system_wide,
|
||||
'team_id' => session('currentTeam')->id,
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
]);
|
||||
redirect()->route('source.github.show', ['github_app_uuid' => $github_app->uuid]);
|
||||
} catch (\Exception $e) {
|
||||
|
@ -9,7 +9,7 @@ class Delete extends Component
|
||||
{
|
||||
public function delete()
|
||||
{
|
||||
$currentTeam = session('currentTeam');
|
||||
$currentTeam = auth()->user()->currentTeam();
|
||||
$currentTeam->delete();
|
||||
|
||||
$team = auth()->user()->teams()->first();
|
||||
|
@ -19,7 +19,7 @@ class Form extends Component
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->team = session('currentTeam');
|
||||
$this->team = auth()->user()->currentTeam();
|
||||
}
|
||||
|
||||
public function submit()
|
||||
|
@ -35,9 +35,9 @@ private function generate_invite_link(bool $isEmail = false)
|
||||
return general_error_handler(that: $this, customErrorMessage: "$this->email must be registered first (or activate transactional emails to invite via email).");
|
||||
}
|
||||
|
||||
$member_emails = session('currentTeam')->members()->get()->pluck('email');
|
||||
$member_emails = auth()->user()->currentTeam()->members()->get()->pluck('email');
|
||||
if ($member_emails->contains($this->email)) {
|
||||
return general_error_handler(that: $this, customErrorMessage: "$this->email is already a member of " . session('currentTeam')->name . ".");
|
||||
return general_error_handler(that: $this, customErrorMessage: "$this->email is already a member of " . auth()->user()->currentTeam()->name . ".");
|
||||
}
|
||||
|
||||
$invitation = TeamInvitation::whereEmail($this->email);
|
||||
@ -53,7 +53,7 @@ private function generate_invite_link(bool $isEmail = false)
|
||||
}
|
||||
|
||||
TeamInvitation::firstOrCreate([
|
||||
'team_id' => session('currentTeam')->id,
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'uuid' => $uuid,
|
||||
'email' => $this->email,
|
||||
'role' => $this->role,
|
||||
|
@ -11,19 +11,19 @@ class Member extends Component
|
||||
|
||||
public function makeAdmin()
|
||||
{
|
||||
$this->member->teams()->updateExistingPivot(session('currentTeam')->id, ['role' => 'admin']);
|
||||
$this->member->teams()->updateExistingPivot(auth()->user()->currentTeam()->id, ['role' => 'admin']);
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
|
||||
public function makeReadonly()
|
||||
{
|
||||
$this->member->teams()->updateExistingPivot(session('currentTeam')->id, ['role' => 'member']);
|
||||
$this->member->teams()->updateExistingPivot(auth()->user()->currentTeam()->id, ['role' => 'member']);
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->member->teams()->detach(session('currentTeam'));
|
||||
$this->member->teams()->detach(auth()->user()->currentTeam());
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ protected function value(): Attribute
|
||||
|
||||
private function get_environment_variables(string $environment_variable): string|null
|
||||
{
|
||||
// $team_id = session('currentTeam')->id;
|
||||
// $team_id = auth()->user()->currentTeam()->id;
|
||||
if (str_contains(trim($environment_variable), '{{') && str_contains(trim($environment_variable), '}}')) {
|
||||
$environment_variable = preg_replace('/\s+/', '', $environment_variable);
|
||||
$environment_variable = str_replace('{{', '', $environment_variable);
|
||||
|
@ -19,12 +19,12 @@ class GithubApp extends BaseModel
|
||||
|
||||
static public function public()
|
||||
{
|
||||
return GithubApp::whereTeamId(session('currentTeam')->id)->whereisPublic(true)->whereNotNull('app_id')->get();
|
||||
return GithubApp::whereTeamId(auth()->user()->currentTeam()->id)->whereisPublic(true)->whereNotNull('app_id')->get();
|
||||
}
|
||||
|
||||
static public function private()
|
||||
{
|
||||
return GithubApp::whereTeamId(session('currentTeam')->id)->whereisPublic(false)->whereNotNull('app_id')->get();
|
||||
return GithubApp::whereTeamId(auth()->user()->currentTeam()->id)->whereisPublic(false)->whereNotNull('app_id')->get();
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
|
@ -16,7 +16,7 @@ class PrivateKey extends BaseModel
|
||||
static public function ownedByCurrentTeam(array $select = ['*'])
|
||||
{
|
||||
$selectArray = collect($select)->concat(['id']);
|
||||
return PrivateKey::whereTeamId(session('currentTeam')->id)->select($selectArray->all());
|
||||
return PrivateKey::whereTeamId(auth()->user()->currentTeam()->id)->select($selectArray->all());
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
|
@ -13,7 +13,7 @@ class Project extends BaseModel
|
||||
|
||||
static public function ownedByCurrentTeam()
|
||||
{
|
||||
return Project::whereTeamId(session('currentTeam')->id)->orderBy('name');
|
||||
return Project::whereTeamId(auth()->user()->currentTeam()->id)->orderBy('name');
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
|
@ -17,7 +17,7 @@ class S3Storage extends BaseModel
|
||||
static public function ownedByCurrentTeam(array $select = ['*'])
|
||||
{
|
||||
$selectArray = collect($select)->concat(['id']);
|
||||
return S3Storage::whereTeamId(session('currentTeam')->id)->select($selectArray->all())->orderBy('name');
|
||||
return S3Storage::whereTeamId(auth()->user()->currentTeam()->id)->select($selectArray->all())->orderBy('name');
|
||||
}
|
||||
|
||||
public function awsUrl()
|
||||
|
@ -34,7 +34,7 @@ static public function isReachable()
|
||||
static public function ownedByCurrentTeam(array $select = ['*'])
|
||||
{
|
||||
$selectArray = collect($select)->concat(['id']);
|
||||
return Server::whereTeamId(session('currentTeam')->id)->with('settings')->select($selectArray->all())->orderBy('name');
|
||||
return Server::whereTeamId(auth()->user()->currentTeam()->id)->with('settings')->select($selectArray->all())->orderBy('name');
|
||||
}
|
||||
|
||||
static public function isUsable()
|
||||
|
@ -79,7 +79,7 @@ public function isAdminFromSession()
|
||||
if ($is_part_of_root_team && $is_admin_of_root_team) {
|
||||
return true;
|
||||
}
|
||||
$role = $teams->where('id', session('currentTeam')->id)->first()->pivot->role;
|
||||
$role = $teams->where('id', auth()->user()->id)->first()->pivot->role;
|
||||
return $role === 'admin' || $role === 'owner';
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ public function currentTeam()
|
||||
|
||||
public function otherTeams()
|
||||
{
|
||||
$team_id = session('currentTeam')->id;
|
||||
$team_id = auth()->user()->currentTeam()->id;
|
||||
return auth()->user()->teams->filter(function ($team) use ($team_id) {
|
||||
return $team->id != $team_id;
|
||||
});
|
||||
@ -117,12 +117,12 @@ public function role()
|
||||
if ($this->teams()->where('team_id', 0)->first()) {
|
||||
return 'admin';
|
||||
}
|
||||
return $this->teams()->where('team_id', session('currentTeam')->id)->first()->pivot->role;
|
||||
return $this->teams()->where('team_id', auth()->user()->currentTeam()->id)->first()->pivot->role;
|
||||
}
|
||||
|
||||
public function resources()
|
||||
{
|
||||
$team_id = session('currentTeam')->id;
|
||||
$team_id = auth()->user()->currentTeam()->id;
|
||||
$data = Application::where('team_id', $team_id)->get();
|
||||
return $data;
|
||||
}
|
||||
|
@ -158,8 +158,8 @@ function refreshPrivateKey(PrivateKey $private_key)
|
||||
foreach ($private_key->servers as $server) {
|
||||
// Delete the old ssh mux file to force a new one to be created
|
||||
Storage::disk('ssh-mux')->delete($server->muxFilename());
|
||||
if (session('currentTeam')->id) {
|
||||
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
||||
if (auth()->user()->currentTeam()->id) {
|
||||
auth()->user()->currentTeam()->privateKeys = PrivateKey::where('team_id', auth()->user()->currentTeam()->id)->get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
auth()->user()->currentTeam()->subscription?->lemon_status !== 'cancelled')
|
||||
<div>Please cancel your subscription before delete this team (Manage My Subscription button).</div>
|
||||
@else
|
||||
@if (session('currentTeam')->isEmpty())
|
||||
@if (auth()->user()->currentTeam()->isEmpty())
|
||||
<div class="pb-4">This will delete your team. Beware! There is no coming back!</div>
|
||||
<x-forms.button isError isModal modalId="deleteTeam">
|
||||
Delete
|
||||
@ -25,25 +25,25 @@
|
||||
<div class="pb-4">You need to delete the following resources to be able to delete the team:</div>
|
||||
<h4 class="pb-4">Projects:</h4>
|
||||
<ul class="pl-8 list-disc">
|
||||
@foreach (session('currentTeam')->projects as $resource)
|
||||
@foreach (auth()->user()->currentTeam()->projects as $resource)
|
||||
<li>{{ $resource->name }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
<h4 class="py-4">Servers:</h4>
|
||||
<ul class="pl-8 list-disc">
|
||||
@foreach (session('currentTeam')->servers as $resource)
|
||||
@foreach (auth()->user()->currentTeam()->servers as $resource)
|
||||
<li>{{ $resource->name }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
<h4 class="py-4">Private Keys:</h4>
|
||||
<ul class="pl-8 list-disc">
|
||||
@foreach (session('currentTeam')->privateKeys as $resource)
|
||||
@foreach (auth()->user()->currentTeam()->privateKeys as $resource)
|
||||
<li>{{ $resource->name }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
<h4 class="py-4">Sources:</h4>
|
||||
<ul class="pl-8 list-disc">
|
||||
@foreach (session('currentTeam')->sources() as $resource)
|
||||
@foreach (auth()->user()->currentTeam()->sources() as $resource)
|
||||
<li>{{ $resource->name }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
@ -1,5 +1,7 @@
|
||||
<x-layout>
|
||||
<x-team.navbar :team="session('currentTeam')"/>
|
||||
<x-team.navbar :team="auth()
|
||||
->user()
|
||||
->currentTeam()" />
|
||||
<h2>Members</h2>
|
||||
<div class="pt-4 overflow-hidden">
|
||||
<table>
|
||||
|
@ -1,5 +1,7 @@
|
||||
<x-layout>
|
||||
<x-team.navbar :team="session('currentTeam')"/>
|
||||
<x-team.navbar :team="auth()
|
||||
->user()
|
||||
->currentTeam()" />
|
||||
<h2 class="pb-4">Notifications</h2>
|
||||
<div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'email' }" class="flex h-full">
|
||||
<div class="flex flex-col gap-4 min-w-fit">
|
||||
@ -10,10 +12,14 @@
|
||||
</div>
|
||||
<div class="w-full pl-8">
|
||||
<div x-cloak x-show="activeTab === 'email'" class="h-full">
|
||||
<livewire:notifications.email-settings :model="session('currentTeam')"/>
|
||||
<livewire:notifications.email-settings :model="auth()
|
||||
->user()
|
||||
->currentTeam()" />
|
||||
</div>
|
||||
<div x-cloak x-show="activeTab === 'discord'">
|
||||
<livewire:notifications.discord-settings :model="session('currentTeam')"/>
|
||||
<livewire:notifications.discord-settings :model="auth()
|
||||
->user()
|
||||
->currentTeam()" />
|
||||
</div>
|
||||
</div>
|
||||
</x-layout>
|
||||
|
@ -1,5 +1,7 @@
|
||||
<x-layout>
|
||||
<x-team.navbar :team="session('currentTeam')"/>
|
||||
<x-team.navbar :team="auth()
|
||||
->user()
|
||||
->currentTeam()" />
|
||||
<livewire:team.form />
|
||||
@if (is_cloud())
|
||||
<div class="pb-8">
|
||||
|
@ -1,5 +1,7 @@
|
||||
<x-layout>
|
||||
<x-team.navbar :team="session('currentTeam')"/>
|
||||
<x-team.navbar :team="auth()
|
||||
->user()
|
||||
->currentTeam()" />
|
||||
<div class="flex items-start gap-2">
|
||||
<h2 class="pb-4">S3 Storages</h2>
|
||||
<x-forms.button class="btn">
|
||||
@ -8,8 +10,7 @@
|
||||
</div>
|
||||
<div class="grid gap-2 lg:grid-cols-2">
|
||||
@forelse ($s3 as $storage)
|
||||
<div x-data
|
||||
x-on:click="goto('{{ $storage->uuid }}')" @class(['gap-2 border cursor-pointer box group border-transparent'])>
|
||||
<div x-data x-on:click="goto('{{ $storage->uuid }}')" @class(['gap-2 border cursor-pointer box group border-transparent'])>
|
||||
<div class="flex flex-col mx-6">
|
||||
<div class=" group-hover:text-white">
|
||||
{{ $storage->name }}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<x-layout>
|
||||
<x-team.navbar :team="session('currentTeam')"/>
|
||||
<x-team.navbar :team="auth()
|
||||
->user()
|
||||
->currentTeam()" />
|
||||
<livewire:team.storage.form :storage="$storage" />
|
||||
</x-layout>
|
||||
|
@ -122,7 +122,7 @@
|
||||
Route::middleware(['auth'])->group(function () {
|
||||
Route::get('/source/new', fn() => view('source.new'))->name('source.new');
|
||||
Route::get('/sources', function () {
|
||||
$sources = session('currentTeam')->sources();
|
||||
$sources = auth()->user()->currentTeam()->sources();
|
||||
return view('source.all', [
|
||||
'sources' => $sources,
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user