-
Notifications
You must be signed in to change notification settings - Fork 0
chore: Sync main with dev #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,20 @@ public static function workspaceModel(): string | |||||
| return config('workspaces.workspace_model', Workspace::class); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * The name a workspace is stored under in a polymorphic column. | ||||||
| * | ||||||
| * Not the class name. A model may answer with something else, which is how | ||||||
| * a morph map works and how a subclass keeps the name its table already | ||||||
| * holds, and a comparison against the class name misses both. | ||||||
| */ | ||||||
| public static function workspaceMorphClass(): string | ||||||
| { | ||||||
| $model = static::workspaceModel(); | ||||||
|
|
||||||
| return (new $model)->getMorphClass(); | ||||||
| } | ||||||
|
|
||||||
| public function ownedWorkspaces(): MorphMany | ||||||
| { | ||||||
| return $this->morphMany(static::workspaceModel(), 'owner'); | ||||||
|
|
@@ -31,8 +45,8 @@ public function workspaces() | |||||
| 'id', | ||||||
| 'id', | ||||||
| 'context_id' | ||||||
| )->where('role_assignments.assignable_type', static::class) | ||||||
| ->where('role_assignments.context_type', static::workspaceModel()); | ||||||
| )->where('role_assignments.assignable_type', $this->getMorphClass()) | ||||||
| ->where('role_assignments.context_type', static::workspaceMorphClass()); | ||||||
| } | ||||||
|
|
||||||
| public function pendingWorkspaceInvitations() | ||||||
|
|
@@ -90,15 +104,15 @@ public function joinWorkspace(Workspace $workspace, ?string $role = null): void | |||||
| $role = $role ?? Role::default()->value; | ||||||
|
|
||||||
| if (method_exists($this, 'assignRole')) { | ||||||
| $this->assignRole($role, static::workspaceModel(), $workspace->id); | ||||||
| $this->assignRole($role, static::workspaceMorphClass(), $workspace->id); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public function leaveWorkspace(Workspace $workspace): void | ||||||
| { | ||||||
| if (method_exists($this, 'removeRole')) { | ||||||
| foreach (Role::values() as $role) { | ||||||
| $this->removeRole($role, static::workspaceModel(), $workspace->id); | ||||||
| $this->removeRole($role, static::workspaceMorphClass(), $workspace->id); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same inconsistency as
Suggested change
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
joinWorkspace()receives the concrete$workspaceinstance, but writescontext_typeusing the morph class of the configured model (static::workspaceMorphClass()). Every read path (Workspace::members(),Workspace::roleAssignments(),WorkspaceController) resolvescontext_typefrom$workspace->getMorphClass(). When the configured class and the passed instance disagree (e.g. config still points at the baseWorkspacewhile a subclass instance overridesgetMorphClass()), the assignment is stored under one name and looked up under another, reproducing exactly the empty-list bug this PR fixes. Resolve the morph class from the instance being joined.