mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
feat: use getDocument instead of find() for rules
This commit is contained in:
@@ -326,9 +326,9 @@ App::post('/v1/functions')
|
||||
|
||||
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
|
||||
if (!empty($functionsDomain)) {
|
||||
$ruleId = ID::unique();
|
||||
$routeSubdomain = ID::unique();
|
||||
$domain = "{$routeSubdomain}.{$functionsDomain}";
|
||||
$ruleId = md5($domain);
|
||||
|
||||
$rule = Authorization::skip(
|
||||
fn () => $dbForConsole->createDocument('rules', new Document([
|
||||
|
||||
@@ -103,7 +103,7 @@ App::post('/v1/proxy/rules')
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Domain may not start with http:// or https://.');
|
||||
}
|
||||
|
||||
$ruleId = ID::unique();
|
||||
$ruleId = md5($domain->get());
|
||||
$rule = new Document([
|
||||
'$id' => $ruleId,
|
||||
'projectId' => $project->getId(),
|
||||
|
||||
@@ -52,14 +52,10 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
||||
|
||||
$host = $request->getHostname() ?? '';
|
||||
|
||||
$route = Authorization::skip(
|
||||
fn () => $dbForConsole->find('rules', [
|
||||
Query::equal('domain', [$host]),
|
||||
Query::limit(1)
|
||||
])
|
||||
)[0] ?? null;
|
||||
$ruleId = md5($host);
|
||||
$route = Authorization::skip(fn () => $dbForConsole->getDocument('rules', $ruleId));
|
||||
|
||||
if ($route === null) {
|
||||
if ($route->isEmpty()) {
|
||||
if ($host === System::getEnv('_APP_DOMAIN_FUNCTIONS', '')) {
|
||||
throw new AppwriteException(AppwriteException::GENERAL_ACCESS_FORBIDDEN, 'This domain cannot be used for security reasons. Please use any subdomain instead.');
|
||||
}
|
||||
@@ -531,6 +527,7 @@ App::init()
|
||||
|
||||
if ($domainDocument->isEmpty()) {
|
||||
$domainDocument = new Document([
|
||||
'$id' => md5($domain->get()),
|
||||
'domain' => $domain->get(),
|
||||
'resourceType' => 'api',
|
||||
'status' => 'verifying',
|
||||
|
||||
@@ -72,6 +72,7 @@ class V19 extends Migration
|
||||
}
|
||||
|
||||
$ruleDocument = new Document([
|
||||
'$id' => md5($domain->getAttribute('domain')),
|
||||
'projectId' => $domain->getAttribute('projectId'),
|
||||
'projectInternalId' => $domain->getAttribute('projectInternalId'),
|
||||
'domain' => $domain->getAttribute('domain'),
|
||||
|
||||
@@ -478,9 +478,7 @@ class Certificates extends Action
|
||||
private function updateDomainDocuments(string $certificateId, string $domain, bool $success, Database $dbForConsole, Event $queueForEvents, Func $queueForFunctions): void
|
||||
{
|
||||
|
||||
$rule = $dbForConsole->findOne('rules', [
|
||||
Query::equal('domain', [$domain]),
|
||||
]);
|
||||
$rule = $dbForConsole->getDocument('rules', md5($domain));
|
||||
|
||||
if (!$rule->isEmpty()) {
|
||||
$rule->setAttribute('certificateId', $certificateId);
|
||||
|
||||
Reference in New Issue
Block a user