fix: Honour a workspace subclass when listing members - #21
Conversation
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.
Code Review SummaryThis PR fixes a bug where member lists (owners, admins, members) appeared empty when the 🚀 Key Improvements
💡 Minor Suggestions
|
| 'id', | ||
| 'id', | ||
| 'assignable_id' | ||
| )->where('role_assignments.context_type', self::class) |
There was a problem hiding this comment.
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.
| )->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, |
There was a problem hiding this comment.
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.
| 'role_id' => Role::where('slug', 'owner')->first()->id, | |
| 'role_id' => Role::where('slug', 'workspace-owner')->first()->id, |
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.