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

@@ -41,7 +41,7 @@ class EnvironmentVariable extends Model
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);

View File

@@ -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

View File

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

View File

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

View File

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

View File

@@ -34,7 +34,7 @@ class Server extends BaseModel
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()

View File

@@ -79,7 +79,7 @@ class User extends Authenticatable implements SendsEmail
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 @@ class User extends Authenticatable implements SendsEmail
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 @@ class User extends Authenticatable implements SendsEmail
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;
}