diff --git a/Controllers/EntitlementApiController.php b/Controllers/EntitlementApiController.php index 8773eab..2b4fdbc 100644 --- a/Controllers/EntitlementApiController.php +++ b/Controllers/EntitlementApiController.php @@ -102,7 +102,7 @@ class EntitlementApiController extends Controller $workspace = Workspace::create([ 'name' => $user->name."'s Workspace", 'slug' => Str::slug($user->name).'-'.Str::random(6), - 'domain' => 'hub.host.uk.com', + 'domain' => 'hub.'.config('app.base_domain', 'host.uk.com'), 'type' => 'custom', ]); diff --git a/Controllers/WorkspaceController.php b/Controllers/WorkspaceController.php index bc63131..809b90d 100644 --- a/Controllers/WorkspaceController.php +++ b/Controllers/WorkspaceController.php @@ -139,7 +139,7 @@ class WorkspaceController extends Controller } // Set default domain - $validated['domain'] = 'hub.host.uk.com'; + $validated['domain'] = 'hub.'.config('app.base_domain', 'host.uk.com'); $validated['type'] = $validated['type'] ?? 'custom'; $workspace = Workspace::create($validated); @@ -261,7 +261,7 @@ class WorkspaceController extends Controller ->whereIn('workspace_id', function ($query) { $query->select('id') ->from('workspaces') - ->where('domain', 'hub.host.uk.com'); + ->where('domain', 'hub.'.config('app.base_domain', 'host.uk.com')); }) ->update(['is_default' => false]); diff --git a/Migrations/2026_03_24_000000_add_feature_code_foreign_keys.php b/Migrations/2026_03_24_000000_add_feature_code_foreign_keys.php new file mode 100644 index 0000000..9680b1b --- /dev/null +++ b/Migrations/2026_03_24_000000_add_feature_code_foreign_keys.php @@ -0,0 +1,57 @@ +foreign('feature_code', 'usage_alert_feature_code_fk') + ->references('code') + ->on('entitlement_features') + ->cascadeOnUpdate() + ->restrictOnDelete(); + }); + + Schema::table('entitlement_boosts', function (Blueprint $table) { + $table->foreign('feature_code', 'boosts_feature_code_fk') + ->references('code') + ->on('entitlement_features') + ->cascadeOnUpdate() + ->restrictOnDelete(); + }); + + Schema::table('entitlement_usage_records', function (Blueprint $table) { + $table->foreign('feature_code', 'usage_records_feature_code_fk') + ->references('code') + ->on('entitlement_features') + ->cascadeOnUpdate() + ->restrictOnDelete(); + }); + } + + public function down(): void + { + Schema::table('entitlement_usage_alert_history', function (Blueprint $table) { + $table->dropForeign('usage_alert_feature_code_fk'); + }); + + Schema::table('entitlement_boosts', function (Blueprint $table) { + $table->dropForeign('boosts_feature_code_fk'); + }); + + Schema::table('entitlement_usage_records', function (Blueprint $table) { + $table->dropForeign('usage_records_feature_code_fk'); + }); + } +}; diff --git a/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php b/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php new file mode 100644 index 0000000..bb5f6a5 --- /dev/null +++ b/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php @@ -0,0 +1,40 @@ +dropForeign(['workspace_id']); + + $table->foreign('workspace_id') + ->references('id') + ->on('workspaces') + ->cascadeOnDelete(); + }); + } + + public function down(): void + { + Schema::table('namespaces', function (Blueprint $table) { + $table->dropForeign(['workspace_id']); + + $table->foreign('workspace_id') + ->references('id') + ->on('workspaces') + ->nullOnDelete(); + }); + } +}; diff --git a/Migrations/2026_03_24_000000_fix_parent_feature_cascade_delete.php b/Migrations/2026_03_24_000000_fix_parent_feature_cascade_delete.php new file mode 100644 index 0000000..81698fa --- /dev/null +++ b/Migrations/2026_03_24_000000_fix_parent_feature_cascade_delete.php @@ -0,0 +1,47 @@ +dropForeign(['parent_feature_id']); + + $table->foreign('parent_feature_id') + ->references('id') + ->on('entitlement_features') + ->cascadeOnDelete(); + }); + } + + /** + * Revert to the original nullOnDelete behaviour. + */ + public function down(): void + { + Schema::table('entitlement_features', function (Blueprint $table) { + $table->dropForeign(['parent_feature_id']); + + $table->foreign('parent_feature_id') + ->references('id') + ->on('entitlement_features') + ->nullOnDelete(); + }); + } +}; diff --git a/Routes/web.php b/Routes/web.php index 6a41eb5..c9fdd3a 100644 --- a/Routes/web.php +++ b/Routes/web.php @@ -26,10 +26,12 @@ use Illuminate\Support\Facades\Route; Route::prefix('account')->name('account.')->group(function () { Route::get('/delete/{token}', ConfirmDeletion::class) - ->name('delete.confirm'); + ->name('delete.confirm') + ->where('token', '[a-zA-Z0-9]{64}'); Route::get('/delete/{token}/cancel', CancelDeletion::class) - ->name('delete.cancel'); + ->name('delete.cancel') + ->where('token', '[a-zA-Z0-9]{64}'); }); /* @@ -43,7 +45,8 @@ Route::prefix('account')->name('account.')->group(function () { */ Route::get('/workspace/invitation/{token}', WorkspaceInvitationController::class) - ->name('workspace.invitation.accept'); + ->name('workspace.invitation.accept') + ->where('token', '[a-zA-Z0-9]{64}'); /* |--------------------------------------------------------------------------