feat: add workspace ownership transfer #82

Open
Charon wants to merge 1 commit from feat/workspace-ownership-transfer into dev
Member

Summary

Adds a transferOwnership(User $newOwner, ?User $actingUser = null) method to the Workspace model that allows the current owner to transfer workspace ownership to another existing member.

Changes

  • Models/Workspace.php -- New transferOwnership() method that:
    • Verifies the new owner is an existing workspace member
    • Demotes the current owner to admin role
    • Promotes the new owner to owner role
    • Updates team assignments (owner/admin teams) when teams are in use
    • Wraps role changes in a DB transaction for atomicity
    • Dispatches WorkspaceOwnershipTransferred event on success
    • Throws WorkspaceOwnershipException for authorisation and validation failures
  • Events/WorkspaceOwnershipTransferred.php -- New event dispatched after successful transfer, carrying workspace, previous owner, and new owner
  • Exceptions/WorkspaceOwnershipException.php -- New exception with named constructors for specific failure scenarios (notAMember, alreadyOwner, noCurrentOwner, unauthorised)
  • tests/Feature/WorkspaceOwnershipTransferTest.php -- 9 test cases covering happy path, authorisation, validation, team assignment updates, and event dispatching

Fixes #35

## Summary Adds a `transferOwnership(User $newOwner, ?User $actingUser = null)` method to the Workspace model that allows the current owner to transfer workspace ownership to another existing member. ### Changes - **`Models/Workspace.php`** -- New `transferOwnership()` method that: - Verifies the new owner is an existing workspace member - Demotes the current owner to admin role - Promotes the new owner to owner role - Updates team assignments (owner/admin teams) when teams are in use - Wraps role changes in a DB transaction for atomicity - Dispatches `WorkspaceOwnershipTransferred` event on success - Throws `WorkspaceOwnershipException` for authorisation and validation failures - **`Events/WorkspaceOwnershipTransferred.php`** -- New event dispatched after successful transfer, carrying workspace, previous owner, and new owner - **`Exceptions/WorkspaceOwnershipException.php`** -- New exception with named constructors for specific failure scenarios (`notAMember`, `alreadyOwner`, `noCurrentOwner`, `unauthorised`) - **`tests/Feature/WorkspaceOwnershipTransferTest.php`** -- 9 test cases covering happy path, authorisation, validation, team assignment updates, and event dispatching Fixes #35
Charon added 1 commit 2026-03-24 13:56:44 +00:00
Add transferOwnership() method to the Workspace model that allows the
current owner to transfer ownership to another existing workspace member.

The method:
- Verifies the new owner is an existing member
- Demotes the current owner to admin role
- Promotes the new owner to owner role
- Updates team assignments when teams are in use
- Wraps the role changes in a DB transaction
- Dispatches WorkspaceOwnershipTransferred event
- Throws WorkspaceOwnershipException for auth/validation failures

New files:
- Events/WorkspaceOwnershipTransferred.php
- Exceptions/WorkspaceOwnershipException.php
- tests/Feature/WorkspaceOwnershipTransferTest.php

Fixes #35

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/workspace-ownership-transfer:feat/workspace-ownership-transfer
git checkout feat/workspace-ownership-transfer

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout dev
git merge --no-ff feat/workspace-ownership-transfer
git checkout feat/workspace-ownership-transfer
git rebase dev
git checkout dev
git merge --ff-only feat/workspace-ownership-transfer
git checkout feat/workspace-ownership-transfer
git rebase dev
git checkout dev
git merge --no-ff feat/workspace-ownership-transfer
git checkout dev
git merge --squash feat/workspace-ownership-transfer
git checkout dev
git merge --ff-only feat/workspace-ownership-transfer
git checkout dev
git merge feat/workspace-ownership-transfer
git push origin dev
Sign in to join this conversation.
No description provided.