Skip to content

fix: Honour a morph class in role lookups - #23

Merged
nfebe merged 2 commits into
devfrom
fix/morph-class-for-role-context
Sep 20, 2026
Merged

nfebe merged 2 commits into
devfrom
fix/morph-class-for-role-context

Conversation

@nfebe

@nfebe nfebe commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Role lookups compared a polymorphic column against the configured class name, so a host pointing the package at a subclass has to store that subclass name in every row. A host with rows already written under the base name, or one registering a morph map, matches nothing: no workspaces, no members.

Nine comparisons now ask the model through getMorphClass. It answers with the class name unless the host says otherwise, so existing behaviour is unchanged and an override or a morph map is honoured as well.

The three places that need a class to instantiate, the route model binding and the two relation definitions, still use the configured class.

Role lookups compared a polymorphic column against the configured class name,
so a host that points the package at a subclass has to store that subclass
name in every row. A host with rows already written under the base name, or
one that registers a morph map, matches nothing and sees no workspaces and no
members.

The comparisons now ask the model through getMorphClass, which answers with the
class name unless the host says otherwise, so what is stored today keeps
working and an override or a morph map is honoured as well.
@sourceant

sourceant Bot commented Sep 20, 2026

Copy link
Copy Markdown

Code Review Summary

✨ Role lookups stop comparing a polymorphic context_type/assignable_type column against a configured class name and instead ask the model through getMorphClass(), so an override or a registered morph map is honoured. Nine comparisons change: four in src/Http/Controllers/WorkspaceController.php (members, userCanAccess, userCanManage, userIsOwner, getUserRole), four in src/Models/Workspace.php (members, roleAssignments, owners, admins) plus a new private userMorphClass() helper, and three in src/Traits/HasWorkspaces.php (workspaces, joinWorkspace, leaveWorkspace) with a new static workspaceMorphClass(). Since getMorphClass() returns the class name unless the host says otherwise, existing behaviour is unchanged, and the three places that need a class to instantiate (route model binding and the two relation definitions) still use the configured class. composer.json bumps the version from 1.1.1 to 1.2.0. tests/Feature/SubclassedWorkspaceTest.php gains a RenamedWorkspace subclass that answers with the base class name already stored in its rows, a case that resolves members when the user model sits behind a morph map, and a tearDown that clears the global morph map so later tests are not affected.

@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
Comment thread src/Http/Controllers/WorkspaceController.php Outdated
Comment thread src/Http/Controllers/WorkspaceController.php Outdated
Comment thread src/Http/Controllers/WorkspaceController.php Outdated
Comment thread src/Http/Controllers/WorkspaceController.php Outdated
Comment thread src/Http/Controllers/WorkspaceController.php Outdated
A role assignment is written through the user's own morph relation, so the
user side of the member lookup holds whatever that answers. Comparing it
against the configured class instead returned no members for a host that maps
its user model, while the same host's inverse lookup worked.

Both sides of the lookup now ask the model, and the controller uses the
workspace it already holds rather than resolving the name a second time.

@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. No specific code suggestions were generated. See the overview comment for a summary.

@nfebe
nfebe merged commit 367df41 into dev Sep 20, 2026
2 checks passed
@nfebe
nfebe deleted the fix/morph-class-for-role-context branch September 20, 2026 10:17
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