Skip to content

Feat: Enhance rules #9395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rule search param fix
  • Loading branch information
Meldiron committed Feb 25, 2025
commit 2ba84bf93f95c4abf11f5146259a4f497c93d70e
20 changes: 19 additions & 1 deletion app/config/collections/platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,27 @@
'default' => null,
'array' => false,
'filters' => [],
]
],
[
'$id' => ID::custom('search'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => 16384,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
],
'indexes' => [
[
'$id' => ID::custom('_key_search'),
'type' => Database::INDEX_FULLTEXT,
'attributes' => ['search'],
'lengths' => [],
'orders' => [],
],
[
'$id' => ID::custom('_key_domain'),
'type' => Database::INDEX_UNIQUE,
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/api/vcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
'value' => $deployment->getId(),
'status' => 'verified',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
]))
);

Expand All @@ -268,6 +269,7 @@
'automation' => 'branch=' . $providerBranch,
'status' => 'verified',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
]))
);
} catch (Duplicate $err) {
Expand All @@ -291,6 +293,7 @@
'automation' => 'commit=' . $providerCommitHash,
'status' => 'verified',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
]))
);
} catch (Duplicate $err) {
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,16 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw
}

if ($domainDocument->isEmpty()) {
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
$domainDocument = new Document([
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
'$id' => System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique(),
'$id' => $ruleId,
'domain' => $domain->get(),
'resourceType' => 'api',
'status' => 'verifying',
'projectId' => 'console',
'projectInternalId' => 'console'
'projectInternalId' => 'console',
'search' => implode(' ', [$ruleId, $domain->get()]),
]);

$domainDocument = $dbForPlatform->createDocument('rules', $domainDocument);
Expand Down
1 change: 1 addition & 0 deletions src/Appwrite/Platform/Modules/Compute/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function redeployVcsSite(Request $request, Document $site, Document $proj
'value' => $deployment->getId(),
'status' => 'verified',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
]))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function action(string $domain, Response $response, Document $project, Ce
'type' => 'api',
'value' => '',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain->get()]),
]);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public function action(string $domain, string $functionId, Response $response, D
'type' => 'deployment',
'value' => $function->getAttribute('deployment', ''),
'certificateId' => '',
'automation' => 'function=' . $function->getId()
'automation' => 'function=' . $function->getId(),
'search' => implode(' ', [$ruleId, $domain->get()]),
]);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function action(string $domain, string $target, Response $response, Docum
'type' => 'redirect',
'value' => $target->get(),
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain->get()]),
]);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public function action(string $domain, string $siteId, string $branch, Response
'type' => 'deployment',
'value' => $site->getAttribute('deploymentId', ''),
'certificateId' => '',
'automation' => !empty($branch) ? ('branch=' . $branch) : ('site=' . $site->getId())
'automation' => !empty($branch) ? ('branch=' . $branch) : ('site=' . $site->getId()),
'search' => implode(' ', [$ruleId, $domain->get()]),
]);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function action(string $siteId, string $deploymentId, Response $response,
'value' => $deployment->getId(),
'status' => 'verified',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
]))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public function action(string $siteId, ?string $installCommand, ?string $buildCo
'value' => $deployment->getId(),
'status' => 'verified',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
]))
);
} else {
Expand Down Expand Up @@ -291,6 +292,7 @@ public function action(string $siteId, ?string $installCommand, ?string $buildCo
'value' => $deployment->getId(),
'status' => 'verified',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
]))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function action(string $siteId, string $repository, string $owner, string
'value' => $deployment->getId(),
'status' => 'verified',
'certificateId' => '',
'search' => implode(' ', [$ruleId, $domain]),
]))
);

Expand Down
46 changes: 45 additions & 1 deletion tests/e2e/Services/Proxy/ProxyCustomServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ public function testListRules()
$this->assertCount(2, $rules['body']['rules']);
$this->assertEquals($rule2Id, $rules['body']['rules'][0]['$id']);


$rules = $this->listRules([
'queries' => [
Query::equal('domain', [$rule2Domain])->toString()
Expand All @@ -324,5 +323,50 @@ public function testListRules()
$this->assertEquals(200, $rules['headers']['status-code']);
$this->assertCount(1, $rules['body']['rules']);
$this->assertEquals($rule2Id, $rules['body']['rules'][0]['$id']);

$rules = $this->listRules([
'search' => $rule1Domain,
'queries' => [ Query::orderDesc('$createdAt') ]
]);

$this->assertEquals(200, $rules['headers']['status-code']);
$ruleIds = \array_column($rules['body']['rules'], '$id');
$this->assertContains($rule1Id, $ruleIds);

$rules = $this->listRules([
'search' => $rule2Domain,
'queries' => [ Query::orderDesc('$createdAt') ]
]);
$this->assertEquals(200, $rules['headers']['status-code']);
$ruleIds = \array_column($rules['body']['rules'], '$id');
$this->assertContains($rule2Id, $ruleIds);

$rules = $this->listRules([
'search' => $rule1Id,
'queries' => [ Query::orderDesc('$createdAt') ]
]);
$this->assertEquals(200, $rules['headers']['status-code']);
$ruleDomains = \array_column($rules['body']['rules'], 'domain');
$this->assertContains($rule1Domain, $ruleDomains);

$rules = $this->listRules([
'search' => $rule2Id,
'queries' => [ Query::orderDesc('$createdAt') ]
]);
$this->assertEquals(200, $rules['headers']['status-code']);
$ruleDomains = \array_column($rules['body']['rules'], 'domain');
$this->assertContains($rule2Domain, $ruleDomains);

$rules = $this->listRules();
$this->assertEquals(200, $rules['headers']['status-code']);
foreach ($rules['body']['rules'] as $rule) {
$rule = $this->deleteRule($rule['$id']);
$this->assertEquals(204, $rule['headers']['status-code']);
}

$rules = $this->listRules();
$this->assertEquals(200, $rules['headers']['status-code']);
$this->assertEquals(0, $rules['body']['total']);
$this->assertCount(0, $rules['body']['rules']);
}
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy