Fix loose boolean convert

This commit is contained in:
Matej Bačo
2022-09-23 09:25:09 +00:00
parent 384543c553
commit 320cfc2858
6 changed files with 28 additions and 19 deletions
+2 -2
View File
@@ -313,9 +313,9 @@ App::get('/v1/avatars/qr')
->param('margin', 1, new Range(0, 10), 'Margin from edge. Pass an integer between 0 to 10. Defaults to 1.', true)
->param('download', false, new Boolean(true), 'Return resulting image with \'Content-Disposition: attachment \' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0.', true)
->inject('response')
->action(function (string $text, int $size, int $margin, bool $download, Response $response) {
->action(function (string $text, int $size, int $margin, mixed $downloadLoose, Response $response) {
$download = in_array($downloadLoose, ['1', 'true', 1, true], true);
$download = ($download === '1' || $download === 'true' || $download === 1 || $download === true);
$options = new QROptions([
'addQuietzone' => true,
'quietzoneSize' => $margin,
+4 -2
View File
@@ -496,7 +496,8 @@ App::post('/v1/databases/:databaseId/collections')
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $name, ?array $permissions, bool $documentSecurity, Response $response, Database $dbForProject, Event $events) {
->action(function (string $databaseId, string $collectionId, string $name, ?array $permissions, mixed $documentSecurityLoose, Response $response, Database $dbForProject, Event $events) {
$documentSecurity = in_array($documentSecurityLoose, ['1', 'true', 1, true], true);
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
@@ -752,7 +753,8 @@ App::put('/v1/databases/:databaseId/collections/:collectionId')
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $name, ?array $permissions, bool $documentSecurity, bool $enabled, Response $response, Database $dbForProject, Event $events) {
->action(function (string $databaseId, string $collectionId, string $name, ?array $permissions, mixed $documentSecurityLoose, bool $enabled, Response $response, Database $dbForProject, Event $events) {
$documentSecurity = in_array($documentSecurityLoose, ['1', 'true', 1, true], true);
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
+2 -3
View File
@@ -610,7 +610,8 @@ App::post('/v1/functions/:functionId/deployments')
->inject('project')
->inject('deviceFunctions')
->inject('deviceLocal')
->action(function (string $functionId, string $entrypoint, mixed $code, bool $activate, Request $request, Response $response, Database $dbForProject, Event $events, Document $project, Device $deviceFunctions, Device $deviceLocal) {
->action(function (string $functionId, string $entrypoint, mixed $code, mixed $activateLoose, Request $request, Response $response, Database $dbForProject, Event $events, Document $project, Device $deviceFunctions, Device $deviceLocal) {
$activate = in_array($activateLoose, ['1', 'true', 1, true], true);
$function = $dbForProject->getDocument('functions', $functionId);
@@ -689,8 +690,6 @@ App::post('/v1/functions/:functionId/deployments')
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed moving file');
}
$activate = (bool) filter_var($activate, FILTER_VALIDATE_BOOLEAN);
if ($chunksUploaded === $chunks) {
if ($activate) {
// Remove deploy for all other deployments.
+6 -8
View File
@@ -510,12 +510,12 @@ App::patch('/v1/projects/:projectId/auth/:method')
->param('status', false, new Boolean(true), 'Set the status of this auth method.')
->inject('response')
->inject('dbForConsole')
->action(function (string $projectId, string $method, bool $status, Response $response, Database $dbForConsole) {
->action(function (string $projectId, string $method, mixed $statusLoose, Response $response, Database $dbForConsole) {
$status = in_array($statusLoose, ['1', 'true', 1, true], true);
$project = $dbForConsole->getDocument('projects', $projectId);
$auth = Config::getParam('auth')[$method] ?? [];
$authKey = $auth['key'] ?? '';
$status = ($status === '1' || $status === 'true' || $status === 1 || $status === true);
if ($project->isEmpty()) {
throw new Exception(Exception::PROJECT_NOT_FOUND);
@@ -593,7 +593,8 @@ App::post('/v1/projects/:projectId/webhooks')
->param('httpPass', '', new Text(256), 'Webhook HTTP password. Max length: 256 chars.', true)
->inject('response')
->inject('dbForConsole')
->action(function (string $projectId, string $name, array $events, string $url, bool $security, string $httpUser, string $httpPass, Response $response, Database $dbForConsole) {
->action(function (string $projectId, string $name, array $events, string $url, mixed $securityLoose, string $httpUser, string $httpPass, Response $response, Database $dbForConsole) {
$security = in_array($securityLoose, ['1', 'true', 1, true], true);
$project = $dbForConsole->getDocument('projects', $projectId);
@@ -601,8 +602,6 @@ App::post('/v1/projects/:projectId/webhooks')
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$security = (bool) filter_var($security, FILTER_VALIDATE_BOOLEAN);
$webhook = new Document([
'$id' => ID::unique(),
'$permissions' => [
@@ -716,7 +715,8 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId')
->param('httpPass', '', new Text(256), 'Webhook HTTP password. Max length: 256 chars.', true)
->inject('response')
->inject('dbForConsole')
->action(function (string $projectId, string $webhookId, string $name, array $events, string $url, bool $security, string $httpUser, string $httpPass, Response $response, Database $dbForConsole) {
->action(function (string $projectId, string $webhookId, string $name, array $events, string $url, mixed $securityLoose, string $httpUser, string $httpPass, Response $response, Database $dbForConsole) {
$security = in_array($securityLoose, ['1', 'true', 1, true], true);
$project = $dbForConsole->getDocument('projects', $projectId);
@@ -724,8 +724,6 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId')
throw new Exception(Exception::PROJECT_NOT_FOUND);
}
$security = ($security === '1' || $security === 'true' || $security === 1 || $security === true);
$webhook = $dbForConsole->findOne('webhooks', [
Query::equal('_uid', [$webhookId]),
Query::equal('projectInternalId', [$project->getInternalId()]),
+11 -2
View File
@@ -71,7 +71,11 @@ App::post('/v1/storage/buckets')
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $bucketId, string $name, ?array $permissions, bool $fileSecurity, bool $enabled, int $maximumFileSize, array $allowedFileExtensions, string $compression, bool $encryption, bool $antivirus, Response $response, Database $dbForProject, Event $events) {
->action(function (string $bucketId, string $name, ?array $permissions, mixed $fileSecurityLoose, mixed $enabledLoose, int $maximumFileSize, array $allowedFileExtensions, string $compression, mixed $encryptionLoose, mixed $antivirusLoose, Response $response, Database $dbForProject, Event $events) {
$fileSecurity = in_array($fileSecurityLoose, ['1', 'true', 1, true], true);
$enabled = in_array($enabledLoose, ['1', 'true', 1, true], true);
$encryption = in_array($encryptionLoose, ['1', 'true', 1, true], true);
$antivirus = in_array($antivirusLoose, ['1', 'true', 1, true], true);
$bucketId = $bucketId === 'unique()' ? ID::unique() : $bucketId;
@@ -243,7 +247,12 @@ App::put('/v1/storage/buckets/:bucketId')
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $bucketId, string $name, ?array $permissions, bool $fileSecurity, bool $enabled, ?int $maximumFileSize, array $allowedFileExtensions, string $compression, bool $encryption, bool $antivirus, Response $response, Database $dbForProject, Event $events) {
->action(function (string $bucketId, string $name, ?array $permissions, mixed $fileSecurityLoose, mixed $enabledLoose, ?int $maximumFileSize, array $allowedFileExtensions, string $compression, mixed $encryptionLoose, mixed $antivirusLoose, Response $response, Database $dbForProject, Event $events) {
$fileSecurity = in_array($fileSecurityLoose, ['1', 'true', 1, true], true);
$enabled = in_array($enabledLoose, ['1', 'true', 1, true], true);
$encryption = in_array($encryptionLoose, ['1', 'true', 1, true], true);
$antivirus = in_array($antivirusLoose, ['1', 'true', 1, true], true);
$bucket = $dbForProject->getDocument('buckets', $bucketId);
if ($bucket->isEmpty()) {
+3 -2
View File
@@ -633,7 +633,8 @@ App::patch('/v1/users/:userId/status')
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $userId, bool $status, Response $response, Database $dbForProject, Event $events) {
->action(function (string $userId, mixed $statusLoose, Response $response, Database $dbForProject, Event $events) {
$status = in_array($statusLoose, ['1', 'true', 1, true], true);
$user = $dbForProject->getDocument('users', $userId);
@@ -641,7 +642,7 @@ App::patch('/v1/users/:userId/status')
throw new Exception(Exception::USER_NOT_FOUND);
}
$user = $dbForProject->updateDocument('users', $user->getId(), $user->setAttribute('status', (bool) $status));
$user = $dbForProject->updateDocument('users', $user->getId(), $user->setAttribute('status', $status));
$events
->setParam('userId', $user->getId());