From f818f16ebe30c5ea5c2dea30ef40ff54b87329bf Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 13 May 2026 18:25:06 +0530 Subject: [PATCH] feat: simplify presence parameter validation by removing Nullable wrapper --- .../Platform/Modules/Presences/HTTP/Update.php | 13 ++++++------- .../Platform/Modules/Presences/HTTP/Upsert.php | 9 ++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php index 5e040701bb..545612ca62 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php @@ -24,7 +24,6 @@ use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Validator\Boolean; use Utopia\Validator\JSON; -use Utopia\Validator\Nullable; use Utopia\Validator\Text; class Update extends PlatformAction @@ -93,15 +92,15 @@ class Update extends PlatformAction ), ]) ->param('presenceId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Presence unique ID.', false, ['dbForProject']) - ->param('userId', null, new Nullable(new UID()), 'User ID.', true) - ->param('status', null, new Nullable(new Text(Database::LENGTH_KEY)), 'Presence status.', true) - ->param('expiresAt', null, new Nullable(new DatetimeValidator( + ->param('userId', null, new UID(), 'User ID.', true) + ->param('status', null, new Text(Database::LENGTH_KEY), 'Presence status.', true) + ->param('expiresAt', null, new DatetimeValidator( new \DateTime(), (new \DateTime())->modify('+30 days'), requireDateInFuture: true - )), 'Presence expiry datetime.', true) - ->param('metadata', null, new Nullable(new JSON()), 'Presence metadata object.', true) - ->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE])), 'An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) + ), 'Presence expiry datetime.', true) + ->param('metadata', null, new JSON(), 'Presence metadata object.', true) + ->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE]), 'An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('purge', false, new Boolean(true), 'When true, purge cached responses used by list presences endpoint.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php index 298bd77f49..f9408c72a9 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Upsert.php @@ -24,7 +24,6 @@ use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\Validator\JSON; -use Utopia\Validator\Nullable; use Utopia\Validator\Text; class Upsert extends PlatformAction @@ -93,14 +92,14 @@ class Upsert extends PlatformAction ), ]) ->param('presenceId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Presence unique ID.', false, ['dbForProject']) - ->param('userId', null, new Nullable(new UID()), 'User ID.', true) + ->param('userId', null, new UID(), 'User ID.', true) ->param('status', '', new Text(Database::LENGTH_KEY), 'Presence status.', false) - ->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE])), 'An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) - ->param('expiresAt', null, new Nullable(new DatetimeValidator( + ->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE]), 'An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) + ->param('expiresAt', null, new DatetimeValidator( new \DateTime(), (new \DateTime())->modify('+30 days'), requireDateInFuture: true - )), 'Presence expiry datetime.', true) + ), 'Presence expiry datetime.', true) ->param('metadata', [], new JSON(), 'Presence metadata object.', true) ->inject('response') ->inject('request')