diff --git a/CHANGELOG.md b/CHANGELOG.md index 77856c4..4ffddde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [1.1.1] - 2026-06-14 + +### Fixed +- Member, owner, and admin lists are now found when a host app uses its own `Workspace` subclass; the lookups now match the configured model instead of the base class + ## [1.1.0] - 2026-06-13 ### Added diff --git a/composer.json b/composer.json index faf65b2..20d6c3a 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Workspace management package for Laravel applications", "type": "library", "license": "MIT", - "version": "1.1.0", + "version": "1.1.1", "authors": [ { "name": "WhileSmart", diff --git a/src/Models/Workspace.php b/src/Models/Workspace.php index 7975489..80e866e 100644 --- a/src/Models/Workspace.php +++ b/src/Models/Workspace.php @@ -70,7 +70,7 @@ public function members() 'id', 'id', 'assignable_id' - )->where('role_assignments.context_type', self::class) + )->where('role_assignments.context_type', static::class) ->where('role_assignments.assignable_type', config('workspaces.user_model', 'App\\Models\\User')); } @@ -93,7 +93,7 @@ public function pendingInvitations(): HasMany public function roleAssignments() { return $this->hasMany('Whilesmart\\Roles\\Models\\RoleAssignment', 'context_id') - ->where('context_type', self::class); + ->where('context_type', static::class); } public function getOwnersAttribute() @@ -103,7 +103,7 @@ public function getOwnersAttribute() $query->whereHas('role', function ($q) { $q->where('slug', 'workspace-owner'); }) - ->where('context_type', self::class) + ->where('context_type', static::class) ->where('context_id', $this->id); }) ->get(); @@ -116,7 +116,7 @@ public function getAdminsAttribute() $query->whereHas('role', function ($q) { $q->whereIn('slug', ['workspace-owner', 'workspace-admin']); }) - ->where('context_type', self::class) + ->where('context_type', static::class) ->where('context_id', $this->id); }) ->get(); diff --git a/tests/Feature/SubclassedWorkspaceTest.php b/tests/Feature/SubclassedWorkspaceTest.php new file mode 100644 index 0000000..29c4761 --- /dev/null +++ b/tests/Feature/SubclassedWorkspaceTest.php @@ -0,0 +1,50 @@ + SubWorkspace::class]); + + $user = User::create([ + 'name' => 'Sub Owner', + 'email' => 'sub-'.uniqid().'@example.com', + 'password' => Hash::make('password'), + ]); + + $workspace = SubWorkspace::create([ + 'name' => 'Sub Workspace', + 'type' => 'team', + 'owner_type' => User::class, + 'owner_id' => $user->id, + ]); + + RoleAssignment::create([ + 'assignable_type' => User::class, + 'assignable_id' => $user->id, + 'role_id' => Role::where('slug', 'owner')->first()->id, + 'context_type' => SubWorkspace::class, + 'context_id' => $workspace->id, + ]); + + // Before the fix this returned 0, because the lookup filtered on the + // base Workspace class while the assignment stores the subclass. + $this->assertCount(1, $workspace->members()->get()); + } +}