added roles and organizations
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-15 20:59:32 -07:00
parent 2ca3860557
commit 177f122c10
57 changed files with 6378 additions and 247 deletions
+31 -2
View File
@@ -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.
*/