Skip to content

fix: Honour a workspace subclass when listing members - #21

Merged
nfebe merged 1 commit into
devfrom
fix/member-lists-honour-subclass
Jun 14, 2026
Merged

nfebe merged 1 commit into
devfrom
fix/member-lists-honour-subclass

Conversation

@nfebe

@nfebe nfebe commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Member, owner, and admin lists came back empty for any app that uses its own Workspace subclass: the lookups compared against the base package class while the stored role assignments reference the configured model. They now resolve against the actual model, so members appear as expected.

Member, owner, and admin lists came back empty for any app that uses its
own Workspace subclass: the lookups compared against the base package
class while the stored role assignments reference the configured model.
They now resolve against the actual model, so members appear as expected.
@sourceant

sourceant Bot commented Jun 14, 2026

Copy link
Copy Markdown

Code Review Summary

This PR fixes a bug where member lists (owners, admins, members) appeared empty when the Workspace model was subclassed. The issue stemmed from using self::class in Eloquent queries, which restricted results to the base class name, ignoring records associated with the subclass name.

🚀 Key Improvements

  • Updated src/Models/Workspace.php to use Late Static Binding (static::class) in all relationship and query filters.
  • Added a comprehensive feature test tests/Feature/SubclassedWorkspaceTest.php to verify that subclassed workspaces correctly resolve members.

💡 Minor Suggestions

  • Ensure the test uses the specific role slugs defined in the model (e.g., workspace-owner) to ensure test consistency with implementation.

@sourceant sourceant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review complete. See the overview comment for a summary.

Comment thread src/Models/Workspace.php
'id',
'id',
'assignable_id'
)->where('role_assignments.context_type', self::class)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using static::class instead of self::class enables Late Static Binding. This ensures that if a developer extends the Workspace model, the query will correctly filter by the child class name stored in the database.

Suggested change
)->where('role_assignments.context_type', self::class)
+ )->where('role_assignments.context_type', static::class)

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.

Hardcoding the role slug as 'owner' might be fragile if the system relies on specific slugs like 'workspace-owner' (as seen in the model methods). Consider using the slug that matches the logic being tested.

Suggested change
'role_id' => Role::where('slug', 'owner')->first()->id,
'role_id' => Role::where('slug', 'workspace-owner')->first()->id,

@nfebe
nfebe merged commit 3339425 into dev Jun 14, 2026
2 checks passed
@nfebe
nfebe deleted the fix/member-lists-honour-subclass branch June 14, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant