Implement EnsureUserHasWorkspace Trait and Integrate into Controllers… (#741)
* Implement EnsureUserHasWorkspace Trait and Integrate into Controllers and Jobs - Introduced the EnsureUserHasWorkspace trait to ensure users have at least one workspace when they are detached from a workspace. - Integrated the trait into WorkspaceUserController to enforce workspace checks during user detachment. - Updated RemoveWorkspaceGuests job to utilize the new trait for ensuring users have a workspace after detachment. - Modified UserWorkspace model to call the ensureUserHasWorkspace method upon deletion, maintaining workspace integrity. These changes enhance user management by ensuring that users always have a workspace, improving overall application stability. * Add test --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\EnsureUserHasWorkspace;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserWorkspace extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use EnsureUserHasWorkspace;
|
||||
|
||||
protected $table = 'user_workspace';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -25,4 +28,13 @@ class UserWorkspace extends Model
|
||||
{
|
||||
return $this->belongsTo(Workspace::class);
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::deleted(function (UserWorkspace $userWorkspace) {
|
||||
$userWorkspace->ensureUserHasWorkspace($userWorkspace->user);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user