diff --git a/app/config/collections.php b/app/config/collections.php index 4da8de6c45..df62b3f4fa 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2,6 +2,7 @@ use Utopia\Config\Config; use Utopia\Database\Database; +use Utopia\Database\ID; $providers = Config::getParam('providers', []); $auth = Config::getParam('auth', []); @@ -17,12 +18,12 @@ $auth = Config::getParam('auth', []); $collections = [ 'databases' => [ - '$collection' => Database::METADATA, - '$id' => 'databases', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('databases'), 'name' => 'Databases', 'attributes' => [ [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'size' => 256, 'required' => true, @@ -31,7 +32,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -44,7 +45,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_fulltext_search', + '$id' => ID::custom('_fulltext_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [], @@ -53,12 +54,12 @@ $collections = [ ], ], 'collections' => [ - '$collection' => 'databases', - '$id' => 'collections', + '$collection' => ID::custom('databases'), + '$id' => ID::custom('collections'), 'name' => 'Collections', 'attributes' => [ [ - '$id' => 'databaseInternalId', + '$id' => ID::custom('databaseInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -69,7 +70,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'databaseId', + '$id' => ID::custom('databaseId'), 'type' => Database::VAR_STRING, 'signed' => true, 'size' => Database::LENGTH_KEY, @@ -80,7 +81,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'size' => 256, 'required' => true, @@ -89,7 +90,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'enabled', + '$id' => ID::custom('enabled'), 'type' => Database::VAR_BOOLEAN, 'signed' => true, 'size' => 0, @@ -100,7 +101,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'documentSecurity', + '$id' => ID::custom('documentSecurity'), 'type' => Database::VAR_BOOLEAN, 'signed' => true, 'size' => 0, @@ -111,7 +112,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'attributes', + '$id' => ID::custom('attributes'), 'type' => Database::VAR_STRING, 'size' => 1000000, 'required' => false, @@ -120,7 +121,7 @@ $collections = [ 'filters' => ['subQueryAttributes'], ], [ - '$id' => 'indexes', + '$id' => ID::custom('indexes'), 'type' => Database::VAR_STRING, 'size' => 1000000, 'required' => false, @@ -129,7 +130,7 @@ $collections = [ 'filters' => ['subQueryIndexes'], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -142,7 +143,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_fulltext_search', + '$id' => ID::custom('_fulltext_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [], @@ -152,12 +153,12 @@ $collections = [ ], 'attributes' => [ - '$collection' => Database::METADATA, - '$id' => 'attributes', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('attributes'), 'name' => 'Attributes', 'attributes' => [ [ - '$id' => 'databaseInternalId', + '$id' => ID::custom('databaseInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -168,7 +169,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'databaseId', + '$id' => ID::custom('databaseId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -179,7 +180,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'collectionInternalId', + '$id' => ID::custom('collectionInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -190,7 +191,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'collectionId', + '$id' => ID::custom('collectionId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -201,7 +202,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'key', + '$id' => ID::custom('key'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -212,7 +213,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'type', + '$id' => ID::custom('type'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -223,7 +224,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'status', + '$id' => ID::custom('status'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16, @@ -234,7 +235,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'size', + '$id' => ID::custom('size'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -245,7 +246,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'required', + '$id' => ID::custom('required'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -256,7 +257,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'default', + '$id' => ID::custom('default'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -267,7 +268,7 @@ $collections = [ 'filters' => ['casting'], ], [ - '$id' => 'signed', + '$id' => ID::custom('signed'), 'type' => Database::VAR_BOOLEAN, 'size' => 0, 'signed' => true, @@ -277,7 +278,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'array', + '$id' => ID::custom('array'), 'type' => Database::VAR_BOOLEAN, 'size' => 0, 'signed' => true, @@ -287,7 +288,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'format', + '$id' => ID::custom('format'), 'type' => Database::VAR_STRING, 'size' => 64, 'signed' => true, @@ -297,7 +298,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'formatOptions', + '$id' => ID::custom('formatOptions'), 'type' => Database::VAR_STRING, 'size' => 16384, 'signed' => true, @@ -307,7 +308,7 @@ $collections = [ 'filters' => ['json', 'range', 'enum'], ], [ - '$id' => 'filters', + '$id' => ID::custom('filters'), 'type' => Database::VAR_STRING, 'size' => 64, 'signed' => true, @@ -319,7 +320,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_db_collection', + '$id' => ID::custom('_key_db_collection'), 'type' => Database::INDEX_KEY, 'attributes' => ['databaseInternalId', 'collectionInternalId'], 'lengths' => [Database::LENGTH_KEY, Database::LENGTH_KEY], @@ -329,12 +330,12 @@ $collections = [ ], 'indexes' => [ - '$collection' => Database::METADATA, - '$id' => 'indexes', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('indexes'), 'name' => 'Indexes', 'attributes' => [ [ - '$id' => 'databaseInternalId', + '$id' => ID::custom('databaseInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -345,7 +346,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'databaseId', + '$id' => ID::custom('databaseId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -356,7 +357,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'collectionInternalId', + '$id' => ID::custom('collectionInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -367,7 +368,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'collectionId', + '$id' => ID::custom('collectionId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -378,7 +379,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'key', + '$id' => ID::custom('key'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -389,7 +390,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'type', + '$id' => ID::custom('type'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16, @@ -400,7 +401,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'status', + '$id' => ID::custom('status'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16, @@ -411,7 +412,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'attributes', + '$id' => ID::custom('attributes'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -422,7 +423,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'lengths', + '$id' => ID::custom('lengths'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -433,7 +434,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'orders', + '$id' => ID::custom('orders'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 4, @@ -446,7 +447,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_db_collection', + '$id' => ID::custom('_key_db_collection'), 'type' => Database::INDEX_KEY, 'attributes' => ['databaseInternalId', 'collectionInternalId'], 'lengths' => [Database::LENGTH_KEY, Database::LENGTH_KEY], @@ -456,12 +457,12 @@ $collections = [ ], 'projects' => [ - '$collection' => Database::METADATA, - '$id' => 'projects', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('projects'), 'name' => 'Projects', 'attributes' => [ [ - '$id' => 'teamInternalId', + '$id' => ID::custom('teamInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -472,7 +473,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'teamId', + '$id' => ID::custom('teamId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -483,7 +484,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 128, @@ -494,7 +495,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'description', + '$id' => ID::custom('description'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -505,7 +506,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'logo', + '$id' => ID::custom('logo'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -516,7 +517,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'url', + '$id' => ID::custom('url'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -527,7 +528,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'version', + '$id' => ID::custom('version'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16, @@ -538,7 +539,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'legalName', + '$id' => ID::custom('legalName'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -549,7 +550,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'legalCountry', + '$id' => ID::custom('legalCountry'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -560,7 +561,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'legalState', + '$id' => ID::custom('legalState'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -571,7 +572,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'legalCity', + '$id' => ID::custom('legalCity'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -582,7 +583,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'legalAddress', + '$id' => ID::custom('legalAddress'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -593,7 +594,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'legalTaxId', + '$id' => ID::custom('legalTaxId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -604,7 +605,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'services', + '$id' => ID::custom('services'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -615,7 +616,7 @@ $collections = [ 'filters' => ['json'], ], [ - '$id' => 'auths', + '$id' => ID::custom('auths'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -626,7 +627,7 @@ $collections = [ 'filters' => ['json'], ], [ - '$id' => 'authProviders', + '$id' => ID::custom('authProviders'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -637,7 +638,7 @@ $collections = [ 'filters' => ['json', 'encrypt'], ], [ - '$id' => 'platforms', + '$id' => ID::custom('platforms'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -648,7 +649,7 @@ $collections = [ 'filters' => ['subQueryPlatforms'], ], [ - '$id' => 'webhooks', + '$id' => ID::custom('webhooks'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -659,7 +660,7 @@ $collections = [ 'filters' => ['subQueryWebhooks'], ], [ - '$id' => 'keys', + '$id' => ID::custom('keys'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -670,7 +671,7 @@ $collections = [ 'filters' => ['subQueryKeys'], ], [ - '$id' => 'domains', + '$id' => ID::custom('domains'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -681,7 +682,7 @@ $collections = [ 'filters' => ['subQueryDomains'], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -694,7 +695,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_search', + '$id' => ID::custom('_key_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [], @@ -704,12 +705,12 @@ $collections = [ ], 'platforms' => [ - '$collection' => Database::METADATA, - '$id' => 'platforms', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('platforms'), 'name' => 'platforms', 'attributes' => [ [ - '$id' => 'projectInternalId', + '$id' => ID::custom('projectInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -720,7 +721,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'projectId', + '$id' => ID::custom('projectId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -731,7 +732,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'type', + '$id' => ID::custom('type'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16, @@ -742,7 +743,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -753,7 +754,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'key', + '$id' => ID::custom('key'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -764,7 +765,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'store', + '$id' => ID::custom('store'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -775,7 +776,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'hostname', + '$id' => ID::custom('hostname'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -788,7 +789,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_project', + '$id' => ID::custom('_key_project'), 'type' => Database::INDEX_KEY, 'attributes' => ['projectInternalId'], 'lengths' => [Database::LENGTH_KEY], @@ -798,12 +799,12 @@ $collections = [ ], 'domains' => [ - '$collection' => Database::METADATA, - '$id' => 'domains', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('domains'), 'name' => 'domains', 'attributes' => [ [ - '$id' => 'projectInternalId', + '$id' => ID::custom('projectInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -814,7 +815,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'projectId', + '$id' => ID::custom('projectId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -825,7 +826,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'updated', + '$id' => ID::custom('updated'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -836,7 +837,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'domain', + '$id' => ID::custom('domain'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -847,7 +848,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'tld', + '$id' => ID::custom('tld'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -858,7 +859,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'registerable', + '$id' => ID::custom('registerable'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -869,7 +870,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'verification', + '$id' => ID::custom('verification'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -880,7 +881,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'certificateId', + '$id' => ID::custom('certificateId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -893,7 +894,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_project', + '$id' => ID::custom('_key_project'), 'type' => Database::INDEX_KEY, 'attributes' => ['projectInternalId'], 'lengths' => [Database::LENGTH_KEY], @@ -903,12 +904,12 @@ $collections = [ ], 'keys' => [ - '$collection' => Database::METADATA, - '$id' => 'keys', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('keys'), 'name' => 'keys', 'attributes' => [ [ - '$id' => 'projectInternalId', + '$id' => ID::custom('projectInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -919,7 +920,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'projectId', + '$id' => ID::custom('projectId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -930,7 +931,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -941,7 +942,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'scopes', + '$id' => ID::custom('scopes'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -952,7 +953,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'secret', + '$id' => ID::custom('secret'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 512, // var_dump of \bin2hex(\random_bytes(128)) => string(256) doubling for encryption @@ -963,7 +964,7 @@ $collections = [ 'filters' => ['encrypt'], ], [ - '$id' => 'expire', + '$id' => ID::custom('expire'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -976,7 +977,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_project', + '$id' => ID::custom('_key_project'), 'type' => Database::INDEX_KEY, 'attributes' => ['projectInternalId'], 'lengths' => [Database::LENGTH_KEY], @@ -986,12 +987,12 @@ $collections = [ ], 'webhooks' => [ - '$collection' => Database::METADATA, - '$id' => 'webhooks', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('webhooks'), 'name' => 'webhooks', 'attributes' => [ [ - '$id' => 'projectInternalId', + '$id' => ID::custom('projectInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1002,7 +1003,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'projectId', + '$id' => ID::custom('projectId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1013,7 +1014,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1024,7 +1025,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'url', + '$id' => ID::custom('url'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1035,7 +1036,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'httpUser', + '$id' => ID::custom('httpUser'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1046,7 +1047,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'httpPass', + '$id' => ID::custom('httpPass'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, // TODO will the length suffice after encryption? @@ -1057,7 +1058,7 @@ $collections = [ 'filters' => ['encrypt'], ], [ - '$id' => 'security', + '$id' => ID::custom('security'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -1068,7 +1069,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'events', + '$id' => ID::custom('events'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1079,7 +1080,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'signatureKey', + '$id' => ID::custom('signatureKey'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -1092,7 +1093,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_project', + '$id' => ID::custom('_key_project'), 'type' => Database::INDEX_KEY, 'attributes' => ['projectInternalId'], 'lengths' => [Database::LENGTH_KEY], @@ -1102,12 +1103,12 @@ $collections = [ ], 'users' => [ - '$collection' => Database::METADATA, - '$id' => 'users', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('users'), 'name' => 'Users', 'attributes' => [ [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1118,7 +1119,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'email', + '$id' => ID::custom('email'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 320, @@ -1129,7 +1130,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'phone', + '$id' => ID::custom('phone'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16, // leading '+' and 15 digitts maximum by E.164 format @@ -1140,7 +1141,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'status', + '$id' => ID::custom('status'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -1151,7 +1152,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'password', + '$id' => ID::custom('password'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1162,7 +1163,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'passwordUpdate', + '$id' => ID::custom('passwordUpdate'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1173,7 +1174,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'prefs', + '$id' => ID::custom('prefs'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 65535, @@ -1184,7 +1185,7 @@ $collections = [ 'filters' => ['json'], ], [ - '$id' => 'registration', + '$id' => ID::custom('registration'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1195,7 +1196,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'emailVerification', + '$id' => ID::custom('emailVerification'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -1206,7 +1207,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'phoneVerification', + '$id' => ID::custom('phoneVerification'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -1217,7 +1218,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'reset', + '$id' => ID::custom('reset'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -1228,7 +1229,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'sessions', + '$id' => ID::custom('sessions'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1239,7 +1240,7 @@ $collections = [ 'filters' => ['subQuerySessions'], ], [ - '$id' => 'tokens', + '$id' => ID::custom('tokens'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1250,7 +1251,7 @@ $collections = [ 'filters' => ['subQueryTokens'], ], [ - '$id' => 'memberships', + '$id' => ID::custom('memberships'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1261,7 +1262,7 @@ $collections = [ 'filters' => ['subQueryMemberships'], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1274,21 +1275,21 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_email', + '$id' => ID::custom('_key_email'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['email'], 'lengths' => [320], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_phone', + '$id' => ID::custom('_key_phone'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['phone'], 'lengths' => [16], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_search', + '$id' => ID::custom('_key_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [], @@ -1298,12 +1299,12 @@ $collections = [ ], 'tokens' => [ - '$collection' => Database::METADATA, - '$id' => 'tokens', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('tokens'), 'name' => 'Tokens', 'attributes' => [ [ - '$id' => 'userInternalId', + '$id' => ID::custom('userInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1314,7 +1315,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'userId', + '$id' => ID::custom('userId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1325,7 +1326,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'type', + '$id' => ID::custom('type'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1336,7 +1337,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'secret', + '$id' => ID::custom('secret'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 512, // https://www.tutorialspoint.com/how-long-is-the-sha256-hash-in-mysql (512 for encryption) @@ -1347,7 +1348,7 @@ $collections = [ 'filters' => ['encrypt'], ], [ - '$id' => 'expire', + '$id' => ID::custom('expire'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1358,7 +1359,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'userAgent', + '$id' => ID::custom('userAgent'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1369,7 +1370,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'ip', + '$id' => ID::custom('ip'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 45, // https://stackoverflow.com/a/166157/2299554 @@ -1382,7 +1383,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_user', + '$id' => ID::custom('_key_user'), 'type' => Database::INDEX_KEY, 'attributes' => ['userInternalId'], 'lengths' => [Database::LENGTH_KEY], @@ -1392,12 +1393,12 @@ $collections = [ ], 'sessions' => [ - '$collection' => Database::METADATA, - '$id' => 'sessions', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('sessions'), 'name' => 'Sessions', 'attributes' => [ [ - '$id' => 'userInternalId', + '$id' => ID::custom('userInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1408,7 +1409,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'userId', + '$id' => ID::custom('userId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1419,7 +1420,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'provider', + '$id' => ID::custom('provider'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 128, @@ -1430,7 +1431,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'providerUid', + '$id' => ID::custom('providerUid'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -1441,7 +1442,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'providerAccessToken', + '$id' => ID::custom('providerAccessToken'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1452,7 +1453,7 @@ $collections = [ 'filters' => ['encrypt'], ], [ - '$id' => 'providerAccessTokenExpiry', + '$id' => ID::custom('providerAccessTokenExpiry'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1463,7 +1464,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'providerRefreshToken', + '$id' => ID::custom('providerRefreshToken'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1474,7 +1475,7 @@ $collections = [ 'filters' => ['encrypt'], ], [ - '$id' => 'secret', + '$id' => ID::custom('secret'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 512, // https://www.tutorialspoint.com/how-long-is-the-sha256-hash-in-mysql (512 for encryption) @@ -1485,7 +1486,7 @@ $collections = [ 'filters' => ['encrypt'], ], [ - '$id' => 'expire', + '$id' => ID::custom('expire'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1496,7 +1497,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'userAgent', + '$id' => ID::custom('userAgent'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1507,7 +1508,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'ip', + '$id' => ID::custom('ip'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 45, // https://stackoverflow.com/a/166157/2299554 @@ -1518,7 +1519,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'countryCode', + '$id' => ID::custom('countryCode'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2, @@ -1529,7 +1530,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'osCode', + '$id' => ID::custom('osCode'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1540,7 +1541,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'osName', + '$id' => ID::custom('osName'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1551,7 +1552,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'osVersion', + '$id' => ID::custom('osVersion'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1562,7 +1563,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'clientType', + '$id' => ID::custom('clientType'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1573,7 +1574,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'clientCode', + '$id' => ID::custom('clientCode'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1584,7 +1585,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'clientName', + '$id' => ID::custom('clientName'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1595,7 +1596,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'clientVersion', + '$id' => ID::custom('clientVersion'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1606,7 +1607,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'clientEngine', + '$id' => ID::custom('clientEngine'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1617,7 +1618,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'clientEngineVersion', + '$id' => ID::custom('clientEngineVersion'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1628,7 +1629,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'deviceName', + '$id' => ID::custom('deviceName'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1639,7 +1640,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'deviceBrand', + '$id' => ID::custom('deviceBrand'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1650,7 +1651,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'deviceModel', + '$id' => ID::custom('deviceModel'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1663,14 +1664,14 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_provider_providerUid', + '$id' => ID::custom('_key_provider_providerUid'), 'type' => Database::INDEX_KEY, 'attributes' => ['provider', 'providerUid'], 'lengths' => [100, 100], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ - '$id' => '_key_user', + '$id' => ID::custom('_key_user'), 'type' => Database::INDEX_KEY, 'attributes' => ['userInternalId'], 'lengths' => [Database::LENGTH_KEY], @@ -1680,12 +1681,12 @@ $collections = [ ], 'teams' => [ - '$collection' => Database::METADATA, - '$id' => 'teams', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('teams'), 'name' => 'Teams', 'attributes' => [ [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 128, @@ -1696,7 +1697,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'total', + '$id' => ID::custom('total'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1707,7 +1708,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1720,7 +1721,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_search', + '$id' => ID::custom('_key_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [], @@ -1730,12 +1731,12 @@ $collections = [ ], 'memberships' => [ - '$collection' => Database::METADATA, - '$id' => 'memberships', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('memberships'), 'name' => 'Memberships', 'attributes' => [ [ - '$id' => 'userInternalId', + '$id' => ID::custom('userInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1746,7 +1747,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'userId', + '$id' => ID::custom('userId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1757,7 +1758,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'teamInternalId', + '$id' => ID::custom('teamInternalId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1768,7 +1769,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'teamId', + '$id' => ID::custom('teamId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1779,7 +1780,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'roles', + '$id' => ID::custom('roles'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 128, @@ -1790,7 +1791,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'invited', + '$id' => ID::custom('invited'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1801,7 +1802,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'joined', + '$id' => ID::custom('joined'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1812,7 +1813,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'confirm', + '$id' => ID::custom('confirm'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -1823,7 +1824,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'secret', + '$id' => ID::custom('secret'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1834,7 +1835,7 @@ $collections = [ 'filters' => ['encrypt'], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -1847,28 +1848,28 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_unique', + '$id' => ID::custom('_key_unique'), 'type' => Database::INDEX_UNIQUE, 'attributes' => ['teamInternalId', 'userInternalId'], 'lengths' => [Database::LENGTH_KEY, Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ - '$id' => '_key_user', + '$id' => ID::custom('_key_user'), 'type' => Database::INDEX_KEY, 'attributes' => ['userInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_team', + '$id' => ID::custom('_key_team'), 'type' => Database::INDEX_KEY, 'attributes' => ['teamInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_search', + '$id' => ID::custom('_key_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [], @@ -1878,12 +1879,12 @@ $collections = [ ], 'functions' => [ - '$collection' => Database::METADATA, - '$id' => 'functions', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('functions'), 'name' => 'Functions', 'attributes' => [ [ - '$id' => 'execute', + '$id' => ID::custom('execute'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 128, @@ -1894,7 +1895,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -1906,7 +1907,7 @@ $collections = [ ], [ 'array' => false, - '$id' => 'status', + '$id' => ID::custom('status'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1916,7 +1917,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'runtime', + '$id' => ID::custom('runtime'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -1927,7 +1928,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'deployment', + '$id' => ID::custom('deployment'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1938,7 +1939,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'vars', + '$id' => ID::custom('vars'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 8192, @@ -1949,7 +1950,7 @@ $collections = [ 'filters' => ['json', 'encrypt'], ], [ - '$id' => 'events', + '$id' => ID::custom('events'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -1960,7 +1961,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'schedule', + '$id' => ID::custom('schedule'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 128, @@ -1971,7 +1972,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'schedulePrevious', + '$id' => ID::custom('schedulePrevious'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1982,7 +1983,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'scheduleNext', + '$id' => ID::custom('scheduleNext'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -1993,7 +1994,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'timeout', + '$id' => ID::custom('timeout'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2004,7 +2005,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -2017,7 +2018,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_search', + '$id' => ID::custom('_key_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [2048], @@ -2027,12 +2028,12 @@ $collections = [ ], 'deployments' => [ - '$collection' => Database::METADATA, - '$id' => 'deployments', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('deployments'), 'name' => 'Deployments', 'attributes' => [ [ - '$id' => 'resourceId', + '$id' => ID::custom('resourceId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2043,7 +2044,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'resourceType', + '$id' => ID::custom('resourceType'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2054,7 +2055,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'buildId', + '$id' => ID::custom('buildId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2066,7 +2067,7 @@ $collections = [ ], [ 'array' => false, - '$id' => 'entrypoint', + '$id' => ID::custom('entrypoint'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2076,7 +2077,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'path', + '$id' => ID::custom('path'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2087,7 +2088,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'size', + '$id' => ID::custom('size'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2098,7 +2099,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'metadata', + '$id' => ID::custom('metadata'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, // https://tools.ietf.org/html/rfc4288#section-4.2 @@ -2109,7 +2110,7 @@ $collections = [ 'filters' => ['json'], ], [ - '$id' => 'chunksTotal', + '$id' => ID::custom('chunksTotal'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2120,7 +2121,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'chunksUploaded', + '$id' => ID::custom('chunksUploaded'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2131,7 +2132,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -2142,7 +2143,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'activate', + '$id' => ID::custom('activate'), 'type' => Database::VAR_BOOLEAN, 'format' => '', 'size' => 0, @@ -2155,21 +2156,21 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_resource', + '$id' => ID::custom('_key_resource'), 'type' => Database::INDEX_KEY, 'attributes' => ['resourceId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_resource_type', + '$id' => ID::custom('_key_resource_type'), 'type' => Database::INDEX_KEY, 'attributes' => ['resourceType'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_search', + '$id' => ID::custom('_key_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [], @@ -2179,12 +2180,12 @@ $collections = [ ], 'builds' => [ - '$collection' => Database::METADATA, - '$id' => 'builds', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('builds'), 'name' => 'Builds', 'attributes' => [ [ - '$id' => 'startTime', + '$id' => ID::custom('startTime'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2195,7 +2196,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'endTime', + '$id' => ID::custom('endTime'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2206,7 +2207,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'duration', + '$id' => ID::custom('duration'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2217,7 +2218,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'deploymentId', + '$id' => ID::custom('deploymentId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2228,7 +2229,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'runtime', + '$id' => ID::custom('runtime'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2239,7 +2240,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'status', + '$id' => ID::custom('status'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 256, @@ -2250,7 +2251,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'outputPath', + '$id' => ID::custom('outputPath'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2261,7 +2262,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'stderr', + '$id' => ID::custom('stderr'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 1000000, @@ -2272,7 +2273,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'stdout', + '$id' => ID::custom('stdout'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 1000000, @@ -2283,7 +2284,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'sourceType', + '$id' => ID::custom('sourceType'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2294,7 +2295,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'source', + '$id' => ID::custom('source'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2307,7 +2308,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_deployment', + '$id' => ID::custom('_key_deployment'), 'type' => Database::INDEX_KEY, 'attributes' => ['deploymentId'], 'lengths' => [Database::LENGTH_KEY], @@ -2317,12 +2318,12 @@ $collections = [ ], 'executions' => [ - '$collection' => Database::METADATA, - '$id' => 'executions', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('executions'), 'name' => 'Executions', 'attributes' => [ [ - '$id' => 'functionId', + '$id' => ID::custom('functionId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2333,7 +2334,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'deploymentId', + '$id' => ID::custom('deploymentId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2345,7 +2346,7 @@ $collections = [ ], [ 'array' => false, - '$id' => 'trigger', + '$id' => ID::custom('trigger'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 128, @@ -2355,7 +2356,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'status', + '$id' => ID::custom('status'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 128, @@ -2366,7 +2367,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'response', + '$id' => ID::custom('response'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 1000000, @@ -2377,7 +2378,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'stderr', + '$id' => ID::custom('stderr'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 1000000, @@ -2388,7 +2389,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'statusCode', + '$id' => ID::custom('statusCode'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2399,7 +2400,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'time', + '$id' => ID::custom('time'), 'type' => Database::VAR_FLOAT, 'format' => '', 'size' => 0, @@ -2410,7 +2411,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -2423,14 +2424,14 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_function', + '$id' => ID::custom('_key_function'), 'type' => Database::INDEX_KEY, 'attributes' => ['functionId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_fulltext_search', + '$id' => ID::custom('_fulltext_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [], @@ -2440,12 +2441,12 @@ $collections = [ ], 'certificates' => [ - '$collection' => Database::METADATA, - '$id' => 'certificates', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('certificates'), 'name' => 'Certificates', 'attributes' => [ [ - '$id' => 'domain', + '$id' => ID::custom('domain'), 'type' => Database::VAR_STRING, 'format' => '', // The maximum total length of a domain name or number is 255 characters. @@ -2459,7 +2460,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'issueDate', + '$id' => ID::custom('issueDate'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2470,7 +2471,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'renewDate', + '$id' => ID::custom('renewDate'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2481,7 +2482,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'attempts', + '$id' => ID::custom('attempts'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2492,7 +2493,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'log', + '$id' => ID::custom('log'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -2503,7 +2504,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'updated', + '$id' => ID::custom('updated'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2516,7 +2517,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_domain', + '$id' => ID::custom('_key_domain'), 'type' => Database::INDEX_KEY, 'attributes' => ['domain'], 'lengths' => [255], @@ -2526,12 +2527,12 @@ $collections = [ ], 'buckets' => [ - '$collection' => Database::METADATA, - '$id' => 'buckets', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('buckets'), 'name' => 'Buckets', 'attributes' => [ [ - '$id' => 'enabled', + '$id' => ID::custom('enabled'), 'type' => Database::VAR_BOOLEAN, 'signed' => true, 'size' => 0, @@ -2541,7 +2542,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'signed' => true, 'size' => 128, @@ -2551,7 +2552,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'fileSecurity', + '$id' => ID::custom('fileSecurity'), 'type' => Database::VAR_BOOLEAN, 'signed' => true, 'size' => 1, @@ -2561,7 +2562,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'maximumFileSize', + '$id' => ID::custom('maximumFileSize'), 'type' => Database::VAR_INTEGER, 'signed' => false, 'size' => 8, @@ -2571,7 +2572,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'allowedFileExtensions', + '$id' => ID::custom('allowedFileExtensions'), 'type' => Database::VAR_STRING, 'signed' => true, 'size' => 64, @@ -2581,7 +2582,7 @@ $collections = [ 'array' => true, ], [ - '$id' => 'encryption', + '$id' => ID::custom('encryption'), 'type' => Database::VAR_BOOLEAN, 'signed' => true, 'size' => 0, @@ -2591,7 +2592,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'antivirus', + '$id' => ID::custom('antivirus'), 'type' => Database::VAR_BOOLEAN, 'signed' => true, 'size' => 0, @@ -2601,7 +2602,7 @@ $collections = [ 'array' => false, ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -2614,14 +2615,14 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_fulltext_name', + '$id' => ID::custom('_fulltext_name'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['name'], 'lengths' => [1024], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_search', + '$id' => ID::custom('_key_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [2048], @@ -2631,12 +2632,12 @@ $collections = [ ], 'stats' => [ - '$collection' => Database::METADATA, - '$id' => 'stats', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('stats'), 'name' => 'Stats', 'attributes' => [ [ - '$id' => 'metric', + '$id' => ID::custom('metric'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 255, @@ -2647,7 +2648,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'value', + '$id' => ID::custom('value'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 8, @@ -2658,7 +2659,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'time', + '$id' => ID::custom('time'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2669,7 +2670,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'period', + '$id' => ID::custom('period'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 4, @@ -2680,7 +2681,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'type', + '$id' => ID::custom('type'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 1, @@ -2693,21 +2694,21 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_time', + '$id' => ID::custom('_key_time'), 'type' => Database::INDEX_KEY, 'attributes' => ['time'], 'lengths' => [], 'orders' => [Database::ORDER_DESC], ], [ - '$id' => '_key_metric', + '$id' => ID::custom('_key_metric'), 'type' => Database::INDEX_KEY, 'attributes' => ['metric'], 'lengths' => [], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_metric_period', + '$id' => ID::custom('_key_metric_period'), 'type' => Database::INDEX_KEY, 'attributes' => ['metric', 'period'], 'lengths' => [], @@ -2717,12 +2718,12 @@ $collections = [ ], 'realtime' => [ - '$collection' => Database::METADATA, - '$id' => 'realtime', + '$collection' => ID::custom(Database::METADATA), + '$id' => ID::custom('realtime'), 'name' => 'Realtime Connections', 'attributes' => [ [ - '$id' => 'container', + '$id' => ID::custom('container'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2733,7 +2734,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'timestamp', + '$id' => ID::custom('timestamp'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2744,7 +2745,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'value', + '$id' => ID::custom('value'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -2757,7 +2758,7 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_timestamp', + '$id' => ID::custom('_key_timestamp'), 'type' => Database::INDEX_KEY, 'attributes' => ['timestamp'], 'lengths' => [], @@ -2766,13 +2767,13 @@ $collections = [ ] ], 'files' => [ - '$collection' => 'buckets', - '$id' => 'files', + '$collection' => ID::custom('buckets'), + '$id' => ID::custom('files'), '$name' => 'Files', 'attributes' => [ [ 'array' => false, - '$id' => 'bucketId', + '$id' => ID::custom('bucketId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -2782,7 +2783,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'name', + '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2793,7 +2794,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'path', + '$id' => ID::custom('path'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2804,7 +2805,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'signature', + '$id' => ID::custom('signature'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2815,7 +2816,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'mimeType', + '$id' => ID::custom('mimeType'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 127, // https://tools.ietf.org/html/rfc4288#section-4.2 @@ -2826,7 +2827,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'metadata', + '$id' => ID::custom('metadata'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, // https://tools.ietf.org/html/rfc4288#section-4.2 @@ -2837,7 +2838,7 @@ $collections = [ 'filters' => ['json'], ], [ - '$id' => 'sizeOriginal', + '$id' => ID::custom('sizeOriginal'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 8, @@ -2848,7 +2849,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'sizeActual', + '$id' => ID::custom('sizeActual'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 8, @@ -2859,7 +2860,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'algorithm', + '$id' => ID::custom('algorithm'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 255, @@ -2870,7 +2871,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'comment', + '$id' => ID::custom('comment'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2881,7 +2882,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'openSSLVersion', + '$id' => ID::custom('openSSLVersion'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 64, @@ -2892,7 +2893,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'openSSLCipher', + '$id' => ID::custom('openSSLCipher'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 64, @@ -2903,7 +2904,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'openSSLTag', + '$id' => ID::custom('openSSLTag'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2914,7 +2915,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'openSSLIV', + '$id' => ID::custom('openSSLIV'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 2048, @@ -2925,7 +2926,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'chunksTotal', + '$id' => ID::custom('chunksTotal'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2936,7 +2937,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'chunksUploaded', + '$id' => ID::custom('chunksUploaded'), 'type' => Database::VAR_INTEGER, 'format' => '', 'size' => 0, @@ -2947,7 +2948,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'search', + '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => 16384, @@ -2960,14 +2961,14 @@ $collections = [ ], 'indexes' => [ [ - '$id' => '_key_search', + '$id' => ID::custom('_key_search'), 'type' => Database::INDEX_FULLTEXT, 'attributes' => ['search'], 'lengths' => [2048], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_bucket', + '$id' => ID::custom('_key_bucket'), 'type' => Database::INDEX_KEY, 'attributes' => ['bucketId'], 'lengths' => [Database::LENGTH_KEY], diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index aa5d7515e2..5e8860c758 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -27,6 +27,7 @@ use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; +use Utopia\Database\ID; use Utopia\Database\Permission; use Utopia\Database\Query; use Utopia\Database\Role; @@ -97,11 +98,11 @@ App::post('/v1/account') try { $userId = $userId == 'unique()' ? $dbForProject->getId() : $userId; $user = Authorization::skip(fn() => $dbForProject->createDocument('users', new Document([ - '$id' => $userId, + '$id' => ID::custom($userId), '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user($userId)), - Permission::delete(Role::user($userId)), + Permission::update(Role::user(ID::custom($userId))), + Permission::delete(Role::user(ID::custom($userId))), ], 'email' => $email, 'emailVerification' => false, @@ -185,9 +186,9 @@ App::post('/v1/account/sessions/email') $secret = Auth::tokenGenerator(); $session = new Document(array_merge( [ - '$id' => $dbForProject->getId(), - 'userId' => $profile->getId(), - 'userInternalId' => $profile->getInternalId(), + '$id' => ID::custom($dbForProject->getId()), + 'userId' => ID::custom($profile->getId()), + 'userInternalId' => ID::custom($profile->getInternalId()), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $email, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -204,9 +205,9 @@ App::post('/v1/account/sessions/email') Authorization::setRole('user:' . $profile->getId()); $session = $dbForProject->createDocument('sessions', $session->setAttribute('$permissions', [ - Permission::read(Role::user($profile->getId())), - Permission::update(Role::user($profile->getId())), - Permission::delete(Role::user($profile->getId())), + Permission::read(Role::user(ID::custom($profile->getId()))), + Permission::update(Role::user(ID::custom($profile->getId()))), + Permission::delete(Role::user(ID::custom($profile->getId()))), ])); $dbForProject->deleteCachedDocument('users', $profile->getId()); @@ -484,11 +485,11 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') try { $userId = $dbForProject->getId(); $user = Authorization::skip(fn() => $dbForProject->createDocument('users', new Document([ - '$id' => $userId, + '$id' => ID::custom($userId), '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user($userId)), - Permission::delete(Role::user($userId)), + Permission::update(Role::user(ID::custom($userId))), + Permission::delete(Role::user(ID::custom($userId))), ], 'email' => $email, 'emailVerification' => true, @@ -520,9 +521,9 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $secret = Auth::tokenGenerator(); $expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG; $session = new Document(array_merge([ - '$id' => $dbForProject->getId(), - 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + '$id' => ID::custom($dbForProject->getId()), + 'userId' => ID::custom($user->getId()), + 'userInternalId' => ID::custom($user->getInternalId()), 'provider' => $provider, 'providerUid' => $oauth2ID, 'providerAccessToken' => $accessToken, @@ -553,9 +554,9 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $dbForProject->updateDocument('users', $user->getId(), $user); $session = $dbForProject->createDocument('sessions', $session->setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -654,11 +655,11 @@ App::post('/v1/account/sessions/magic-url') $userId = $userId == 'unique()' ? $dbForProject->getId() : $userId; $user = Authorization::skip(fn () => $dbForProject->createDocument('users', new Document([ - '$id' => $userId, + '$id' => ID::custom($userId), '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user($userId)), - Permission::delete(Role::user($userId)), + Permission::update(Role::user(ID::custom($userId))), + Permission::delete(Role::user(ID::custom($userId))), ], 'email' => $email, 'emailVerification' => false, @@ -680,7 +681,7 @@ App::post('/v1/account/sessions/magic-url') $expire = \time() + Auth::TOKEN_EXPIRATION_CONFIRM; $token = new Document([ - '$id' => $dbForProject->getId(), + '$id' => ID::custom($dbForProject->getId()), 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_MAGIC_URL, @@ -694,9 +695,9 @@ App::post('/v1/account/sessions/magic-url') $token = $dbForProject->createDocument('tokens', $token ->setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -783,7 +784,7 @@ App::put('/v1/account/sessions/magic-url') $expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG; $session = new Document(array_merge( [ - '$id' => $dbForProject->getId(), + '$id' => ID::custom($dbForProject->getId()), 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_MAGIC_URL, @@ -802,9 +803,9 @@ App::put('/v1/account/sessions/magic-url') $session = $dbForProject->createDocument('sessions', $session ->setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -904,11 +905,11 @@ App::post('/v1/account/sessions/phone') $userId = $userId == 'unique()' ? $dbForProject->getId() : $userId; $user = Authorization::skip(fn () => $dbForProject->createDocument('users', new Document([ - '$id' => $userId, + '$id' => ID::custom($userId), '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user($userId)), - Permission::delete(Role::user($userId)), + Permission::update(Role::user(ID::custom($userId))), + Permission::delete(Role::user(ID::custom($userId))), ], 'email' => null, 'phone' => $number, @@ -932,7 +933,7 @@ App::post('/v1/account/sessions/phone') $expire = \time() + Auth::TOKEN_EXPIRATION_PHONE; $token = new Document([ - '$id' => $dbForProject->getId(), + '$id' => ID::custom($dbForProject->getId()), 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_PHONE, @@ -946,9 +947,9 @@ App::post('/v1/account/sessions/phone') $token = $dbForProject->createDocument('tokens', $token ->setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -1022,7 +1023,7 @@ App::put('/v1/account/sessions/phone') $expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG; $session = new Document(array_merge( [ - '$id' => $dbForProject->getId(), + '$id' => ID::custom($dbForProject->getId()), 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_PHONE, @@ -1041,9 +1042,9 @@ App::put('/v1/account/sessions/phone') $session = $dbForProject->createDocument('sessions', $session ->setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -1141,11 +1142,11 @@ App::post('/v1/account/sessions/anonymous') $userId = $dbForProject->getId(); $user = Authorization::skip(fn() => $dbForProject->createDocument('users', new Document([ - '$id' => $userId, + '$id' => ID::custom($userId), '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user($userId)), - Permission::delete(Role::user($userId)), + Permission::update(Role::user(ID::custom($userId))), + Permission::delete(Role::user(ID::custom($userId))), ], 'email' => null, 'emailVerification' => false, @@ -1170,7 +1171,7 @@ App::post('/v1/account/sessions/anonymous') $expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG; $session = new Document(array_merge( [ - '$id' => $dbForProject->getId(), + '$id' => ID::custom($dbForProject->getId()), 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_ANONYMOUS, @@ -1188,9 +1189,9 @@ App::post('/v1/account/sessions/anonymous') Authorization::setRole('user:' . $user->getId()); $session = $dbForProject->createDocument('sessions', $session-> setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -2001,7 +2002,7 @@ App::post('/v1/account/recovery') $secret = Auth::tokenGenerator(); $recovery = new Document([ - '$id' => $dbForProject->getId(), + '$id' => ID::custom($dbForProject->getId()), 'userId' => $profile->getId(), 'userInternalId' => $profile->getInternalId(), 'type' => Auth::TOKEN_TYPE_RECOVERY, @@ -2015,9 +2016,9 @@ App::post('/v1/account/recovery') $recovery = $dbForProject->createDocument('tokens', $recovery ->setAttribute('$permissions', [ - Permission::read(Role::user($profile->getId())), - Permission::update(Role::user($profile->getId())), - Permission::delete(Role::user($profile->getId())), + Permission::read(Role::user(ID::custom($profile->getId()))), + Permission::update(Role::user(ID::custom($profile->getId()))), + Permission::delete(Role::user(ID::custom($profile->getId()))), ])); $dbForProject->deleteCachedDocument('users', $profile->getId()); @@ -2165,7 +2166,7 @@ App::post('/v1/account/verification') $expire = \time() + Auth::TOKEN_EXPIRATION_CONFIRM; $verification = new Document([ - '$id' => $dbForProject->getId(), + '$id' => ID::custom($dbForProject->getId()), 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_VERIFICATION, @@ -2179,9 +2180,9 @@ App::post('/v1/account/verification') $verification = $dbForProject->createDocument('tokens', $verification ->setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -2323,7 +2324,7 @@ App::post('/v1/account/verification/phone') $expire = \time() + Auth::TOKEN_EXPIRATION_CONFIRM; $verification = new Document([ - '$id' => $dbForProject->getId(), + '$id' => ID::custom($dbForProject->getId()), 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_PHONE, @@ -2337,9 +2338,9 @@ App::post('/v1/account/verification/phone') $verification = $dbForProject->createDocument('tokens', $verification ->setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 9c5805375f..9a7c79f31b 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -5,6 +5,7 @@ use Utopia\App; use Appwrite\Event\Delete; use Appwrite\Extend\Exception; use Utopia\Audit\Audit; +use Utopia\Database\ID; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; use Utopia\Validator\Integer; @@ -94,12 +95,12 @@ function createAttribute(string $databaseId, string $collectionId, Document $att try { $attribute = new Document([ - '$id' => $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, + '$id' => ID::custom($db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), 'key' => $key, - 'databaseInternalId' => $db->getInternalId(), - 'databaseId' => $db->getId(), - 'collectionInternalId' => $collection->getInternalId(), - 'collectionId' => $collectionId, + 'databaseInternalId' => ID::custom($db->getInternalId()), + 'databaseId' => ID::custom($db->getId()), + 'collectionInternalId' => ID::custom($collection->getInternalId()), + 'collectionId' => ID::custom($collectionId), 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck 'size' => $size, @@ -177,7 +178,7 @@ App::post('/v1/databases') try { $dbForProject->createDocument('databases', new Document([ - '$id' => $databaseId, + '$id' => ID::custom($databaseId), 'name' => $name, 'search' => implode(' ', [$databaseId, $name]), ])); @@ -193,7 +194,7 @@ App::post('/v1/databases') foreach ($collections['attributes'] as $attribute) { $attributes[] = new Document([ - '$id' => $attribute['$id'], + '$id' => ID::custom($attribute['$id']), 'type' => $attribute['type'], 'size' => $attribute['size'], 'required' => $attribute['required'], @@ -207,7 +208,7 @@ App::post('/v1/databases') foreach ($collections['indexes'] as $index) { $indexes[] = new Document([ - '$id' => $index['$id'], + '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], 'lengths' => $index['lengths'], @@ -344,7 +345,7 @@ App::get('/v1/databases/:databaseId/logs') $output[$i] = new Document([ 'event' => $log['event'], - 'userId' => $log['userId'], + 'userId' => ID::custom($log['userId']), 'userEmail' => $log['data']['userEmail'] ?? null, 'userName' => $log['data']['userName'] ?? null, 'mode' => $log['data']['mode'] ?? null, @@ -519,7 +520,7 @@ App::post('/v1/databases/:databaseId/collections') try { $dbForProject->createDocument('database_' . $database->getInternalId(), new Document([ - '$id' => $collectionId, + '$id' => ID::custom($collectionId), '$permissions' => $permissions ?? [], 'databaseInternalId' => $database->getInternalId(), 'databaseId' => $databaseId, @@ -1600,7 +1601,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') try { $index = $dbForProject->createDocument('indexes', new Document([ - '$id' => $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, + '$id' => ID::custom($db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), 'key' => $key, 'status' => 'processing', // processing, available, failed, deleting, stuck 'databaseInternalId' => $db->getInternalId(), @@ -1870,6 +1871,10 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception('Unauthorized permissions', 401, Exception::USER_UNAUTHORIZED); } + /** + * Add permissions for current the user for any missing types + * from the allowed permissions for this resource type. + */ $permissions = PermissionsProcessor::addDefaultsIfNeeded( $permissions, $user->getId(), diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index e3671fe89f..114f150a5e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -9,6 +9,7 @@ use Appwrite\Event\Func; use Appwrite\Event\Validator\Event as ValidatorEvent; use Appwrite\Extend\Exception; use Appwrite\Utopia\Database\Validator\CustomId; +use Utopia\Database\ID; use Utopia\Database\Permission; use Utopia\Database\Role; use Utopia\Database\Validator\UID; @@ -67,7 +68,7 @@ App::post('/v1/functions') $functionId = ($functionId == 'unique()') ? $dbForProject->getId() : $functionId; $function = $dbForProject->createDocument('functions', new Document([ - '$id' => $functionId, + '$id' => ID::custom($functionId), 'execute' => $execute, 'status' => 'disabled', 'name' => $name, @@ -570,13 +571,13 @@ App::post('/v1/functions/:functionId/deployments') if ($deployment->isEmpty()) { $deployment = $dbForProject->createDocument('deployments', new Document([ - '$id' => $deploymentId, + '$id' => ID::custom($deploymentId), '$permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceId' => $function->getId(), + 'resourceId' => ID::custom($function->getId()), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, 'path' => $path, @@ -602,7 +603,7 @@ App::post('/v1/functions/:functionId/deployments') } else { if ($deployment->isEmpty()) { $deployment = $dbForProject->createDocument('deployments', new Document([ - '$id' => $deploymentId, + '$id' => ID::custom($deploymentId), '$permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), @@ -861,10 +862,10 @@ App::post('/v1/functions/:functionId/executions') /** @var Document $execution */ $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', new Document([ - '$id' => $executionId, - '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [], - 'functionId' => $function->getId(), - 'deploymentId' => $deployment->getId(), + '$id' => ID::custom($executionId), + '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user(ID::custom($user->getId())))] : [], + 'functionId' => ID::custom($function->getId()), + 'deploymentId' => ID::custom($deployment->getId()), 'trigger' => 'http', // http / schedule / event 'status' => 'waiting', // waiting / processing / completed / failed 'statusCode' => 0, @@ -889,8 +890,8 @@ App::post('/v1/functions/:functionId/executions') if (!$current->isEmpty()) { $jwtObj = new JWT(App::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 10); // Instantiate with key, algo, maxAge and leeway. $jwt = $jwtObj->encode([ - 'userId' => $user->getId(), - 'sessionId' => $current->getId(), + 'userId' => ID::custom($user->getId()), + 'sessionId' => ID::custom($current->getId()), ]); } } diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 8c515f2418..d1bef6df2c 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -17,6 +17,7 @@ use Utopia\Audit\Audit; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\ID; use Utopia\Database\Permission; use Utopia\Database\Query; use Utopia\Database\Role; @@ -88,17 +89,17 @@ App::post('/v1/projects') } $project = $dbForConsole->createDocument('projects', new Document([ - '$id' => $projectId, + '$id' => ID::custom($projectId), '$permissions' => [ - Permission::read(Role::team($teamId)), - Permission::update(Role::team($teamId, 'owner')), - Permission::update(Role::team($teamId, 'developer')), - Permission::delete(Role::team($teamId, 'owner')), - Permission::delete(Role::team($teamId, 'developer')), + Permission::read(Role::team(ID::custom($teamId))), + Permission::update(Role::team(ID::custom($teamId), 'owner')), + Permission::update(Role::team(ID::custom($teamId), 'developer')), + Permission::delete(Role::team(ID::custom($teamId), 'owner')), + Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'name' => $name, - 'teamInternalId' => $team->getInternalId(), - 'teamId' => $team->getId(), + 'teamInternalId' => ID::custom($team->getInternalId()), + 'teamId' => ID::custom($team->getId()), 'description' => $description, 'logo' => $logo, 'url' => $url, @@ -108,7 +109,7 @@ App::post('/v1/projects') 'legalState' => $legalState, 'legalCity' => $legalCity, 'legalAddress' => $legalAddress, - 'legalTaxId' => $legalTaxId, + 'legalTaxId' => ID::custom($legalTaxId), 'services' => new stdClass(), 'platforms' => null, 'authProviders' => [], @@ -139,7 +140,7 @@ App::post('/v1/projects') foreach ($collection['attributes'] as $attribute) { $attributes[] = new Document([ - '$id' => $attribute['$id'], + '$id' => ID::custom($attribute['$id']), 'type' => $attribute['type'], 'size' => $attribute['size'], 'required' => $attribute['required'], @@ -153,7 +154,7 @@ App::post('/v1/projects') foreach ($collection['indexes'] as $index) { $indexes[] = new Document([ - '$id' => $index['$id'], + '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], 'lengths' => $index['lengths'], @@ -596,14 +597,14 @@ App::post('/v1/projects/:projectId/webhooks') $security = (bool) filter_var($security, FILTER_VALIDATE_BOOLEAN); $webhook = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => ID::custom($dbForConsole->getId()), '$permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getInternalId(), - 'projectId' => $project->getId(), + 'projectInternalId' => ID::custom($project->getInternalId()), + 'projectId' => ID::custom($project->getId()), 'name' => $name, 'events' => $events, 'url' => $url, @@ -843,14 +844,14 @@ App::post('/v1/projects/:projectId/keys') } $key = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => ID::custom($dbForConsole->getId()), '$permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), Permission::delete(Role::any()), ], 'projectInternalId' => $project->getInternalId(), - 'projectId' => $project->getId(), + 'projectId' => ID::custom($project->getId()), 'name' => $name, 'scopes' => $scopes, 'expire' => $expire, @@ -1042,7 +1043,7 @@ App::post('/v1/projects/:projectId/platforms') } $platform = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => ID::custom($dbForConsole->getId()), '$permissions' => [ 'read(any)', 'update(any)', @@ -1257,7 +1258,7 @@ App::post('/v1/projects/:projectId/domains') $domain = new Domain($domain); $domain = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => ID::custom($dbForConsole->getId()), '$permissions' => [ 'read(any)', 'update(any)', diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 1f0865d849..cb7d9ce143 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -19,6 +19,7 @@ use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Structure as StructureException; +use Utopia\Database\ID; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; @@ -82,7 +83,7 @@ App::post('/v1/storage/buckets') foreach ($files['attributes'] as $attribute) { $attributes[] = new Document([ - '$id' => $attribute['$id'], + '$id' => ID::custom($attribute['$id']), 'type' => $attribute['type'], 'size' => $attribute['size'], 'required' => $attribute['required'], @@ -96,7 +97,7 @@ App::post('/v1/storage/buckets') foreach ($files['indexes'] as $index) { $indexes[] = new Document([ - '$id' => $index['$id'], + '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], 'lengths' => $index['lengths'], @@ -105,8 +106,8 @@ App::post('/v1/storage/buckets') } $dbForProject->createDocument('buckets', new Document([ - '$id' => $bucketId, - '$collection' => 'buckets', + '$id' => ID::custom($bucketId), + '$collection' => ID::custom('buckets'), '$permissions' => $permissions, 'name' => $name, 'maximumFileSize' => $maximumFileSize, @@ -362,6 +363,10 @@ App::post('/v1/storage/buckets/:bucketId/files') throw new Exception('Unauthorized permissions', 401, Exception::USER_UNAUTHORIZED); } + /** + * Add permissions for current the user for any missing types + * from the allowed permissions for this resource type. + */ $permissions = PermissionsProcessor::addDefaultsIfNeeded( $permissions, $user->getId(), @@ -523,9 +528,9 @@ App::post('/v1/storage/buckets/:bucketId/files') try { if ($file->isEmpty()) { $doc = new Document([ - '$id' => $fileId, + '$id' => ID::custom($fileId), '$permissions' => $permissions, - 'bucketId' => $bucket->getId(), + 'bucketId' => ID::custom($bucket->getId()), 'name' => $fileName, 'path' => $path, 'signature' => $fileHash, @@ -580,7 +585,7 @@ App::post('/v1/storage/buckets/:bucketId/files') try { if ($file->isEmpty()) { $doc = new Document([ - '$id' => $fileId, + '$id' => ID::custom($fileId), '$permissions' => $permissions, 'bucketId' => $bucket->getId(), 'name' => $fileName, diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 47c7844db6..b2bd541bb7 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -21,6 +21,7 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Authorization as AuthorizationException; use Utopia\Database\Exception\Duplicate; +use Utopia\Database\ID; use Utopia\Database\Permission; use Utopia\Database\Query; use Utopia\Database\Role; @@ -60,11 +61,11 @@ App::post('/v1/teams') $teamId = $teamId == 'unique()' ? $dbForProject->getId() : $teamId; $team = Authorization::skip(fn() => $dbForProject->createDocument('teams', new Document([ - '$id' => $teamId , + '$id' => ID::custom($teamId ), '$permissions' => [ - Permission::read(Role::team($teamId)), - Permission::update(Role::team($teamId, 'owner')), - Permission::delete(Role::team($teamId, 'owner')), + Permission::read(Role::team(ID::custom($teamId))), + Permission::update(Role::team(ID::custom($teamId), 'owner')), + Permission::delete(Role::team(ID::custom($teamId), 'owner')), ], 'name' => $name, 'total' => ($isPrivilegedUser || $isAppUser) ? 0 : 1, @@ -74,19 +75,19 @@ App::post('/v1/teams') if (!$isPrivilegedUser && !$isAppUser) { // Don't add user on server mode $membershipId = $dbForProject->getId(); $membership = new Document([ - '$id' => $membershipId, + '$id' => ID::custom($membershipId), '$permissions' => [ - Permission::read(Role::user($user->getId())), - Permission::read(Role::team($team->getId())), - Permission::update(Role::user($user->getId())), - Permission::update(Role::team($team->getId(), 'owner')), - Permission::delete(Role::user($user->getId())), - Permission::delete(Role::team($team->getId(), 'owner')), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::read(Role::team(ID::custom($team->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::update(Role::team(ID::custom($team->getId()), 'owner')), + Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::team(ID::custom($team->getId()), 'owner')), ], - 'userId' => $user->getId(), + 'userId' => ID::custom($user->getId()), 'userInternalId' => $user->getInternalId(), - 'teamId' => $team->getId(), - 'teamInternalId' => $team->getInternalId(), + 'teamId' => ID::custom($team->getId()), + 'teamInternalId' => ID::custom($team->getInternalId()), 'roles' => $roles, 'invited' => \time(), 'joined' => \time(), @@ -338,12 +339,12 @@ App::post('/v1/teams/:teamId/memberships') try { $userId = $dbForProject->getId(); $invitee = Authorization::skip(fn() => $dbForProject->createDocument('users', new Document([ - '$id' => $userId, + '$id' => ID::custom($userId), '$permissions' => [ Permission::read(Role::any()), - Permission::read(Role::user($userId)), - Permission::update(Role::user($userId)), - Permission::delete(Role::user($userId)), + Permission::read(Role::user(ID::custom($userId))), + Permission::update(Role::user(ID::custom($userId))), + Permission::delete(Role::user(ID::custom($userId))), ], 'email' => $email, 'emailVerification' => false, @@ -379,18 +380,18 @@ App::post('/v1/teams/:teamId/memberships') $membershipId = $dbForProject->getId(); $membership = new Document([ - '$id' => $membershipId, + '$id' => ID::custom($membershipId), '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user($invitee->getId())), - Permission::update(Role::team($team->getId(), 'owner')), - Permission::delete(Role::user($invitee->getId())), - Permission::delete(Role::team($team->getId(), 'owner')), + Permission::update(Role::user(ID::custom($invitee->getId()))), + Permission::update(Role::team(ID::custom($team->getId()), 'owner')), + Permission::delete(Role::user(ID::custom($invitee->getId()))), + Permission::delete(Role::team(ID::custom($team->getId()), 'owner')), ], - 'userId' => $invitee->getId(), - 'userInternalId' => $invitee->getInternalId(), - 'teamId' => $team->getId(), - 'teamInternalId' => $team->getInternalId(), + 'userId' => ID::custom($invitee->getId()), + 'userInternalId' => ID::custom($invitee->getInternalId()), + 'teamId' => ID::custom($team->getId()), + 'teamInternalId' => ID::custom($team->getInternalId()), 'roles' => $roles, 'invited' => \time(), 'joined' => ($isPrivilegedUser || $isAppUser) ? \time() : 0, @@ -723,9 +724,9 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') $expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG; $secret = Auth::tokenGenerator(); $session = new Document(array_merge([ - '$id' => $dbForProject->getId(), - 'userId' => $user->getId(), - 'userInternalId' => $user->getInternalId(), + '$id' => ID::custom($dbForProject->getId()), + 'userId' => ID::custom($user->getId()), + 'userInternalId' => ID::custom($user->getInternalId()), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $user->getAttribute('email'), 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -737,9 +738,9 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') $session = $dbForProject->createDocument('sessions', $session ->setAttribute('$permissions', [ - Permission::read(Role::user($user->getId())), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), + Permission::read(Role::user(ID::custom($user->getId()))), + Permission::update(Role::user(ID::custom($user->getId()))), + Permission::delete(Role::user(ID::custom($user->getId()))), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -895,7 +896,7 @@ App::get('/v1/teams/:teamId/logs') $output[$i] = new Document([ 'event' => $log['event'], - 'userId' => $log['userId'], + 'userId' => ID::custom($log['userId']), 'userEmail' => $log['data']['userEmail'] ?? null, 'userName' => $log['data']['userName'] ?? null, 'mode' => $log['data']['mode'] ?? null, diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 088a2cb557..99f41d8d4b 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -14,6 +14,9 @@ use Appwrite\Utopia\Response; use Utopia\App; use Utopia\Audit\Audit; use Utopia\Config\Config; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; use Utopia\Locale\Locale; use Appwrite\Extend\Exception; use Utopia\Database\Document; @@ -56,11 +59,11 @@ App::post('/v1/users') try { $userId = $userId == 'unique()' ? $dbForProject->getId() : $userId; $user = $dbForProject->createDocument('users', new Document([ - '$id' => $userId, + '$id' => ID::custom($userId), '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user($userId)), - Permission::delete(Role::user($userId)), + Permission::update(Role::user(ID::custom($userId))), + Permission::delete(Role::user(ID::custom($userId))), ], 'email' => $email, 'emailVerification' => false, diff --git a/app/controllers/mock.php b/app/controllers/mock.php index d3b150a55f..0dafa44d68 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -282,7 +282,7 @@ App::post('/v1/mock/tests/general/upload') if ($end !== $size) { $response->json([ - '$id' => 'newfileid', + '$id' => ID::custom('newfileid'), 'chunksTotal' => $file['size'] / $chunkSize, 'chunksUploaded' => $start / $chunkSize ]); diff --git a/app/http.php b/app/http.php index 40dd703858..9d2ede9319 100644 --- a/app/http.php +++ b/app/http.php @@ -10,6 +10,7 @@ use Swoole\Http\Response as SwooleResponse; use Utopia\App; use Utopia\CLI\Console; use Utopia\Config\Config; +use Utopia\Database\ID; use Utopia\Database\Permission; use Utopia\Database\Role; use Utopia\Database\Validator\Authorization; @@ -134,7 +135,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { foreach ($collection['attributes'] as $attribute) { $attributes[] = new Document([ - '$id' => $attribute['$id'], + '$id' => ID::custom($attribute['$id']), 'type' => $attribute['type'], 'size' => $attribute['size'], 'required' => $attribute['required'], @@ -148,7 +149,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { foreach ($collection['indexes'] as $index) { $indexes[] = new Document([ - '$id' => $index['$id'], + '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], 'lengths' => $index['lengths'], @@ -162,8 +163,8 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { if ($dbForConsole->getDocument('buckets', 'default')->isEmpty()) { Console::success('[Setup] - Creating default bucket...'); $dbForConsole->createDocument('buckets', new Document([ - '$id' => 'default', - '$collection' => 'buckets', + '$id' => ID::custom('default'), + '$collection' => ID::custom('buckets'), 'name' => 'Default', 'maximumFileSize' => (int) App::getEnv('_APP_STORAGE_LIMIT', 0), // 10MB 'allowedFileExtensions' => [], @@ -192,7 +193,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { foreach ($files['attributes'] as $attribute) { $attributes[] = new Document([ - '$id' => $attribute['$id'], + '$id' => ID::custom($attribute['$id']), 'type' => $attribute['type'], 'size' => $attribute['size'], 'required' => $attribute['required'], @@ -206,7 +207,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { foreach ($files['indexes'] as $index) { $indexes[] = new Document([ - '$id' => $index['$id'], + '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], 'lengths' => $index['lengths'], diff --git a/app/init.php b/app/init.php index 146a4fc2a7..c8729b1d5e 100644 --- a/app/init.php +++ b/app/init.php @@ -43,6 +43,7 @@ use Appwrite\OpenSSL\OpenSSL; use Appwrite\Stats\Stats; use Appwrite\Utopia\View; use Utopia\App; +use Utopia\Database\ID; use Utopia\Logger\Logger; use Utopia\Config\Config; use Utopia\Locale\Locale; @@ -711,7 +712,7 @@ App::setResource('usage', function ($register) { App::setResource('clients', function ($request, $console, $project) { $console->setAttribute('platforms', [ // Always allow current host - '$collection' => 'platforms', + '$collection' => ID::custom('platforms'), 'name' => 'Current Host', 'type' => 'web', 'hostname' => $request->getHostname(), @@ -787,7 +788,7 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons if (APP_MODE_ADMIN !== $mode) { if ($project->isEmpty()) { - $user = new Document(['$id' => '', '$collection' => 'users']); + $user = new Document(['$id' => ID::custom(''), '$collection' => 'users']); } else { $user = $dbForProject->getDocument('users', Auth::$unique); } @@ -799,14 +800,14 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons $user->isEmpty() // Check a document has been found in the DB || !Auth::sessionVerify($user->getAttribute('sessions', []), Auth::$secret) ) { // Validate user has valid login token - $user = new Document(['$id' => '', '$collection' => 'users']); + $user = new Document(['$id' => ID::custom(''), '$collection' => 'users']); } if (APP_MODE_ADMIN === $mode) { if ($user->find('teamId', $project->getAttribute('teamId'), 'memberships')) { Authorization::setDefaultStatus(false); // Cancel security segmentation for admin users. } else { - $user = new Document(['$id' => '', '$collection' => 'users']); + $user = new Document(['$id' => ID::custom(''), '$collection' => 'users']); } } @@ -829,7 +830,7 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons } if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token - $user = new Document(['$id' => '', '$collection' => 'users']); + $user = new Document(['$id' => ID::custom(''), '$collection' => 'users']); } } @@ -854,10 +855,10 @@ App::setResource('project', function ($dbForConsole, $request, $console) { App::setResource('console', function () { return new Document([ - '$id' => 'console', - '$internalId' => 'console', + '$id' => ID::custom('console'), + '$internalId' => ID::custom('console'), 'name' => 'Appwrite', - '$collection' => 'projects', + '$collection' => ID::custom('projects'), 'description' => 'Appwrite core engine', 'logo' => '', 'teamId' => -1, @@ -865,7 +866,7 @@ App::setResource('console', function () { 'keys' => [], 'platforms' => [ [ - '$collection' => 'platforms', + '$collection' => ID::custom('platforms'), 'name' => 'Localhost', 'type' => 'web', 'hostname' => 'localhost', diff --git a/app/realtime.php b/app/realtime.php index 65a458ec9e..91b2ca6e9f 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -146,8 +146,8 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume try { $attempts++; $document = new Document([ - '$id' => $database->getId(), - '$collection' => 'realtime', + '$id' => ID::custom($database->getId()), + '$collection' => ID::custom('realtime'), '$permissions' => [], 'container' => $containerId, 'timestamp' => time(), @@ -443,7 +443,7 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, ])); $stats->set($project->getId(), [ - 'projectId' => $project->getId(), + 'projectId' => ID::custom($project->getId()), 'teamId' => $project->getAttribute('teamId') ]); $stats->incr($project->getId(), 'connections'); diff --git a/app/workers/builds.php b/app/workers/builds.php index 271e2967d4..9184fa3f96 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -80,10 +80,10 @@ class BuildsV1 extends Worker if (empty($buildId)) { $buildId = $dbForProject->getId(); $build = $dbForProject->createDocument('builds', new Document([ - '$id' => $buildId, + '$id' => ID::custom($buildId), '$permissions' => [], 'startTime' => $startTime, - 'deploymentId' => $deployment->getId(), + 'deploymentId' => ID::custom($deployment->getId()), 'status' => 'processing', 'outputPath' => '', 'runtime' => $function->getAttribute('runtime'), @@ -123,7 +123,7 @@ class BuildsV1 extends Worker /** Trigger Realtime */ $allEvents = Event::generateEvents('functions.[functionId].deployments.[deploymentId].update', [ - 'functionId' => $function->getId(), + 'functionId' => ID::custom($function->getId()), 'deploymentId' => $deployment->getId() ]); $target = Realtime::fromPayload( diff --git a/app/workers/functions.php b/app/workers/functions.php index 3b87d4a27e..1d45641d07 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -236,10 +236,10 @@ class FunctionsV1 extends Worker if ($execution->isEmpty()) { $executionId = $dbForProject->getId(); $execution = $dbForProject->createDocument('executions', new Document([ - '$id' => $executionId, - '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))], - 'functionId' => $functionId, - 'deploymentId' => $deploymentId, + '$id' => ID::custom($executionId), + '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user(ID::custom($user->getId())))], + 'functionId' => ID::custom($functionId), + 'deploymentId' => ID::custom($deploymentId), 'trigger' => $trigger, 'status' => 'waiting', 'statusCode' => 0, @@ -327,7 +327,7 @@ class FunctionsV1 extends Worker /** Trigger realtime event */ $allEvents = Event::generateEvents('functions.[functionId].executions.[executionId].update', [ - 'functionId' => $function->getId(), + 'functionId' => ID::custom($function->getId()), 'executionId' => $execution->getId() ]); $target = Realtime::fromPayload( diff --git a/phpunit.xml b/phpunit.xml index 5379852718..e955ab7cee 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index a92e232719..9d104637f7 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -9,6 +9,7 @@ use Utopia\CLI\Console; use Utopia\Config\Config; use Exception; use Utopia\App; +use Utopia\Database\ID; use Utopia\Database\Validator\Authorization; abstract class Migration @@ -62,15 +63,15 @@ abstract class Migration Authorization::setDefaultStatus(false); $this->collections = array_merge([ '_metadata' => [ - '$id' => '_metadata', + '$id' => ID::custom('_metadata'), '$collection' => Database::METADATA ], 'audit' => [ - '$id' => 'audit', + '$id' => ID::custom('audit'), '$collection' => Database::METADATA ], 'abuse' => [ - '$id' => 'abuse', + '$id' => ID::custom('abuse'), '$collection' => Database::METADATA ] ], Config::getParam('collections', [])); diff --git a/src/Appwrite/Migration/Version/V12.php b/src/Appwrite/Migration/Version/V12.php index 78d6407519..48abb5bedc 100644 --- a/src/Appwrite/Migration/Version/V12.php +++ b/src/Appwrite/Migration/Version/V12.php @@ -158,8 +158,8 @@ class V12 extends Migration if (!$this->projectDB->findOne('buckets', [new Query('$id', Query::TYPE_EQUAL, ['default'])])) { $this->projectDB->createDocument('buckets', new Document([ - '$id' => 'default', - '$collection' => 'buckets', + '$id' => ID::custom('default'), + '$collection' => ID::custom('buckets'), 'dateCreated' => \time(), 'dateUpdated' => \time(), 'name' => 'Default', diff --git a/src/Appwrite/Migration/Version/V14.php b/src/Appwrite/Migration/Version/V14.php index 7d7d551ec5..ee9b686145 100644 --- a/src/Appwrite/Migration/Version/V14.php +++ b/src/Appwrite/Migration/Version/V14.php @@ -67,7 +67,7 @@ class V14 extends Migration try { $this->projectDB->createDocument('databases', new Document([ - '$id' => 'default', + '$id' => ID::custom('default'), 'name' => 'Default', 'search' => 'default Default' ])); diff --git a/src/Appwrite/Utopia/Response/Filters/V11.php b/src/Appwrite/Utopia/Response/Filters/V11.php index 31b0949e28..8fa22f42b2 100644 --- a/src/Appwrite/Utopia/Response/Filters/V11.php +++ b/src/Appwrite/Utopia/Response/Filters/V11.php @@ -278,7 +278,7 @@ class V11 extends Filter $content['rules'] = \array_map(function ($attribute) use ($content) { return [ '$id' => $attribute['key'], - '$collection' => $content['$id'], + '$collection' => ID::custom($content['$id']), 'type' => $attribute['type'], 'key' => $attribute['key'], 'label' => $attribute['key'], diff --git a/src/Appwrite/Utopia/Response/Model/Bucket.php b/src/Appwrite/Utopia/Response/Model/Bucket.php index fbcda389fb..04d2b45bc4 100644 --- a/src/Appwrite/Utopia/Response/Model/Bucket.php +++ b/src/Appwrite/Utopia/Response/Model/Bucket.php @@ -32,7 +32,7 @@ class Bucket extends Model 'type' => self::TYPE_STRING, 'description' => 'File permissions.', 'default' => [], - 'example' => [Permission::read(Role::any())], + 'example' => ['read("any")'], 'array' => true, ]) ->addRule('fileSecurity', [ diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php index e6e487b728..14764ced5b 100644 --- a/src/Appwrite/Utopia/Response/Model/Collection.php +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -32,7 +32,7 @@ class Collection extends Model 'type' => self::TYPE_STRING, 'description' => 'Collection permissions.', 'default' => '', - 'example' => Permission::read(Role::any()), + 'example' => ['read("any")'], 'array' => true ]) ->addRule('databaseId', [ diff --git a/src/Appwrite/Utopia/Response/Model/Document.php b/src/Appwrite/Utopia/Response/Model/Document.php index 41aadf6cf2..3547c2cc00 100644 --- a/src/Appwrite/Utopia/Response/Model/Document.php +++ b/src/Appwrite/Utopia/Response/Model/Document.php @@ -56,9 +56,9 @@ class Document extends Any ]) ->addRule('$permissions', [ 'type' => self::TYPE_STRING, - 'description' => 'Document write permissions.', + 'description' => 'Document permissions.', 'default' => '', - 'example' => Permission::read(Role::user('608f9da25e7e1')), + 'example' => ['read("any")'], 'array' => true, ]) ; diff --git a/src/Appwrite/Utopia/Response/Model/Execution.php b/src/Appwrite/Utopia/Response/Model/Execution.php index 6bc91c9a2a..9f3ab36dad 100644 --- a/src/Appwrite/Utopia/Response/Model/Execution.php +++ b/src/Appwrite/Utopia/Response/Model/Execution.php @@ -28,11 +28,11 @@ class Execution extends Model 'default' => 0, 'example' => 1592981250, ]) - ->addRule('$permissions', [ + ->addRule('$roles', [ 'type' => self::TYPE_STRING, - 'description' => 'Execution permissions.', + 'description' => 'Execution roles.', 'default' => '', - 'example' => 'any', + 'example' => ['any'], 'array' => true, ]) ->addRule('functionId', [ diff --git a/src/Appwrite/Utopia/Response/Model/File.php b/src/Appwrite/Utopia/Response/Model/File.php index 7a2c636370..b4f6b515d7 100644 --- a/src/Appwrite/Utopia/Response/Model/File.php +++ b/src/Appwrite/Utopia/Response/Model/File.php @@ -38,7 +38,7 @@ class File extends Model 'type' => self::TYPE_STRING, 'description' => 'File permissions.', 'default' => [], - 'example' => Permission::read(Role::any()), + 'example' => ['read("any")'], 'array' => true, ]) ->addRule('name', [ diff --git a/tests/e2e/Scopes/ProjectConsole.php b/tests/e2e/Scopes/ProjectConsole.php index 56b717ce0d..bc8ce4c0cf 100644 --- a/tests/e2e/Scopes/ProjectConsole.php +++ b/tests/e2e/Scopes/ProjectConsole.php @@ -2,12 +2,14 @@ namespace Tests\E2E\Scopes; +use Utopia\Database\ID; + trait ProjectConsole { public function getProject(): array { return [ - '$id' => 'console', + '$id' => ID::custom('console'), 'name' => 'Appwrite', 'apiKey' => '', ]; diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index ad8e63add5..6d5837e3c9 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -3,6 +3,7 @@ namespace Tests\E2E\Scopes; use Tests\E2E\Client; +use Utopia\Database\ID; trait ProjectCustom { @@ -26,7 +27,7 @@ trait ProjectCustom 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', ], [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Demo Project Team', ]); $this->assertEquals(201, $team['headers']['status-code']); @@ -39,7 +40,7 @@ trait ProjectCustom 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', ], [ - 'projectId' => 'unique()', + 'projectId' => ID::unique(), 'name' => 'Demo Project', 'teamId' => $team['body']['$id'], 'description' => 'Demo Project Description', diff --git a/tests/e2e/Scopes/Scope.php b/tests/e2e/Scopes/Scope.php index a4d65636a6..bd6ef3d8aa 100644 --- a/tests/e2e/Scopes/Scope.php +++ b/tests/e2e/Scopes/Scope.php @@ -4,6 +4,7 @@ namespace Tests\E2E\Scopes; use Tests\E2E\Client; use PHPUnit\Framework\TestCase; +use Utopia\Database\ID; abstract class Scope extends TestCase { @@ -87,7 +88,7 @@ abstract class Scope extends TestCase 'content-type' => 'application/json', 'x-appwrite-project' => 'console', ], [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -107,7 +108,7 @@ abstract class Scope extends TestCase $session = $this->client->parseCookie((string)$session['headers']['set-cookie'])['a_session_console']; self::$root = [ - '$id' => $root['body']['$id'], + '$id' => ID::custom($root['body']['$id']), 'name' => $root['body']['name'], 'email' => $root['body']['email'], 'session' => $session, @@ -139,7 +140,7 @@ abstract class Scope extends TestCase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -159,7 +160,7 @@ abstract class Scope extends TestCase $session = $this->client->parseCookie((string)$session['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']]; self::$user[$this->getProject()['$id']] = [ - '$id' => $user['body']['$id'], + '$id' => ID::custom($user['body']['$id']), 'name' => $user['body']['name'], 'email' => $user['body']['email'], 'session' => $session, diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 283c76a34b..e38cc06629 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -3,6 +3,7 @@ namespace Tests\E2E\Services\Account; use Tests\E2E\Client; +use Utopia\Database\ID; trait AccountBase { @@ -20,7 +21,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -43,7 +44,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -56,7 +57,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => '', 'password' => '', ]); @@ -68,7 +69,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => '', ]); @@ -80,7 +81,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => '', 'password' => $password, ]); @@ -340,7 +341,7 @@ trait AccountBase $this->assertIsNumeric($response['body']['total']); $this->assertContains($response['body']['logs'][1]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); $this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP)); - $this->assertIsNumeric($response['body']['logs'][1]['time']); + $this->assertIsString($response['body']['logs'][1]['time']); $this->assertEquals('Windows', $response['body']['logs'][1]['osName']); $this->assertEquals('WIN', $response['body']['logs'][1]['osCode']); @@ -362,7 +363,7 @@ trait AccountBase $this->assertContains($response['body']['logs'][2]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); - $this->assertIsNumeric($response['body']['logs'][2]['time']); + $this->assertIsString($response['body']['logs'][2]['time']); $this->assertEquals('Windows', $response['body']['logs'][2]['osName']); $this->assertEquals('WIN', $response['body']['logs'][2]['osCode']); @@ -663,7 +664,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $data['email'], 'password' => $data['password'], 'name' => $data['name'], @@ -899,7 +900,7 @@ trait AccountBase 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'userId' => 'ewewe', + 'userId' => ID::custom('ewewe'), 'secret' => $verification, ]); @@ -1214,7 +1215,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'ewewe', + 'userId' => ID::custom('ewewe'), 'secret' => $recovery, 'password' => $newPassowrd, 'passwordAgain' => $newPassowrd, @@ -1263,7 +1264,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, // 'url' => 'http://localhost/magiclogin', ]); @@ -1301,7 +1302,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'url' => 'localhost/magiclogin', ]); @@ -1313,7 +1314,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'url' => 'http://remotehost/magiclogin', ]); @@ -1389,7 +1390,7 @@ trait AccountBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'ewewe', + 'userId' => ID::custom('ewewe'), 'secret' => $token, ]); diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 688bdb9df9..eb1d7f86de 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -8,6 +8,7 @@ use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; +use Utopia\Database\ID; use function sleep; class AccountCustomClientTest extends Scope @@ -70,7 +71,7 @@ class AccountCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -151,7 +152,7 @@ class AccountCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -230,7 +231,7 @@ class AccountCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -410,7 +411,7 @@ class AccountCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password ]); @@ -689,7 +690,7 @@ class AccountCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'number' => $number, ]); @@ -708,7 +709,7 @@ class AccountCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()' + 'userId' => ID::unique() ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -737,7 +738,7 @@ class AccountCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'ewewe', + 'userId' => ID::custom('ewewe'), 'secret' => $token, ]); @@ -963,7 +964,7 @@ class AccountCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'userId' => 'ewewe', + 'userId' => ID::custom('ewewe'), 'secret' => Mock::$defaultDigits, ]); diff --git a/tests/e2e/Services/Account/AccountCustomServerTest.php b/tests/e2e/Services/Account/AccountCustomServerTest.php index 3c5955f47b..85d140c829 100644 --- a/tests/e2e/Services/Account/AccountCustomServerTest.php +++ b/tests/e2e/Services/Account/AccountCustomServerTest.php @@ -6,6 +6,7 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; +use Utopia\Database\ID; class AccountCustomServerTest extends Scope { @@ -26,7 +27,7 @@ class AccountCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 9b512f0155..84cf1c614e 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -4,6 +4,9 @@ namespace Tests\E2E\Services\Databases; use Tests\E2E\Client; use Utopia\Database\Database; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; trait DatabasesBase { @@ -17,7 +20,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ], [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'Test Database' ]); @@ -42,7 +45,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Movies', 'permissions' => [ Permission::read(Role::any()), @@ -86,14 +89,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Captain America', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ], ]); @@ -225,7 +228,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Response Models', 'permissions' => [], 'documentSecurity' => true, @@ -782,7 +785,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Captain America', 'releaseYear' => 1944, @@ -792,9 +795,9 @@ trait DatabasesBase ] ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -802,7 +805,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Spider-Man: Far From Home', 'releaseYear' => 2019, @@ -813,9 +816,9 @@ trait DatabasesBase ] ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -823,7 +826,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Spider-Man: Homecoming', 'releaseYear' => 2017, @@ -834,9 +837,9 @@ trait DatabasesBase ], ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -844,14 +847,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'releaseYear' => 2020, // Missing title, expect an 400 error ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -942,7 +945,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ], [ - 'databaseId' => 'default', + 'databaseId' => ID::custom('default'), 'name' => 'Default' ]); @@ -958,7 +961,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Movies', 'permissions' => [], 'documentSecurity' => true, @@ -1420,7 +1423,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Thor: Ragnaroc', 'releaseYear' => 2017, @@ -1428,9 +1431,9 @@ trait DatabasesBase '$createdAt' => 5 // Should be ignored ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ], ]); @@ -1491,16 +1494,16 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Thor: Ragnarok', 'releaseYear' => 2017, 'actors' => [], ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1539,7 +1542,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'InvalidDocumentDatabase', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -1551,7 +1554,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'invalidDocumentStructure', 'permissions' => [ Permission::create(Role::any()), @@ -1687,7 +1690,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'attributeId' => 'defaultRequired', + 'attributeId' => ID::custom('defaultRequired'), 'required' => true, 'default' => 12 ]); @@ -1697,7 +1700,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'attributeId' => 'enumDefault', + 'attributeId' => ID::custom('enumDefault'), 'elements' => ['north', 'west'], 'default' => 'south' ]); @@ -1707,7 +1710,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'attributeId' => 'enumDefault', + 'attributeId' => ID::custom('enumDefault'), 'elements' => ['north', 'west'], 'default' => 'NORTH' ]); @@ -1748,14 +1751,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'email' => 'user@example.com', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1763,14 +1766,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'enum' => 'yes', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1778,14 +1781,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'ip' => '1.1.1.1', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1793,14 +1796,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'url' => 'http://www.example.com', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1808,14 +1811,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'range' => 3, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1823,14 +1826,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'floatRange' => 1.4, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1838,14 +1841,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'probability' => 0.99999, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1853,14 +1856,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'upperBound' => 8, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1868,14 +1871,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'lowerBound' => 8, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1897,14 +1900,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'email' => 'user@@example.com', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1912,14 +1915,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'enum' => 'badEnum', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1927,14 +1930,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'ip' => '1.1.1.1.1', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1942,14 +1945,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'url' => 'example...com', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1957,14 +1960,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'range' => 11, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1972,14 +1975,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'floatRange' => 2.5, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -1987,14 +1990,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'probability' => 1.1, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -2002,14 +2005,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'upperBound' => 11, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -2017,14 +2020,14 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'lowerBound' => 3, ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -2058,7 +2061,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Captain America', 'releaseYear' => 1944, @@ -2156,7 +2159,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'EnforceCollectionPermissions', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -2169,7 +2172,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'enforceCollectionPermissions', 'documentSecurity' => true, 'permissions' => [ @@ -2224,7 +2227,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'attribute' => 'one', ], @@ -2241,7 +2244,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'attribute' => 'one', ], @@ -2258,13 +2261,13 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ], [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'attribute' => 'one', ], 'permissions' => [ - Permission::read(Role::user('other')), - Permission::update(Role::user('other')), + Permission::read(Role::user(ID::custom('other'))), + Permission::update(Role::user(ID::custom('other'))), ], ]); @@ -2301,7 +2304,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], [ - 'userId' => 'other', + 'userId' => ID::custom('other'), 'email' => $email, 'password' => $password, 'name' => $name, @@ -2370,7 +2373,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Captain America', 'releaseYear' => 1944, @@ -2380,9 +2383,9 @@ trait DatabasesBase ] ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -2393,7 +2396,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Captain America 5', 'releaseYear' => 1944, @@ -2403,9 +2406,9 @@ trait DatabasesBase ] ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -2416,7 +2419,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Captain America', 'releaseYear' => 1944, @@ -2426,9 +2429,9 @@ trait DatabasesBase ] ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -2452,7 +2455,7 @@ trait DatabasesBase ]; $document = $this->client->call(Client::METHOD_POST, '/databases/' . $data['databaseId'] . '/collections/' . $data['moviesId'] . '/documents', $headers, [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Creation Date Test', 'releaseYear' => 2000 @@ -2506,7 +2509,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'Empty Permissions', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -2519,13 +2522,13 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Movies', 'permissions' => [ - Permission::create(Role::user($this->getUser()['$id'])), - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::create(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ], 'documentSecurity' => true, ]); @@ -2556,7 +2559,7 @@ trait DatabasesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Captain America', ], @@ -2581,7 +2584,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -2594,8 +2597,8 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ], ]); diff --git a/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php b/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php index 15332d8cc0..71fa7a590f 100644 --- a/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php +++ b/tests/e2e/Services/Databases/DatabasesConsoleClientTest.php @@ -6,6 +6,9 @@ use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Client; use Tests\E2E\Scopes\SideConsole; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class DatabasesConsoleClientTest extends Scope { @@ -19,7 +22,7 @@ class DatabasesConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'invalidDocumentDatabase', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -33,7 +36,7 @@ class DatabasesConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Movies', 'permissions' => [ Permission::read(Role::any()), diff --git a/tests/e2e/Services/Databases/DatabasesCustomClientTest.php b/tests/e2e/Services/Databases/DatabasesCustomClientTest.php index b9f42d6311..1d7ed8bf2b 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomClientTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomClientTest.php @@ -6,6 +6,9 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class DatabasesCustomClientTest extends Scope { @@ -32,7 +35,7 @@ class DatabasesCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'permissionCheckDatabase', + 'databaseId' => ID::custom('permissionCheckDatabase'), 'name' => 'Test Database', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -45,7 +48,7 @@ class DatabasesCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'permissionCheck', + 'collectionId' => ID::custom('permissionCheck'), 'name' => 'permissionCheck', 'permissions' => [], 'documentSecurity' => true, @@ -73,15 +76,15 @@ class DatabasesCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'documentId' => 'permissionCheckDocument', + 'documentId' => ID::custom('permissionCheckDocument'), 'data' => [ 'name' => 'AppwriteBeginner', ], 'permissions' => [ - Permission::read(Role::user('user2')), - Permission::read(Role::user($userId)), - Permission::update(Role::user($userId)), - Permission::delete(Role::user($userId)), + Permission::read(Role::user(ID::custom('user2'))), + Permission::read(Role::user(ID::custom($userId))), + Permission::update(Role::user(ID::custom($userId))), + Permission::delete(Role::user(ID::custom($userId))), ], ]); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 0f075d9e22..73d89cac7b 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -7,6 +7,9 @@ use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; use Tests\E2E\Client; use Utopia\Database\Database; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class DatabasesCustomServerTest extends Scope { @@ -21,7 +24,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'first', + 'databaseId' => ID::custom('first'), 'name' => 'Test 1', ]); $this->assertEquals(201, $test1['headers']['status-code']); @@ -32,7 +35,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'second', + 'databaseId' => ID::custom('second'), 'name' => 'Test 2', ]); $this->assertEquals(201, $test2['headers']['status-code']); @@ -172,7 +175,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'name' => 'Test 1', - 'databaseId' => 'first', + 'databaseId' => ID::custom('first'), ]); $this->assertEquals(409, $response['headers']['status-code']); @@ -233,7 +236,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'invalidDocumentDatabase', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -249,7 +252,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'name' => 'Test 1', - 'collectionId' => 'first', + 'collectionId' => ID::custom('first'), 'permissions' => [ Permission::read(Role::any()), Permission::create(Role::any()), @@ -265,7 +268,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'name' => 'Test 2', - 'collectionId' => 'second', + 'collectionId' => ID::custom('second'), 'permissions' => [ Permission::read(Role::any()), Permission::create(Role::any()), @@ -409,7 +412,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'name' => 'Test 1', - 'collectionId' => 'first', + 'collectionId' => ID::custom('first'), 'permissions' => [ Permission::read(Role::any()), Permission::create(Role::any()), @@ -429,7 +432,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'invalidDocumentDatabase', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -446,7 +449,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Actors', 'permissions' => [ Permission::read(Role::any()), @@ -499,7 +502,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'firstName' => 'lorem', 'lastName' => 'ipsum', @@ -717,7 +720,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'invalidDocumentDatabase', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -729,7 +732,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'TestCleanupDuplicateIndexOnDeleteAttribute', 'permissions' => [ Permission::read(Role::any()), @@ -849,15 +852,15 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'firstName' => 'Tom', 'lastName' => 'Holland', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ], ]); @@ -865,15 +868,15 @@ class DatabasesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'firstName' => 'Samuel', 'lastName' => 'Jackson', ], 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ], ]); @@ -924,7 +927,7 @@ class DatabasesCustomServerTest extends Scope // 'x-appwrite-project' => $this->getProject()['$id'], // 'x-appwrite-key' => $this->getProject()['apiKey'] // ]), [ - // 'collectionId' => 'unique()', + // 'collectionId' => ID::unique(), // 'name' => 'attributeCountLimit', // 'read' => ['any'], // 'write' => ['any'], @@ -969,7 +972,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'invalidDocumentDatabase', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -981,7 +984,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'attributeRowWidthLimit', + 'collectionId' => ID::custom('attributeRowWidthLimit'), 'name' => 'attributeRowWidthLimit', 'permissions' => [ Permission::read(Role::any()), @@ -1035,7 +1038,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'invalidDocumentDatabase', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -1047,7 +1050,7 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'testLimitException', + 'collectionId' => ID::custom('testLimitException'), 'name' => 'testLimitException', 'permissions' => [ Permission::read(Role::any()), diff --git a/tests/e2e/Services/Databases/DatabasesPermissionsGuestTest.php b/tests/e2e/Services/Databases/DatabasesPermissionsGuestTest.php index 788a248fee..e3a568c574 100644 --- a/tests/e2e/Services/Databases/DatabasesPermissionsGuestTest.php +++ b/tests/e2e/Services/Databases/DatabasesPermissionsGuestTest.php @@ -6,6 +6,9 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class DatabasesPermissionsGuestTest extends Scope { @@ -20,7 +23,7 @@ class DatabasesPermissionsGuestTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'InvalidDocumentDatabase', ]); $this->assertEquals(201, $database['headers']['status-code']); @@ -28,7 +31,7 @@ class DatabasesPermissionsGuestTest extends Scope $databaseId = $database['body']['$id']; $movies = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', $this->getServerHeader(), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Movies', 'permissions' => [ Permission::read(Role::any()), @@ -76,7 +79,7 @@ class DatabasesPermissionsGuestTest extends Scope $collectionId = $data['collectionId']; $databaseId = $data['databaseId']; $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', $this->getServerHeader(), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Lorem', ], diff --git a/tests/e2e/Services/Databases/DatabasesPermissionsMemberTest.php b/tests/e2e/Services/Databases/DatabasesPermissionsMemberTest.php index 188d49bee5..de819a6f16 100644 --- a/tests/e2e/Services/Databases/DatabasesPermissionsMemberTest.php +++ b/tests/e2e/Services/Databases/DatabasesPermissionsMemberTest.php @@ -6,6 +6,7 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; +use Utopia\Database\ID; use Utopia\Database\Permission; use Utopia\Database\Role; @@ -30,10 +31,10 @@ class DatabasesPermissionsMemberTest extends Scope return [ [[Permission::read(Role::any())]], [[Permission::read(Role::users())]], - [[Permission::read(Role::user('random'))]], - [[Permission::read(Role::user('lorem')), Permission::update(Role::user('lorem')), Permission::delete(Role::user('lorem'))]], - [[Permission::read(Role::user('dolor')), Permission::update(Role::user('dolor')), Permission::delete(Role::user('dolor'))]], - [[Permission::read(Role::user('dolor')), Permission::read(Role::user('lorem')), Permission::update(Role::user('dolor')), Permission::delete(Role::user('dolor'))]], + [[Permission::read(Role::user(ID::custom('random')))]], + [[Permission::read(Role::user(ID::custom('lorem'))), Permission::update(Role::user('lorem')), Permission::delete(Role::user('lorem'))]], + [[Permission::read(Role::user(ID::custom('dolor'))), Permission::update(Role::user('dolor')), Permission::delete(Role::user('dolor'))]], + [[Permission::read(Role::user(ID::custom('dolor'))), Permission::read(Role::user('lorem')), Permission::update(Role::user('dolor')), Permission::delete(Role::user('dolor'))]], [[Permission::update(Role::any()), Permission::delete(Role::any())]], [[Permission::read(Role::any()), Permission::update(Role::any()), Permission::delete(Role::any())]], [[Permission::read(Role::users()), Permission::update(Role::users()), Permission::delete(Role::users())]], @@ -54,7 +55,7 @@ class DatabasesPermissionsMemberTest extends Scope $this->createUsers(); $db = $this->client->call(Client::METHOD_POST, '/databases', $this->getServerHeader(), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'Test Database', ]); $this->assertEquals(201, $db['headers']['status-code']); @@ -62,7 +63,7 @@ class DatabasesPermissionsMemberTest extends Scope $databaseId = $db['body']['$id']; $public = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', $this->getServerHeader(), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Movies', 'permissions' => [ Permission::read(Role::any()), @@ -84,7 +85,7 @@ class DatabasesPermissionsMemberTest extends Scope $this->assertEquals(202, $response['headers']['status-code']); $private = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', $this->getServerHeader(), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Private Movies', 'permissions' => [ Permission::read(Role::users()), @@ -126,7 +127,7 @@ class DatabasesPermissionsMemberTest extends Scope $databaseId = $data['databaseId']; $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collections['public'] . '/documents', $this->getServerHeader(), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Lorem', ], @@ -135,7 +136,7 @@ class DatabasesPermissionsMemberTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collections['private'] . '/documents', $this->getServerHeader(), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Lorem', ], diff --git a/tests/e2e/Services/Databases/DatabasesPermissionsTeamTest.php b/tests/e2e/Services/Databases/DatabasesPermissionsTeamTest.php index f1c47cf22d..8c3a2b1422 100644 --- a/tests/e2e/Services/Databases/DatabasesPermissionsTeamTest.php +++ b/tests/e2e/Services/Databases/DatabasesPermissionsTeamTest.php @@ -6,6 +6,9 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class DatabasesPermissionsTeamTest extends Scope { @@ -42,13 +45,13 @@ class DatabasesPermissionsTeamTest extends Scope $this->assertEquals(201, $db['headers']['status-code']); $collection1 = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/collections', $this->getServerHeader(), [ - 'collectionId' => 'collection1', + 'collectionId' => ID::custom('collection1'), 'name' => 'Collection 1', 'permissions' => [ - Permission::read(Role::team($teams['team1']['$id'])), - Permission::create(Role::team($teams['team1']['$id'], 'admin')), - Permission::update(Role::team($teams['team1']['$id'], 'admin')), - Permission::delete(Role::team($teams['team1']['$id'], 'admin')), + Permission::read(Role::team(ID::custom($teams['team1']['$id']))), + Permission::create(Role::team(ID::custom($teams['team1']['$id']), 'admin')), + Permission::update(Role::team(ID::custom($teams['team1']['$id']), 'admin')), + Permission::delete(Role::team(ID::custom($teams['team1']['$id']), 'admin')), ], ]); @@ -61,13 +64,13 @@ class DatabasesPermissionsTeamTest extends Scope ]); $collection2 = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/collections', $this->getServerHeader(), [ - 'collectionId' => 'collection2', + 'collectionId' => ID::custom('collection2'), 'name' => 'Collection 2', 'permissions' => [ - Permission::read(Role::team($teams['team2']['$id'])), - Permission::create(Role::team($teams['team2']['$id'], 'owner')), - Permission::update(Role::team($teams['team2']['$id'], 'owner')), - Permission::delete(Role::team($teams['team2']['$id'], 'owner')), + Permission::read(Role::team(ID::custom($teams['team2']['$id']))), + Permission::create(Role::team(ID::custom($teams['team2']['$id']), 'owner')), + Permission::update(Role::team(ID::custom($teams['team2']['$id']), 'owner')), + Permission::delete(Role::team(ID::custom($teams['team2']['$id']), 'owner')), ] ]); @@ -138,7 +141,7 @@ class DatabasesPermissionsTeamTest extends Scope $this->createCollections($this->teams); $response = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/collections/' . $this->collections['collection1'] . '/documents', $this->getServerHeader(), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Lorem', ], @@ -146,7 +149,7 @@ class DatabasesPermissionsTeamTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/collections/' . $this->collections['collection2'] . '/documents', $this->getServerHeader(), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Ipsum', ], @@ -189,7 +192,7 @@ class DatabasesPermissionsTeamTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $users[$user]['session'], ], [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'title' => 'Ipsum', ], diff --git a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php index 084923ac3e..93e59c5112 100644 --- a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php @@ -6,6 +6,7 @@ use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Client; use Tests\E2E\Scopes\SideConsole; +use Utopia\Database\ID; class FunctionsConsoleClientTest extends Scope { @@ -18,7 +19,7 @@ class FunctionsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => ["user:{$this->getUser()['$id']}"], 'runtime' => 'php-8.0', @@ -41,7 +42,7 @@ class FunctionsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test Failure', 'execute' => ['some-random-string'], 'runtime' => 'php-8.0' diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 7626c1917b..26e0e666fc 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -9,6 +9,7 @@ use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideClient; use Utopia\CLI\Console; use Utopia\Database\Database; +use Utopia\Database\ID; class FunctionsCustomClientTest extends Scope { @@ -25,7 +26,7 @@ class FunctionsCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'vars' => [ 'funcKey1' => 'funcValue1', @@ -55,7 +56,7 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => ["user:{$this->getUser()['$id']}"], 'runtime' => 'php-8.0', @@ -145,7 +146,7 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, ], [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => ['any'], 'runtime' => 'php-8.0', @@ -236,7 +237,7 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [], 'runtime' => 'php-8.0', @@ -330,7 +331,7 @@ class FunctionsCustomClientTest extends Scope 'x-appwrite-project' => $projectId, 'x-appwrite-key' => $apikey, ], [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => ['any'], 'runtime' => 'php-8.0', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 1d0a42b536..d95c779592 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -9,6 +9,7 @@ use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; use Utopia\CLI\Console; use Utopia\Database\Database; +use Utopia\Database\ID; class FunctionsCustomServerTest extends Scope { @@ -25,7 +26,7 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'runtime' => 'php-8.0', 'vars' => [ @@ -123,7 +124,7 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test 2', 'runtime' => 'php-8.0', 'vars' => [ @@ -711,7 +712,7 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test ' . $name, 'runtime' => $name, 'vars' => [], @@ -796,7 +797,7 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test ' . $name, 'runtime' => $name, 'vars' => [], @@ -905,7 +906,7 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test ' . $name, 'runtime' => $name, 'vars' => [ @@ -1010,7 +1011,7 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test ' . $name, 'runtime' => $name, 'vars' => [ @@ -1115,7 +1116,7 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test ' . $name, 'runtime' => $name, 'vars' => [ @@ -1220,7 +1221,7 @@ class FunctionsCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test ' . $name, 'runtime' => $name, 'vars' => [ @@ -1325,7 +1326,7 @@ class FunctionsCustomServerTest extends Scope // 'content-type' => 'application/json', // 'x-appwrite-project' => $this->getProject()['$id'], // ], $this->getHeaders()), [ - // 'functionId' => 'unique()', + // 'functionId' => ID::unique(), // 'name' => 'Test '.$name, // 'runtime' => $name, // 'vars' => [ diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 81c33c5e35..23d699d436 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -8,6 +8,7 @@ use Tests\E2E\Scopes\SideClient; use Tests\E2E\Services\Projects\ProjectsBase; use Tests\E2E\Client; use Utopia\Database\Database; +use Utopia\Database\ID; class ProjectsConsoleClientTest extends Scope { @@ -24,7 +25,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Project Test', ]); @@ -36,7 +37,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'projectId' => 'unique()', + 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], ]); @@ -58,7 +59,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'projectId' => 'unique()', + 'projectId' => ID::unique(), 'name' => '', 'teamId' => $team['body']['$id'], ]); @@ -69,7 +70,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'projectId' => 'unique()', + 'projectId' => ID::unique(), 'name' => 'Project Test', ]); @@ -135,7 +136,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Project Test 2', ]); @@ -147,7 +148,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'projectId' => 'unique()', + 'projectId' => ID::unique(), 'name' => 'Project Test 2', 'teamId' => $team['body']['$id'], ]); @@ -314,7 +315,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'projectId' => 'unique()', + 'projectId' => ID::unique(), 'name' => 'Project Test 2', ]); @@ -335,7 +336,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'projectId' => 'unique()', + 'projectId' => ID::unique(), 'name' => '', ]); @@ -393,7 +394,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'provider' => 'unknown', - 'appId' => 'AppId', + 'appId' => ID::custom('AppId'), 'secret' => 'Secret', ]); @@ -419,7 +420,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $originalEmail, 'password' => $originalPassword, 'name' => $originalName, @@ -472,7 +473,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -485,7 +486,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'cookie' => 'a_session_' . $id . '=' . $session, ]), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Arsenal' ]); @@ -579,7 +580,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -605,7 +606,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -623,7 +624,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Project Test', ]); $this->assertEquals(201, $team['headers']['status-code']); @@ -634,7 +635,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ - 'projectId' => 'unique()', + 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], ]); @@ -767,7 +768,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, ]), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Arsenal' ]); @@ -857,7 +858,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-key' => $keySecret, ]), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Arsenal' ]); diff --git a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php index 9ba7649fbb..efcfe95f53 100644 --- a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php @@ -6,6 +6,9 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideConsole; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class RealtimeConsoleClientTest extends Scope { @@ -145,7 +148,7 @@ class RealtimeConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'Actors DB', ]); @@ -157,7 +160,7 @@ class RealtimeConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Actors', 'permissions' => [ Permission::read(Role::any()), diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 805044b9f6..ed81e843d8 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -8,6 +8,9 @@ use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; use Utopia\CLI\Console; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; use WebSocket\ConnectionException; class RealtimeCustomClientTest extends Scope @@ -628,7 +631,7 @@ class RealtimeCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'Actors DB', ]); @@ -642,7 +645,7 @@ class RealtimeCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Actors', 'permissions' => [ Permission::read(Role::users()), @@ -680,7 +683,7 @@ class RealtimeCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'name' => 'Chris Evans' ], @@ -726,7 +729,7 @@ class RealtimeCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'name' => 'Chris Evans 2' ], @@ -771,7 +774,7 @@ class RealtimeCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'name' => 'Bradley Cooper' ], @@ -851,7 +854,7 @@ class RealtimeCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'Actors DB', ]); @@ -865,7 +868,7 @@ class RealtimeCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Actors', 'permissions' => [ Permission::read(Role::any()), @@ -902,7 +905,7 @@ class RealtimeCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'name' => 'Chris Evans' ], @@ -984,7 +987,7 @@ class RealtimeCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'name' => 'Bradley Cooper' ], @@ -1058,7 +1061,7 @@ class RealtimeCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Bucket 1', 'permissions' => [ Permission::read(Role::any()), @@ -1077,7 +1080,7 @@ class RealtimeCustomClientTest extends Scope 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), 'permissions' => [ Permission::read(Role::any()), @@ -1215,7 +1218,7 @@ class RealtimeCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ], [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => ['users'], 'runtime' => 'php-8.0', @@ -1358,7 +1361,7 @@ class RealtimeCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Arsenal' ]); diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 4b517d5918..682ab3b4f5 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -4,6 +4,9 @@ namespace Tests\E2E\Services\Storage; use CURLFile; use Tests\E2E\Client; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; trait StorageBase { @@ -17,7 +20,7 @@ trait StorageBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket', 'fileSecurity' => true, 'maximumFileSize' => 2000000, //2MB @@ -38,7 +41,7 @@ trait StorageBase 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), 'permissions' => [ Permission::read(Role::any()), @@ -64,7 +67,7 @@ trait StorageBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket 2', 'fileSecurity' => true, 'permissions' => [ @@ -163,7 +166,7 @@ trait StorageBase 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), 'permissions' => [ Permission::read(Role::any()), @@ -181,7 +184,7 @@ trait StorageBase 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/disk-b/kitten-1.png'), 'image/png', 'kitten-1.png'), 'permissions' => [ Permission::read(Role::any()), @@ -201,7 +204,7 @@ trait StorageBase 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/disk-a/kitten-3.gif'), 'image/gif', 'kitten-3.gif'), 'permissions' => [ Permission::read(Role::any()), @@ -221,7 +224,7 @@ trait StorageBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket 2', 'fileSecurity' => true, 'maximumFileSize' => 200000000, //200MB @@ -476,7 +479,7 @@ trait StorageBase 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'testcache', + 'fileId' => ID::custom('testcache'), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), 'permissions' => [ Permission::read(Role::any()), @@ -522,7 +525,7 @@ trait StorageBase 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'testcache', + 'fileId' => ID::custom('testcache'), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/disk-b/kitten-2.png'), 'image/png', 'logo.png'), 'permissions' => [ Permission::read(Role::any()), @@ -571,9 +574,9 @@ trait StorageBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); @@ -601,9 +604,9 @@ trait StorageBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - Permission::update(Role::user($this->getUser()['$id'])), - Permission::delete(Role::user($this->getUser()['$id'])), + Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::update(Role::user(ID::custom($this->getUser()['$id']))), + Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] ]); diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php index c13c28f925..5a79aaac36 100644 --- a/tests/e2e/Services/Storage/StorageConsoleClientTest.php +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -51,7 +51,7 @@ class StorageConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket', 'permission' => 'file' ]); diff --git a/tests/e2e/Services/Storage/StorageCustomClientTest.php b/tests/e2e/Services/Storage/StorageCustomClientTest.php index 12d9ae7efd..ea3cfd883b 100644 --- a/tests/e2e/Services/Storage/StorageCustomClientTest.php +++ b/tests/e2e/Services/Storage/StorageCustomClientTest.php @@ -10,6 +10,9 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class StorageCustomClientTest extends Scope { @@ -27,7 +30,7 @@ class StorageCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket', 'permissions' => [ Permission::read(Role::any()), @@ -45,7 +48,7 @@ class StorageCustomClientTest extends Scope 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'), ]); @@ -92,7 +95,7 @@ class StorageCustomClientTest extends Scope 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'), ]); @@ -120,7 +123,7 @@ class StorageCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket', 'fileSecurity' => true, 'permissions' => [ @@ -137,7 +140,7 @@ class StorageCustomClientTest extends Scope 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'), ]); @@ -166,11 +169,11 @@ class StorageCustomClientTest extends Scope 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'), - 'folderId' => 'xyz', + 'folderId' => ID::custom('xyz'), 'permissions' => [ - Permission::read(Role::user('notme')), + Permission::read(Role::user(ID::custom('notme'))), ], ]); @@ -184,12 +187,12 @@ class StorageCustomClientTest extends Scope 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'), - 'folderId' => 'xyz', + 'folderId' => ID::custom('xyz'), 'permissions' => [ - Permission::update(Role::user('notme')), - Permission::delete(Role::user('notme')), + Permission::update(Role::user(ID::custom('notme'))), + Permission::delete(Role::user(ID::custom('notme'))), ] ]); @@ -203,13 +206,13 @@ class StorageCustomClientTest extends Scope 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'), - 'folderId' => 'xyz', + 'folderId' => ID::custom('xyz'), 'permissions' => [ - Permission::read(Role::user('notme')), - Permission::update(Role::user('notme')), - Permission::delete(Role::user('notme')), + Permission::read(Role::user(ID::custom('notme'))), + Permission::update(Role::user(ID::custom('notme'))), + Permission::delete(Role::user(ID::custom('notme'))), ], ]); @@ -233,7 +236,7 @@ class StorageCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::read(Role::user('notme')), + Permission::read(Role::user(ID::custom('notme'))), ], ]); @@ -248,8 +251,8 @@ class StorageCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::update(Role::user('notme')), - Permission::delete(Role::user('notme')), + Permission::update(Role::user(ID::custom('notme'))), + Permission::delete(Role::user(ID::custom('notme'))), ] ]); @@ -264,10 +267,10 @@ class StorageCustomClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::read(Role::user('notme')), - Permission::create(Role::user('notme')), - Permission::update(Role::user('notme')), - Permission::delete(Role::user('notme')), + Permission::read(Role::user(ID::custom('notme'))), + Permission::create(Role::user(ID::custom('notme'))), + Permission::update(Role::user(ID::custom('notme'))), + Permission::delete(Role::user(ID::custom('notme'))), ], ]); diff --git a/tests/e2e/Services/Storage/StorageCustomServerTest.php b/tests/e2e/Services/Storage/StorageCustomServerTest.php index 09bb5caed7..26bfff4921 100644 --- a/tests/e2e/Services/Storage/StorageCustomServerTest.php +++ b/tests/e2e/Services/Storage/StorageCustomServerTest.php @@ -6,6 +6,7 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; +use Utopia\Database\ID; class StorageCustomServerTest extends Scope { @@ -22,7 +23,7 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket', 'fileSecurity' => true, ]); @@ -44,7 +45,7 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'bucketId' => 'bucket1', + 'bucketId' => ID::custom('bucket1'), 'name' => 'Test Bucket', 'fileSecurity' => true, ]); @@ -58,7 +59,7 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => '', 'fileSecurity' => true, ]); @@ -179,7 +180,7 @@ class StorageCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket Updated', 'enabled' => false, 'fileSecurity' => true, diff --git a/tests/e2e/Services/Teams/TeamsBase.php b/tests/e2e/Services/Teams/TeamsBase.php index e626124058..f8868bfbb1 100644 --- a/tests/e2e/Services/Teams/TeamsBase.php +++ b/tests/e2e/Services/Teams/TeamsBase.php @@ -4,6 +4,7 @@ namespace Tests\E2E\Services\Teams; use Tests\E2E\Client; use Utopia\Database\Database; +use Utopia\Database\ID; trait TeamsBase { @@ -16,7 +17,7 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Arsenal' ]); @@ -35,7 +36,7 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => $teamId, + 'teamId' => ID::custom($teamId), 'name' => 'Manchester United' ]); @@ -51,7 +52,7 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Newcastle' ]); @@ -251,7 +252,7 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Demo' ]); @@ -266,7 +267,7 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Demo New' ]); @@ -300,7 +301,7 @@ trait TeamsBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Demo' ]); diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 08e2ddc8c8..c17e9d4c76 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -238,7 +238,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => $secret, - 'userId' => $userUid, + 'userId' => ID::custom($userUid), ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -318,7 +318,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => 'sdasdasd', - 'userId' => $userUid, + 'userId' => ID::custom($userUid), ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -329,7 +329,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => '', - 'userId' => $userUid, + 'userId' => ID::custom($userUid), ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -340,7 +340,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => $secret, - 'userId' => 'sdasd', + 'userId' => ID::custom('sdasd'), ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -351,7 +351,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => $secret, - 'userId' => '', + 'userId' => ID::custom(''), ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -362,7 +362,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => $secret, - 'userId' => $userUid, + 'userId' => ID::custom($userUid), ]); $this->assertEquals(409, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php index 970a9e88a0..7018ac0aff 100644 --- a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php +++ b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php @@ -24,7 +24,7 @@ class TeamsConsoleClientTest extends Scope 'x-appwrite-project' => 'console' ], $this->getHeaders()), [ 'name' => 'Latest version Team', - 'teamId' => 'unique()' + 'teamId' => ID::unique() ]); $this->assertEquals(201, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index f7c0abd113..e4f40dba86 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -4,6 +4,7 @@ namespace Tests\E2E\Services\Users; use Tests\E2E\Client; use Utopia\Database\Database; +use Utopia\Database\ID; trait UsersBase { @@ -16,7 +17,7 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => 'cristiano.ronaldo@manchester-united.co.uk', 'password' => 'password', 'name' => 'Cristiano Ronaldo', @@ -42,7 +43,7 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'userId' => 'user1', + 'userId' => ID::custom('user1'), 'email' => 'lionel.messi@psg.fr', 'password' => 'password', 'name' => 'Lionel Messi', diff --git a/tests/e2e/Services/Webhooks/WebhooksBase.php b/tests/e2e/Services/Webhooks/WebhooksBase.php index 2d139805c3..b1079a17fd 100644 --- a/tests/e2e/Services/Webhooks/WebhooksBase.php +++ b/tests/e2e/Services/Webhooks/WebhooksBase.php @@ -4,6 +4,9 @@ namespace Tests\E2E\Services\Webhooks; use CURLFile; use Tests\E2E\Client; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; trait WebhooksBase { @@ -25,7 +28,7 @@ trait WebhooksBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'Actors DB', ]); @@ -39,7 +42,7 @@ trait WebhooksBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Actors', 'permissions' => [ Permission::read(Role::any()), @@ -189,7 +192,7 @@ trait WebhooksBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'firstName' => 'Chris', 'lastName' => 'Evans', @@ -312,7 +315,7 @@ trait WebhooksBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'documentId' => 'unique()', + 'documentId' => ID::unique(), 'data' => [ 'firstName' => 'Bradly', 'lastName' => 'Cooper', @@ -377,7 +380,7 @@ trait WebhooksBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'bucketId' => 'unique()', + 'bucketId' => ID::unique(), 'name' => 'Test Bucket', 'permissions' => [ Permission::read(Role::any()), @@ -485,14 +488,14 @@ trait WebhooksBase 'content-type' => 'multipart/form-data', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'fileId' => 'unique()', + 'fileId' => ID::unique(), 'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'), 'permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'folderId' => 'xyz', + 'folderId' => ID::custom('xyz'), ]); $fileId = $file['body']['$id']; @@ -687,7 +690,7 @@ trait WebhooksBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Arsenal' ]); @@ -776,7 +779,7 @@ trait WebhooksBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => 'unique()', + 'teamId' => ID::unique(), 'name' => 'Chelsea' ]); diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php index 6ddc148b82..06ba74432c 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php @@ -6,6 +6,7 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\SideClient; +use Utopia\Database\ID; class WebhooksCustomClientTest extends Scope { @@ -27,7 +28,7 @@ class WebhooksCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -85,7 +86,7 @@ class WebhooksCustomClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index f4b21548f7..32559ec32f 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -8,6 +8,9 @@ use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; use Utopia\CLI\Console; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class WebhooksCustomServerTest extends Scope { @@ -141,7 +144,7 @@ class WebhooksCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ], $this->getHeaders()), [ - 'databaseId' => 'unique()', + 'databaseId' => ID::unique(), 'name' => 'Actors DB', ]); @@ -155,7 +158,7 @@ class WebhooksCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ - 'collectionId' => 'unique()', + 'collectionId' => ID::unique(), 'name' => 'Demo', 'permissions' => [ Permission::read(Role::any()), @@ -214,7 +217,7 @@ class WebhooksCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'userId' => 'unique()', + 'userId' => ID::unique(), 'email' => $email, 'password' => $password, 'name' => $name, @@ -392,7 +395,7 @@ class WebhooksCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'functionId' => 'unique()', + 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => ['any'], 'runtime' => 'php-8.0', diff --git a/tests/unit/Auth/AuthTest.php b/tests/unit/Auth/AuthTest.php index 7830cf84fc..731af9d241 100644 --- a/tests/unit/Auth/AuthTest.php +++ b/tests/unit/Auth/AuthTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit\Auth; use Appwrite\Auth\Auth; use Utopia\Database\Document; +use Utopia\Database\ID; use Utopia\Database\Validator\Authorization; use PHPUnit\Framework\TestCase; @@ -70,14 +71,14 @@ class AuthTest extends TestCase $hash = Auth::hash($secret); $tokens1 = [ new Document([ - '$id' => 'token1', + '$id' => ID::custom('token1'), 'expire' => time() + 60 * 60 * 24, 'secret' => $hash, 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => 'test@example.com', ]), new Document([ - '$id' => 'token2', + '$id' => ID::custom('token2'), 'expire' => time() - 60 * 60 * 24, 'secret' => 'secret2', 'provider' => Auth::SESSION_PROVIDER_EMAIL, @@ -87,14 +88,14 @@ class AuthTest extends TestCase $tokens2 = [ new Document([ // Correct secret and type time, wrong expire time - '$id' => 'token1', + '$id' => ID::custom('token1'), 'expire' => time() - 60 * 60 * 24, 'secret' => $hash, 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => 'test@example.com', ]), new Document([ - '$id' => 'token2', + '$id' => ID::custom('token2'), 'expire' => time() - 60 * 60 * 24, 'secret' => 'secret2', 'provider' => Auth::SESSION_PROVIDER_EMAIL, @@ -114,13 +115,13 @@ class AuthTest extends TestCase $hash = Auth::hash($secret); $tokens1 = [ new Document([ - '$id' => 'token1', + '$id' => ID::custom('token1'), 'type' => Auth::TOKEN_TYPE_RECOVERY, 'expire' => time() + 60 * 60 * 24, 'secret' => $hash, ]), new Document([ - '$id' => 'token2', + '$id' => ID::custom('token2'), 'type' => Auth::TOKEN_TYPE_RECOVERY, 'expire' => time() - 60 * 60 * 24, 'secret' => 'secret2', @@ -129,13 +130,13 @@ class AuthTest extends TestCase $tokens2 = [ new Document([ // Correct secret and type time, wrong expire time - '$id' => 'token1', + '$id' => ID::custom('token1'), 'type' => Auth::TOKEN_TYPE_RECOVERY, 'expire' => time() - 60 * 60 * 24, 'secret' => $hash, ]), new Document([ - '$id' => 'token2', + '$id' => ID::custom('token2'), 'type' => Auth::TOKEN_TYPE_RECOVERY, 'expire' => time() - 60 * 60 * 24, 'secret' => 'secret2', @@ -144,13 +145,13 @@ class AuthTest extends TestCase $tokens3 = [ // Correct secret and expire time, wrong type new Document([ - '$id' => 'token1', + '$id' => ID::custom('token1'), 'type' => Auth::TOKEN_TYPE_INVITE, 'expire' => time() + 60 * 60 * 24, 'secret' => $hash, ]), new Document([ - '$id' => 'token2', + '$id' => ID::custom('token2'), 'type' => Auth::TOKEN_TYPE_RECOVERY, 'expire' => time() - 60 * 60 * 24, 'secret' => 'secret2', @@ -213,17 +214,17 @@ class AuthTest extends TestCase public function testUserRoles(): void { $user = new Document([ - '$id' => '123', + '$id' => ID::custom('123'), 'memberships' => [ [ - 'teamId' => 'abc', + 'teamId' => ID::custom('abc'), 'roles' => [ 'administrator', 'moderator' ] ], [ - 'teamId' => 'def', + 'teamId' => ID::custom('def'), 'roles' => [ 'guest' ] @@ -247,17 +248,17 @@ class AuthTest extends TestCase { Authorization::setRole(Auth::USER_ROLE_OWNER); $user = new Document([ - '$id' => '123', + '$id' => ID::custom('123'), 'memberships' => [ [ - 'teamId' => 'abc', + 'teamId' => ID::custom('abc'), 'roles' => [ 'administrator', 'moderator' ] ], [ - 'teamId' => 'def', + 'teamId' => ID::custom('def'), 'roles' => [ 'guest' ] @@ -281,17 +282,17 @@ class AuthTest extends TestCase { Authorization::setRole(Auth::USER_ROLE_APP); $user = new Document([ - '$id' => '123', + '$id' => ID::custom('123'), 'memberships' => [ [ - 'teamId' => 'abc', + 'teamId' => ID::custom('abc'), 'roles' => [ 'administrator', 'moderator' ] ], [ - 'teamId' => 'def', + 'teamId' => ID::custom('def'), 'roles' => [ 'guest' ] diff --git a/tests/unit/Messaging/MessagingChannelsTest.php b/tests/unit/Messaging/MessagingChannelsTest.php index 1b68e6d6a2..336f972b83 100644 --- a/tests/unit/Messaging/MessagingChannelsTest.php +++ b/tests/unit/Messaging/MessagingChannelsTest.php @@ -6,6 +6,7 @@ use Appwrite\Auth\Auth; use Utopia\Database\Document; use Appwrite\Messaging\Adapter\Realtime; use PHPUnit\Framework\TestCase; +use Utopia\Database\ID; class MessagingChannelsTest extends TestCase { @@ -49,10 +50,10 @@ class MessagingChannelsTest extends TestCase for ($i = 0; $i < $this->connectionsPerChannel; $i++) { foreach ($this->allChannels as $index => $channel) { $user = new Document([ - '$id' => 'user' . $this->connectionsCount, + '$id' => ID::custom('user' . $this->connectionsCount), 'memberships' => [ [ - 'teamId' => 'team' . $i, + 'teamId' => ID::custom('team' . $i), 'roles' => [ empty($index % 2) ? 'admin' : 'member' ] diff --git a/tests/unit/Messaging/MessagingTest.php b/tests/unit/Messaging/MessagingTest.php index 63786e81b3..34eb1ef08a 100644 --- a/tests/unit/Messaging/MessagingTest.php +++ b/tests/unit/Messaging/MessagingTest.php @@ -5,6 +5,9 @@ namespace Tests\Unit\Messaging; use Utopia\Database\Document; use Appwrite\Messaging\Adapter\Realtime; use PHPUnit\Framework\TestCase; +use Utopia\Database\ID; +use Utopia\Database\Permission; +use Utopia\Database\Role; class MessagingTest extends TestCase { @@ -160,17 +163,17 @@ class MessagingTest extends TestCase public function testConvertChannelsUser(): void { $user = new Document([ - '$id' => '123', + '$id' => ID::custom('123'), 'memberships' => [ [ - 'teamId' => 'abc', + 'teamId' => ID::custom('abc'), 'roles' => [ 'administrator', 'moderator' ] ], [ - 'teamId' => 'def', + 'teamId' => ID::custom('def'), 'roles' => [ 'guest' ] @@ -204,8 +207,8 @@ class MessagingTest extends TestCase $result = Realtime::fromPayload( event: 'databases.database_id.collections.collection_id.documents.document_id.create', payload: new Document([ - '$id' => 'test', - '$collection' => 'collection', + '$id' => ID::custom('test'), + '$collection' => ID::custom('collection'), '$permissions' => [ 'read(admin)', 'update(admin)', @@ -213,10 +216,10 @@ class MessagingTest extends TestCase ], ]), database: new Document([ - '$id' => 'database', + '$id' => ID::custom('database'), ]), collection: new Document([ - '$id' => 'collection', + '$id' => ID::custom('collection'), '$permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), @@ -234,8 +237,8 @@ class MessagingTest extends TestCase $result = Realtime::fromPayload( event: 'databases.database_id.collections.collection_id.documents.document_id.create', payload: new Document([ - '$id' => 'test', - '$collection' => 'collection', + '$id' => ID::custom('test'), + '$collection' => ID::custom('collection'), '$permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), @@ -243,10 +246,10 @@ class MessagingTest extends TestCase ], ]), database: new Document([ - '$id' => 'database', + '$id' => ID::custom('database'), ]), collection: new Document([ - '$id' => 'collection', + '$id' => ID::custom('collection'), '$permissions' => [ 'read(admin)', 'update(admin)', @@ -268,8 +271,8 @@ class MessagingTest extends TestCase $result = Realtime::fromPayload( event: 'buckets.bucket_id.files.file_id.create', payload: new Document([ - '$id' => 'test', - '$collection' => 'bucket', + '$id' => ID::custom('test'), + '$collection' => ID::custom('bucket'), '$permissions' => [ 'read(admin)', 'update(admin)', @@ -277,7 +280,7 @@ class MessagingTest extends TestCase ], ]), bucket: new Document([ - '$id' => 'bucket', + '$id' => ID::custom('bucket'), '$permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), @@ -295,8 +298,8 @@ class MessagingTest extends TestCase $result = Realtime::fromPayload( event: 'buckets.bucket_id.files.file_id.create', payload: new Document([ - '$id' => 'test', - '$collection' => 'bucket', + '$id' => ID::custom('test'), + '$collection' => ID::custom('bucket'), '$permissions' => [ Permission::read(Role::any()), Permission::update(Role::any()), @@ -304,7 +307,7 @@ class MessagingTest extends TestCase ], ]), bucket: new Document([ - '$id' => 'bucket', + '$id' => ID::custom('bucket'), '$permissions' => [ 'read(admin)', 'update(admin)', diff --git a/tests/unit/Migration/MigrationV12Test.php b/tests/unit/Migration/MigrationV12Test.php index 2a0a0512a2..5b88ae7f5d 100644 --- a/tests/unit/Migration/MigrationV12Test.php +++ b/tests/unit/Migration/MigrationV12Test.php @@ -5,6 +5,7 @@ namespace Tests\Unit\Migration; use ReflectionClass; use Appwrite\Migration\Version\V12; use Utopia\Database\Document; +use Utopia\Database\ID; class MigrationV12Test extends MigrationTest { @@ -19,8 +20,8 @@ class MigrationV12Test extends MigrationTest public function testMigrationProjects(): void { $document = $this->fixDocument(new Document([ - '$id' => 'project', - '$collection' => 'projects', + '$id' => ID::custom('project'), + '$collection' => ID::custom('projects'), 'name' => 'Appwrite', 'version' => '0.12.0', 'search' => '' @@ -33,8 +34,8 @@ class MigrationV12Test extends MigrationTest public function testMigrationUsers(): void { $document = $this->fixDocument(new Document([ - '$id' => 'user', - '$collection' => 'users', + '$id' => ID::custom('user'), + '$collection' => ID::custom('users'), 'email' => 'test@appwrite.io', 'name' => 'Torsten Dittmann' ])); @@ -45,8 +46,8 @@ class MigrationV12Test extends MigrationTest public function testMigrationTeams(): void { $document = $this->fixDocument(new Document([ - '$id' => 'team', - '$collection' => 'teams', + '$id' => ID::custom('team'), + '$collection' => ID::custom('teams'), 'name' => 'Appwrite' ])); @@ -56,8 +57,8 @@ class MigrationV12Test extends MigrationTest public function testMigrationFunctions(): void { $document = $this->fixDocument(new Document([ - '$id' => 'function', - '$collection' => 'functions', + '$id' => ID::custom('function'), + '$collection' => ID::custom('functions'), 'name' => 'My Function', 'runtime' => 'php-8.0' ])); @@ -68,9 +69,9 @@ class MigrationV12Test extends MigrationTest public function testMigrationExecutions(): void { $document = $this->fixDocument(new Document([ - '$id' => 'execution', - '$collection' => 'executions', - 'functionId' => 'function' + '$id' => ID::custom('execution'), + '$collection' => ID::custom('executions'), + 'functionId' => ID::custom('function') ])); $this->assertEquals($document->getAttribute('search'), 'execution function'); diff --git a/tests/unit/Migration/MigrationV13Test.php b/tests/unit/Migration/MigrationV13Test.php index 954aea71cf..a0daaf309d 100644 --- a/tests/unit/Migration/MigrationV13Test.php +++ b/tests/unit/Migration/MigrationV13Test.php @@ -5,6 +5,7 @@ namespace Tests\Unit\Migration; use ReflectionClass; use Appwrite\Migration\Version\V13; use Utopia\Database\Document; +use Utopia\Database\ID; class MigrationV13Test extends MigrationTest { @@ -19,8 +20,8 @@ class MigrationV13Test extends MigrationTest public function testMigrateFunctions(): void { $document = $this->fixDocument(new Document([ - '$id' => 'func', - '$collection' => 'functions', + '$id' => ID::custom('func'), + '$collection' => ID::custom('functions'), 'events' => ['account.create', 'users.create'] ])); @@ -30,8 +31,8 @@ class MigrationV13Test extends MigrationTest public function testMigrationWebhooks(): void { $document = $this->fixDocument(new Document([ - '$id' => 'webh', - '$collection' => 'webhooks', + '$id' => ID::custom('webh'), + '$collection' => ID::custom('webhooks'), 'events' => ['account.create', 'users.create'] ])); diff --git a/tests/unit/Migration/MigrationV14Test.php b/tests/unit/Migration/MigrationV14Test.php index 1010a2c873..0ca249069b 100644 --- a/tests/unit/Migration/MigrationV14Test.php +++ b/tests/unit/Migration/MigrationV14Test.php @@ -5,6 +5,7 @@ namespace Tests\Unit\Migration; use ReflectionClass; use Appwrite\Migration\Version\V14; use Utopia\Database\Document; +use Utopia\Database\ID; class MigrationV14Test extends MigrationTest { @@ -19,8 +20,8 @@ class MigrationV14Test extends MigrationTest public function testMigrateProjects(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'projects', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('projects'), 'version' => '0.14.0' ])); @@ -31,7 +32,7 @@ class MigrationV14Test extends MigrationTest public function testMigrateKeys(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', + '$id' => ID::custom('appwrite'), '$collection' => 'keys' ])); @@ -42,7 +43,7 @@ class MigrationV14Test extends MigrationTest public function testMigrateWebhooks(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', + '$id' => ID::custom('appwrite'), '$collection' => 'webhooks' ])); @@ -53,8 +54,8 @@ class MigrationV14Test extends MigrationTest public function testMigrateUsers(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'users', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('users'), 'phoneVerification' => null ])); @@ -65,8 +66,8 @@ class MigrationV14Test extends MigrationTest public function testMigratePlatforms(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'platforms', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('platforms'), '$createdAt' => null, '$updatedAt' => null, 'dateCreated' => 123456789, @@ -80,8 +81,8 @@ class MigrationV14Test extends MigrationTest public function testMigrateFunctions(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'functions', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('functions'), '$createdAt' => null, '$updatedAt' => null, 'dateCreated' => 123456789, @@ -95,8 +96,8 @@ class MigrationV14Test extends MigrationTest public function testMigrateDeployments(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'deployments', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('deployments'), '$createdAt' => null, 'dateCreated' => 123456789, ])); @@ -107,8 +108,8 @@ class MigrationV14Test extends MigrationTest public function testMigrateExecutions(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'executions', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('executions'), '$createdAt' => null, 'dateCreated' => 123456789, ])); @@ -119,8 +120,8 @@ class MigrationV14Test extends MigrationTest public function testMigrateTeams(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'teams', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('teams'), '$createdAt' => null, 'dateCreated' => 123456789, ])); @@ -131,8 +132,8 @@ class MigrationV14Test extends MigrationTest public function testMigrateAudits(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'audit', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('audit'), 'resource' => 'collection/movies', 'event' => 'collections.movies.create' ])); @@ -141,8 +142,8 @@ class MigrationV14Test extends MigrationTest $this->assertEquals($document->getAttribute('event'), 'databases.default.collections.movies.create'); $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'audit', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('audit'), 'resource' => 'document/avatar', 'event' => 'collections.movies.documents.avatar.create' ])); @@ -154,16 +155,16 @@ class MigrationV14Test extends MigrationTest public function testMigrateStats(): void { $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'stats', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('stats'), 'metric' => 'database.collections.62b2039844d4277495d0.documents.create' ])); $this->assertEquals($document->getAttribute('metric'), 'databases.default.collections.62b2039844d4277495d0.documents.create'); $document = $this->fixDocument(new Document([ - '$id' => 'appwrite', - '$collection' => 'stats', + '$id' => ID::custom('appwrite'), + '$collection' => ID::custom('stats'), 'metric' => 'users.create' ])); diff --git a/tests/unit/Network/Validators/OriginTest.php b/tests/unit/Network/Validators/OriginTest.php index 50dc0ad10a..2392ae4cfa 100644 --- a/tests/unit/Network/Validators/OriginTest.php +++ b/tests/unit/Network/Validators/OriginTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit\Network\Validators; use Appwrite\Network\Validator\Origin; use PHPUnit\Framework\TestCase; +use Utopia\Database\ID; class OriginTest extends TestCase { @@ -11,19 +12,19 @@ class OriginTest extends TestCase { $validator = new Origin([ [ - '$collection' => 'platforms', + '$collection' => ID::custom('platforms'), 'name' => 'Production', 'type' => 'web', 'hostname' => 'appwrite.io', ], [ - '$collection' => 'platforms', + '$collection' => ID::custom('platforms'), 'name' => 'Development', 'type' => 'web', 'hostname' => 'appwrite.test', ], [ - '$collection' => 'platforms', + '$collection' => ID::custom('platforms'), 'name' => 'Localhost', 'type' => 'web', 'hostname' => 'localhost',