+31
-2
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\OrganizationRole;
|
||||
use App\WorkspaceType;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
@@ -71,6 +72,16 @@ class User extends Authenticatable implements PasskeyUser
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsToMany<Folder, $this>
|
||||
*/
|
||||
public function sharedFolders(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Folder::class)
|
||||
->withPivot('role', 'invited_by')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a personal organization owned by this user and make it current.
|
||||
*/
|
||||
@@ -78,6 +89,7 @@ class User extends Authenticatable implements PasskeyUser
|
||||
{
|
||||
$organization = Organization::create([
|
||||
'name' => $this->name."'s Workspace",
|
||||
'type' => WorkspaceType::Personal,
|
||||
'personal_workspace' => true,
|
||||
]);
|
||||
|
||||
@@ -122,13 +134,30 @@ class User extends Authenticatable implements PasskeyUser
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user is an administrator.
|
||||
* Determine whether the user is a site-wide administrator. This is
|
||||
* unrelated to any workspace role: site admins may reach the admin area,
|
||||
* whereas a workspace owner or admin may not.
|
||||
*/
|
||||
public function isAdmin(): bool
|
||||
public function isSiteAdmin(): bool
|
||||
{
|
||||
return (bool) $this->is_admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user is an owner or admin of the given workspace.
|
||||
* This grants rights inside that workspace only, never site-wide access.
|
||||
*/
|
||||
public function isOrganizationAdmin(Organization $organization): bool
|
||||
{
|
||||
return $organization->users()
|
||||
->where('users.id', $this->id)
|
||||
->wherePivotIn('role', [
|
||||
OrganizationRole::Owner->value,
|
||||
OrganizationRole::Admin->value,
|
||||
])
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum length allowed for todo notes.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user