Add core logic to allow for limited databases and allocations
This commit is contained in:
		
							parent
							
								
									5f6c153537
								
							
						
					
					
						commit
						87b96bdfc8
					
				@ -13,7 +13,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
 | 
			
		||||
     */
 | 
			
		||||
    public function rules(): array
 | 
			
		||||
    {
 | 
			
		||||
        $rules = Server::getUpdateRulesForId($this->route()->parameter('server')->id);
 | 
			
		||||
        $rules = Server::getUpdateRulesForId($this->getModel(Server::class)->id);
 | 
			
		||||
 | 
			
		||||
        return [
 | 
			
		||||
            'allocation' => $rules['allocation_id'],
 | 
			
		||||
@ -26,6 +26,9 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
 | 
			
		||||
            'add_allocations.*' => 'integer',
 | 
			
		||||
            'remove_allocations' => 'bail|array',
 | 
			
		||||
            'remove_allocations.*' => 'integer',
 | 
			
		||||
            'feature_limits' => 'required|array',
 | 
			
		||||
            'feature_limits.databases' => $rules['database_limit'],
 | 
			
		||||
            'feature_limits.allocations' => $rules['allocation_limit'],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -39,7 +42,9 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
 | 
			
		||||
        $data = parent::validated();
 | 
			
		||||
 | 
			
		||||
        $data['allocation_id'] = $data['allocation'];
 | 
			
		||||
        unset($data['allocation']);
 | 
			
		||||
        $data['database_limit'] = $data['feature_limits']['databases'];
 | 
			
		||||
        $data['allocation_limit'] = $data['feature_limits']['allocations'];
 | 
			
		||||
        unset($data['allocation'], $data['feature_limits']);
 | 
			
		||||
 | 
			
		||||
        return $data;
 | 
			
		||||
    }
 | 
			
		||||
@ -56,6 +61,8 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
 | 
			
		||||
            'remove_allocations' => 'allocations to remove',
 | 
			
		||||
            'add_allocations.*' => 'allocation to add',
 | 
			
		||||
            'remove_allocations.*' => 'allocation to remove',
 | 
			
		||||
            'feature_limits.databases' => 'Database Limit',
 | 
			
		||||
            'feature_limits.allocations' => 'Allocation Limit',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -69,6 +69,8 @@ class Server extends Model implements CleansAttributes, ValidableContract
 | 
			
		||||
        'skip_scripts' => 'sometimes',
 | 
			
		||||
        'image' => 'required',
 | 
			
		||||
        'startup' => 'required',
 | 
			
		||||
        'database_limit' => 'present',
 | 
			
		||||
        'allocation_limit' => 'present',
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -93,6 +95,8 @@ class Server extends Model implements CleansAttributes, ValidableContract
 | 
			
		||||
        'skip_scripts' => 'boolean',
 | 
			
		||||
        'image' => 'string|max:255',
 | 
			
		||||
        'installed' => 'boolean',
 | 
			
		||||
        'database_limit' => 'nullable|integer|min:0',
 | 
			
		||||
        'allocation_limit' => 'nullable|integer|min:0',
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -116,6 +120,8 @@ class Server extends Model implements CleansAttributes, ValidableContract
 | 
			
		||||
        'egg_id' => 'integer',
 | 
			
		||||
        'pack_id' => 'integer',
 | 
			
		||||
        'installed' => 'integer',
 | 
			
		||||
        'database_limit' => 'integer',
 | 
			
		||||
        'allocation_limit' => 'integer',
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -91,6 +91,8 @@ class BuildModificationService
 | 
			
		||||
            'cpu' => array_get($data, 'cpu'),
 | 
			
		||||
            'disk' => array_get($data, 'disk'),
 | 
			
		||||
            'allocation_id' => array_get($data, 'allocation_id'),
 | 
			
		||||
            'database_limit' => array_get($data, 'database_limit'),
 | 
			
		||||
            'allocation_limit' => array_get($data, 'allocation_limit'),
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $allocations = $this->allocationRepository->findWhere([['server_id', '=', $server->id]]);
 | 
			
		||||
 | 
			
		||||
@ -75,6 +75,10 @@ class ServerTransformer extends BaseTransformer
 | 
			
		||||
                'io' => $server->io,
 | 
			
		||||
                'cpu' => $server->cpu,
 | 
			
		||||
            ],
 | 
			
		||||
            'feature_limits' => [
 | 
			
		||||
                'databases' => $server->database_limit,
 | 
			
		||||
                'allocations' => $server->allocation_limit,
 | 
			
		||||
            ],
 | 
			
		||||
            'user' => $server->owner_id,
 | 
			
		||||
            'node' => $server->node_id,
 | 
			
		||||
            'allocation' => $server->allocation_id,
 | 
			
		||||
 | 
			
		||||
@ -36,6 +36,10 @@ class ServerTransformer extends BaseClientTransformer
 | 
			
		||||
                'io' => $server->io,
 | 
			
		||||
                'cpu' => $server->cpu,
 | 
			
		||||
            ],
 | 
			
		||||
            'feature_limits' => [
 | 
			
		||||
                'databases' => $server->database_limit,
 | 
			
		||||
                'allocations' => $server->allocation_limit,
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,33 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
use Illuminate\Support\Facades\Schema;
 | 
			
		||||
use Illuminate\Database\Schema\Blueprint;
 | 
			
		||||
use Illuminate\Database\Migrations\Migration;
 | 
			
		||||
 | 
			
		||||
class AddDatabaseAndPortLimitColumnsToServersTable extends Migration
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Run the migrations.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function up()
 | 
			
		||||
    {
 | 
			
		||||
        Schema::table('servers', function (Blueprint $table) {
 | 
			
		||||
            $table->unsignedInteger('database_limit')->after('installed')->nullable()->default(0);
 | 
			
		||||
            $table->unsignedInteger('allocation_limit')->after('installed')->nullable()->default(0);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Reverse the migrations.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function down()
 | 
			
		||||
    {
 | 
			
		||||
        Schema::table('servers', function (Blueprint $table) {
 | 
			
		||||
            $table->dropColumn(['database_limit', 'allocation_limit']);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -111,7 +111,7 @@
 | 
			
		||||
                    <div class="form-group col-sm-4">
 | 
			
		||||
                        <label for="pSwap">Swap</label>
 | 
			
		||||
                        <div class="input-group">
 | 
			
		||||
                            <input type="text" value="{{ old('swap') }}" class="form-control" name="swap" id="pSwap" />
 | 
			
		||||
                            <input type="text" value="{{ old('swap', 0) }}" class="form-control" name="swap" id="pSwap" />
 | 
			
		||||
                            <span class="input-group-addon">MB</span>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
 | 
			
		||||
@ -89,6 +89,33 @@
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="col-sm-7">
 | 
			
		||||
            <div class="row">
 | 
			
		||||
                <div class="col-xs-12">
 | 
			
		||||
                    <div class="box">
 | 
			
		||||
                        <div class="box-header with-border">
 | 
			
		||||
                            <h3 class="box-title">Application Feature Limits</h3>
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="box-body">
 | 
			
		||||
                            <div class="row">
 | 
			
		||||
                                <div class="form-group col-xs-6">
 | 
			
		||||
                                    <label for="cpu" class="control-label">Database Limit</label>
 | 
			
		||||
                                    <div>
 | 
			
		||||
                                        <input type="text" name="database_limit" class="form-control" value="{{ old('database_limit', $server->database_limit) }}"/>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <p class="text-muted small">The total number of databases a user is allowed to create for this server. Leave blank to allow unlimmited.</p>
 | 
			
		||||
                                </div>
 | 
			
		||||
                                <div class="form-group col-xs-6">
 | 
			
		||||
                                    <label for="cpu" class="control-label">Allocation Limit</label>
 | 
			
		||||
                                    <div>
 | 
			
		||||
                                        <input type="text" name="allocation_limit" class="form-control" value="{{ old('allocation_limit', $server->allocation_limit) }}"/>
 | 
			
		||||
                                    </div>
 | 
			
		||||
                                    <p class="text-muted small"><strong>This feature is not currently implemented.</strong> The total number of allocations a user is allowed to create for this server. Leave blank to allow unlimited.</p>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="col-xs-12">
 | 
			
		||||
                    <div class="box">
 | 
			
		||||
                        <div class="box-header with-border">
 | 
			
		||||
                            <h3 class="box-title">Allocation Management</h3>
 | 
			
		||||
@ -136,6 +163,8 @@
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </form>
 | 
			
		||||
</div>
 | 
			
		||||
@endsection
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user