switch to auth()->user from session

This commit is contained in:
Andras Bacsai
2023-08-11 17:31:53 +02:00
parent e60ec6c47e
commit 833e45155d
32 changed files with 90 additions and 77 deletions

View File

@@ -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 @@ class ApplicationController extends Controller
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 @@ class ApplicationController extends Controller
{
$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');
}

View File

@@ -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 @@ class DatabaseController extends Controller
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 @@ class DatabaseController extends Controller
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');
}

View File

@@ -41,7 +41,7 @@ class MagicController extends Controller
{
$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

View File

@@ -18,7 +18,7 @@ class ProjectController extends Controller
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 @@ class ProjectController extends Controller
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 @@ class ProjectController extends Controller
$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 @@ class ProjectController extends Controller
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');
}

View File

@@ -67,7 +67,7 @@ class StandaloneDocker extends Component
'name' => $this->name,
'network' => $this->network,
'server_id' => $this->server_id,
'team_id' => session('currentTeam')->id
'team_id' => auth()->user()->currentTeam()->id
]);
}
$this->createNetworkAndAttachToProxy();

View File

@@ -26,7 +26,7 @@ class Change extends Component
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.');

View File

@@ -32,7 +32,7 @@ class Create extends Component
'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');

View File

@@ -29,7 +29,7 @@ class Source extends Component
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;
});
}

View File

@@ -11,7 +11,7 @@ class EmptyProject extends Component
{
$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']);
}

View File

@@ -55,7 +55,7 @@ class GithubPrivateRepositoryDeployKey extends Component
}
$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()

View File

@@ -42,7 +42,7 @@ class Form extends Component
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);
}

View File

@@ -64,7 +64,7 @@ class ByIp extends Component
'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;

View File

@@ -40,7 +40,7 @@ class Create extends Component
'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) {

View File

@@ -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();

View File

@@ -19,7 +19,7 @@ class Form extends Component
public function mount()
{
$this->team = session('currentTeam');
$this->team = auth()->user()->currentTeam();
}
public function submit()

View File

@@ -35,9 +35,9 @@ class InviteLink extends Component
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 @@ class InviteLink extends Component
}
TeamInvitation::firstOrCreate([
'team_id' => session('currentTeam')->id,
'team_id' => auth()->user()->currentTeam()->id,
'uuid' => $uuid,
'email' => $this->email,
'role' => $this->role,

View File

@@ -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');
}
}