mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00
Delete subuser on owner change (#748)
* Delete subuser on owner change * Move logic to Model
This commit is contained in:
parent
6d42a15ec3
commit
09eac71f05
@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use App\Exceptions\Http\Server\ServerStateConflictException;
|
||||
use App\Services\Subusers\SubuserDeletionService;
|
||||
|
||||
/**
|
||||
* \App\Models\Server.
|
||||
@ -203,6 +204,17 @@ class Server extends Model
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(function (self $server) {
|
||||
$subuser = $server->subusers()->where('user_id', $server->owner_id)->first();
|
||||
if ($subuser) {
|
||||
// @phpstan-ignore-next-line
|
||||
app(SubuserDeletionService::class)->handle($subuser, $server);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format for server allocations when communicating with the Daemon.
|
||||
*/
|
||||
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('subusers')
|
||||
->whereIn('user_id', function ($query) {
|
||||
$query->select('id')
|
||||
->from('servers')
|
||||
->whereColumn('owner_id', 'subusers.server_id');
|
||||
})
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Not needed
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user