Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions app/Http/Controllers/API/v1/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ class ConfigurationController extends WsConfigController
{
use ApiQueryable;

// todo: Remove this when the parent controller makes the method protected
private function getAllowedConfigKeys(): array
{
return config('model-configuration.allowed_keys', []);

}

public function store(Request $request): JsonResponse
{
$validator = Validator::make($request->all(), [
$rules = [
'key' => 'required',
'value' => 'required',
'type' => 'required|in:string,int,float,bool,array,json,date',
'client_id' => ['nullable', 'string', new ValidateClientId],
]);
];

$allowedKeys = $this->getAllowedConfigKeys();
if (! empty($allowedKeys)) {
$rules['key'] = 'required|in:'.implode(',', $allowedKeys);
}
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
return $this->failure('Validation failed.', 422, [$validator->errors()]);
}
Expand Down Expand Up @@ -59,6 +71,11 @@ public function update(Request $request, $key): JsonResponse
$user = $request->user();

$formattedKey = $this->sanitizeKey($key);
$allowedKeys = $this->getAllowedConfigKeys();

if (! empty($allowedKeys) && ! in_array($formattedKey, $allowedKeys)) {
return $this->failure('Invalid configuration key.', 422);
}

// Check if the configuration exists
$configuration = $user->getConfig($formattedKey);
Expand Down
Loading