mirror of
https://github.com/appwrite/appwrite
synced 2026-05-21 16:08:22 +00:00
WIP: Add new console endpoint
This commit is contained in:
parent
2ad0428727
commit
d95cdc3296
2 changed files with 37 additions and 7 deletions
|
|
@ -3,9 +3,13 @@
|
|||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\App;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\System\System;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\WhiteList;
|
||||
|
||||
App::init()
|
||||
->groups(['console'])
|
||||
|
|
@ -109,3 +113,32 @@ App::post('/v1/console/assistant')
|
|||
|
||||
$response->chunk('', true);
|
||||
});
|
||||
|
||||
App::get('v1/console/resources')
|
||||
->desc('Check resource availability')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
|
||||
->label('sdk.namespace', 'console')
|
||||
->label('sdk.method', 'resources')
|
||||
->label('sdk.description', '/docs/references/console/resources.md') //TODO: add this file
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_NONE)
|
||||
->param('type', '', new WhiteList(['rules']), 'Resource type.')
|
||||
->param('id', '', new UID(), 'ID of the resource.')
|
||||
->inject('response')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $type, string $id, Response $response, Database $dbForConsole) {
|
||||
if ($type !== 'rules') {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Invalid resource type.');
|
||||
}
|
||||
|
||||
$document = Authorization::skip(fn () => $dbForConsole->getDocument('rules', $id));
|
||||
|
||||
if ($document && !$document->isEmpty()) {
|
||||
throw new Exception(Exception::RULE_ALREADY_EXISTS, 'Subdomain already assigned to different resource.');
|
||||
}
|
||||
|
||||
$response->noContent();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use Utopia\Database\Document;
|
|||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
use Utopia\Database\Helpers\Role;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
|
|
@ -46,7 +45,7 @@ class CreateSite extends Base
|
|||
->setHttpPath('/v1/sites')
|
||||
->desc('Create site')
|
||||
->groups(['api', 'sites'])
|
||||
->label('scope', 'sites.write')
|
||||
->label('scope', 'functions.write')
|
||||
->label('event', 'sites.[siteId].create')
|
||||
->label('audits.event', 'site.create')
|
||||
->label('audits.resource', 'site/{response.$id}')
|
||||
|
|
@ -103,15 +102,13 @@ class CreateSite extends Base
|
|||
$domain = '';
|
||||
|
||||
if (!empty($sitesDomain)) {
|
||||
$ruleId = ID::unique();
|
||||
$routeSubdomain = $subdomain ?: ID::unique();
|
||||
$domain = "{$routeSubdomain}.{$sitesDomain}";
|
||||
$ruleId = md5($domain);
|
||||
|
||||
$subdomain = Authorization::skip(fn () => $dbForConsole->findOne('rules', [
|
||||
Query::equal('domain', [$domain])
|
||||
]));
|
||||
$subdomain = Authorization::skip(fn () => $dbForConsole->getDocument('rules', $ruleId));
|
||||
|
||||
if (!empty($subdomain)) {
|
||||
if ($subdomain && !$subdomain->isEmpty()) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Subdomain already exists. Please choose a different subdomain.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue