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>
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Tenant\Events;
|
|
|
|
use Core\Tenant\Models\User;
|
|
use Core\Tenant\Models\Workspace;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
|
|
/**
|
|
* Event dispatched when workspace ownership is transferred to another member.
|
|
*
|
|
* ## Event Payload
|
|
*
|
|
* - `workspace`: The affected Workspace model
|
|
* - `previousOwner`: The User who was the previous owner (now demoted to admin)
|
|
* - `newOwner`: The User who is the new owner
|
|
*
|
|
* ## Usage
|
|
*
|
|
* ```php
|
|
* Event::listen(WorkspaceOwnershipTransferred::class, function ($event) {
|
|
* // Notify relevant parties, log audit trail, etc.
|
|
* });
|
|
* ```
|
|
*/
|
|
class WorkspaceOwnershipTransferred
|
|
{
|
|
use Dispatchable;
|
|
|
|
/**
|
|
* Create a new event instance.
|
|
*
|
|
* @param Workspace $workspace The workspace whose ownership was transferred
|
|
* @param User $previousOwner The user who was the previous owner
|
|
* @param User $newOwner The user who is now the owner
|
|
*/
|
|
public function __construct(
|
|
public readonly Workspace $workspace,
|
|
public readonly User $previousOwner,
|
|
public readonly User $newOwner,
|
|
) {}
|
|
}
|