mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 22:14:45 +02:00
Change allowed_ips
to non-nullable (#373)
* change `allowed_ips` to non nullable * fix default value * show "allowed_ips" input
This commit is contained in:
parent
12518bc5d6
commit
0c0b468525
@ -71,9 +71,7 @@ class CreateApiKey extends CreateRecord
|
||||
->placeholder('Example: 127.0.0.1 or 192.168.1.1')
|
||||
->label('Whitelisted IPv4 Addresses')
|
||||
->helperText('Press enter to add a new IP address or leave blank to allow any IP address')
|
||||
->columnSpanFull()
|
||||
->hidden()
|
||||
->default(null),
|
||||
->columnSpanFull(),
|
||||
|
||||
Forms\Components\Textarea::make('memo')
|
||||
->required()
|
||||
|
@ -15,7 +15,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
* @property int $key_type
|
||||
* @property string $identifier
|
||||
* @property string $token
|
||||
* @property array|null $allowed_ips
|
||||
* @property array $allowed_ips
|
||||
* @property string|null $memo
|
||||
* @property \Illuminate\Support\Carbon|null $last_used_at
|
||||
* @property \Illuminate\Support\Carbon|null $expires_at
|
||||
@ -113,6 +113,13 @@ class ApiKey extends Model
|
||||
'r_' . AdminAcl::RESOURCE_MOUNTS,
|
||||
];
|
||||
|
||||
/**
|
||||
* Default attributes when creating a new model.
|
||||
*/
|
||||
protected $attributes = [
|
||||
'allowed_ips' => '[]',
|
||||
];
|
||||
|
||||
/**
|
||||
* Fields that should not be included when calling toArray() or toJson()
|
||||
* on this model.
|
||||
@ -128,7 +135,7 @@ class ApiKey extends Model
|
||||
'identifier' => 'required|string|size:16|unique:api_keys,identifier',
|
||||
'token' => 'required|string',
|
||||
'memo' => 'required|nullable|string|max:500',
|
||||
'allowed_ips' => 'nullable|array',
|
||||
'allowed_ips' => 'array',
|
||||
'allowed_ips.*' => 'string',
|
||||
'last_used_at' => 'nullable|date',
|
||||
'expires_at' => 'nullable|date',
|
||||
|
@ -27,7 +27,7 @@ class ApiKeyFactory extends Factory
|
||||
'key_type' => ApiKey::TYPE_APPLICATION,
|
||||
'identifier' => ApiKey::generateTokenIdentifier(ApiKey::TYPE_APPLICATION),
|
||||
'token' => $token ?: $token = Str::random(ApiKey::KEY_LENGTH),
|
||||
'allowed_ips' => null,
|
||||
'allowed_ips' => [],
|
||||
'memo' => 'Test Function Key',
|
||||
'created_at' => Carbon::now(),
|
||||
'updated_at' => Carbon::now(),
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('api_keys')->whereNull('allowed_ips')->update([
|
||||
'allowed_ips' => '[]',
|
||||
]);
|
||||
|
||||
Schema::table('api_keys', function (Blueprint $table) {
|
||||
$table->text('allowed_ips')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('api_keys', function (Blueprint $table) {
|
||||
$table->text('allowed_ips')->nullable()->change();
|
||||
});
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user