diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 28694a0b10..e13bca73ef 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1,6 +1,7 @@ label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PROJECT) + ->param('projectId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') ->param('teamId', '', new UID(), 'Team unique ID.') ->param('description', '', new Text(256), 'Project description. Max length: 256 chars.', true) @@ -49,7 +51,7 @@ App::post('/v1/projects') ->inject('dbForInternal') ->inject('dbForExternal') ->inject('consoleDB') - ->action(function ($name, $teamId, $description, $logo, $url, $legalName, $legalCountry, $legalState, $legalCity, $legalAddress, $legalTaxId, $response, $dbForConsole, $dbForInternal, $dbForExternal, $consoleDB) { + ->action(function ($projectId, $name, $teamId, $description, $logo, $url, $legalName, $legalCountry, $legalState, $legalCity, $legalAddress, $legalTaxId, $response, $dbForConsole, $dbForInternal, $dbForExternal, $consoleDB) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForConsole */ /** @var Utopia\Database\Database $dbForInternal */ @@ -63,6 +65,7 @@ App::post('/v1/projects') } $project = $dbForConsole->createDocument('projects', new Document([ + '$id' => $projectId == 'unique()' ? $dbForConsole->getId() : $projectId, '$collection' => 'projects', '$read' => ['team:' . $teamId], '$write' => ['team:' . $teamId . '/owner', 'team:' . $teamId . '/developer'], @@ -602,6 +605,7 @@ App::post('/v1/projects/:projectId/webhooks') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_WEBHOOK) + ->param('webhookId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Webhook name. Max length: 128 chars.') ->param('events', null, new ArrayList(new WhiteList(array_keys(Config::getParam('events'), true), true)), 'Events list.') @@ -611,7 +615,7 @@ App::post('/v1/projects/:projectId/webhooks') ->param('httpPass', '', new Text(256), 'Webhook HTTP password. Max length: 256 chars.', true) ->inject('response') ->inject('dbForConsole') - ->action(function ($projectId, $name, $events, $url, $security, $httpUser, $httpPass, $response, $dbForConsole) { + ->action(function ($webhookId, $projectId, $name, $events, $url, $security, $httpUser, $httpPass, $response, $dbForConsole) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForConsole */ @@ -624,7 +628,7 @@ App::post('/v1/projects/:projectId/webhooks') $security = ($security === '1' || $security === 'true' || $security === 1 || $security === true); $webhook = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => $webhookId == 'unique()' ? $dbForConsole->getId() : $webhookId, 'name' => $name, 'events' => $events, 'url' => $url, @@ -801,12 +805,13 @@ App::post('/v1/projects/:projectId/keys') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_KEY) + ->param('keyId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', null, new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true)), 'Key scopes list.') ->inject('response') ->inject('dbForConsole') - ->action(function ($projectId, $name, $scopes, $response, $dbForConsole) { + ->action(function ($keyId, $projectId, $name, $scopes, $response, $dbForConsole) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForConsole */ @@ -817,7 +822,7 @@ App::post('/v1/projects/:projectId/keys') } $key = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => $keyId == 'unique()' ? $dbForConsole->getId() : $keyId, 'name' => $name, 'scopes' => $scopes, 'secret' => \bin2hex(\random_bytes(128)), @@ -978,6 +983,7 @@ App::post('/v1/projects/:projectId/tasks') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_TASK) + ->param('taskId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Task name. Max length: 128 chars.') ->param('status', null, new WhiteList(['play', 'pause'], true), 'Task status.') @@ -990,7 +996,7 @@ App::post('/v1/projects/:projectId/tasks') ->param('httpPass', '', new Text(256), 'Task HTTP password. Max length: 256 chars.', true) ->inject('response') ->inject('dbForConsole') - ->action(function ($projectId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass, $response, $dbForConsole) { + ->action(function ($taskId, $projectId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass, $response, $dbForConsole) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForConsole */ @@ -1005,7 +1011,7 @@ App::post('/v1/projects/:projectId/tasks') $security = ($security === '1' || $security === 'true' || $security === 1 || $security === true); $task = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => $taskId == 'unique()' ? $dbForConsole->getId() : $taskId, 'projectId' => $project->getId(), 'name' => $name, 'status' => $status, @@ -1210,6 +1216,7 @@ App::post('/v1/projects/:projectId/platforms') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_PLATFORM) + ->param('platformId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('type', null, new WhiteList(['web', 'flutter-ios', 'flutter-android', 'flutter-linux', 'flutter-macos', 'flutter-windows', 'ios', 'android', 'unity'], true), 'Platform type.') ->param('name', null, new Text(128), 'Platform name. Max length: 128 chars.') @@ -1218,7 +1225,7 @@ App::post('/v1/projects/:projectId/platforms') ->param('hostname', '', new Text(256), 'Platform client hostname. Max length: 256 chars.', true) ->inject('response') ->inject('dbForConsole') - ->action(function ($projectId, $type, $name, $key, $store, $hostname, $response, $dbForConsole) { + ->action(function ($platformId, $projectId, $type, $name, $key, $store, $hostname, $response, $dbForConsole) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForConsole */ @@ -1229,7 +1236,7 @@ App::post('/v1/projects/:projectId/platforms') } $platform = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => $platformId == 'unique()' ? $dbForConsole->getId() : $platformId, 'type' => $type, 'name' => $name, 'key' => $key, @@ -1410,11 +1417,12 @@ App::post('/v1/projects/:projectId/domains') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_DOMAIN) + ->param('domainId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('domain', null, new DomainValidator(), 'Domain name.') ->inject('response') ->inject('dbForConsole') - ->action(function ($projectId, $domain, $response, $dbForConsole) { + ->action(function ($domainId, $projectId, $domain, $response, $dbForConsole) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForConsole */ @@ -1439,7 +1447,7 @@ App::post('/v1/projects/:projectId/domains') $domain = new Domain($domain); $domain = new Document([ - '$id' => $dbForConsole->getId(), + '$id' => $domainId == 'unique()' ? $dbForConsole->getId() : $domainId, 'updated' => \time(), 'domain' => $domain->get(), 'tld' => $domain->getSuffix(),