feat: make user owner

fix: ownership check
This commit is contained in:
Andras Bacsai
2024-02-23 12:34:36 +01:00
parent ea0a9763bf
commit f931ebece8
6 changed files with 131 additions and 73 deletions

View File

@@ -67,7 +67,7 @@ class User extends Authenticatable implements SendsEmail
'team_id' => session('currentTeam')->id
]);
return new NewAccessToken($token, $token->getKey().'|'.$plainTextToken);
return new NewAccessToken($token, $token->getKey() . '|' . $plainTextToken);
}
public function teams()
{
@@ -103,9 +103,13 @@ class User extends Authenticatable implements SendsEmail
public function isAdmin()
{
return data_get($this->pivot, 'role') === 'admin' || data_get($this->pivot, 'role') === 'owner';
return $this->role() === 'admin' || $this->role() === 'owner';
}
public function isOwner()
{
return $this->role() === 'owner';
}
public function isAdminFromSession()
{
if (auth()->user()->id === 0) {
@@ -155,6 +159,6 @@ class User extends Authenticatable implements SendsEmail
public function role()
{
return session('currentTeam')->pivot->role;
return auth()->user()->teams->where('id', currentTeam()->id)->first()->pivot->role;
}
}