Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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();
Expand Down
50 changes: 50 additions & 0 deletions tests/Feature/SubclassedWorkspaceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Tests\Feature;

use Illuminate\Support\Facades\Hash;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
use Whilesmart\Roles\Models\Role;
use Whilesmart\Roles\Models\RoleAssignment;
use Whilesmart\Workspaces\Models\Workspace;
use Workbench\App\Models\User;

class SubWorkspace extends Workspace
{
protected $table = 'workspaces';
}

class SubclassedWorkspaceTest extends TestCase
{
#[Test]
public function members_resolve_when_the_workspace_model_is_subclassed(): void
{
config(['workspaces.workspace_model' => 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on first() without checking for null can lead to errors if the database state is unexpected. While likely seeded in tests, using firstOrFail() or a explicit check is safer.

Suggested change
'role_id' => Role::where('slug', 'owner')->first()->id,
'role_id' => Role::where('slug', 'owner')->firstOrFail()->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());
}
}
Loading