diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 8097592e19..9a92bfb5cc 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -175,7 +175,10 @@ class Base extends Action $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); $domain = ID::unique() . "." . $sitesDomain; - $ruleId = md5($domain); + + // TODO: @christyjacob remove once we migrate the rules in 1.7.x + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain) : ID::unique(); + Authorization::skip( fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 53556f60ba..33f2468f43 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -732,7 +732,7 @@ class Builds extends Action $rule = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [ Query::equal("projectInternalId", [$project->getInternalId()]), Query::equal("type", ["deployment"]), - Query::equal("value", [$deployment->getId()]) + Query::equal('deploymentInternalId', [$deployment->getInternalId()]), ])); if ($rule->isEmpty()) { @@ -841,9 +841,15 @@ class Builds extends Action $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); $this->listRules($project, [ - Query::equal("automation", ["function=" . $resource->getId()]), + Query::equal("projectInternalId", [$project->getInternalId()]), + Query::equal("type", ["deployment"]), + Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), + Query::equal('deploymentResourceType', ['function']), + Query::equal("deploymentUpdatePolicy", ['active']), ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule->setAttribute('value', $deployment->getId()); + $rule = $rule + ->setAttribute('deploymentId', $deployment->getId()) + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); break; @@ -852,37 +858,41 @@ class Builds extends Action $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); $this->listRules($project, [ - Query::equal("automation", ["site=" . $resource->getId()]), + Query::equal("projectInternalId", [$project->getInternalId()]), + Query::equal("type", ["deployment"]), + Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), + Query::equal('deploymentResourceType', ['site']), + Query::equal("deploymentUpdatePolicy", ['active']), ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule->setAttribute('value', $deployment->getId()); + $rule = $rule + ->setAttribute('deploymentId', $deployment->getId()) + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); }); - // VCS branch - $branchName = $deployment->getAttribute('providerBranch'); - if (!empty($branchName)) { - $this->listRules($project, [ - Query::equal("automation", ["branch=" . $branchName]), - ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule->setAttribute('value', $deployment->getId()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); - }); - } - - // VCS commit - $commitHash = $deployment->getAttribute('providerCommitHash', ''); - if (!empty($commitHash)) { - $this->listRules($project, [ - Query::equal("automation", ["commit=" . $commitHash]), - ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule->setAttribute('value', $deployment->getId()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); - }); - } break; } } + if ($resource->getCollection() === 'sites') { + // VCS branch + $branchName = $deployment->getAttribute('providerBranch'); + if (!empty($branchName)) { + $this->listRules($project, [ + Query::equal("projectInternalId", [$project->getInternalId()]), + Query::equal("type", ["deployment"]), + Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]), + Query::equal('deploymentResourceType', ['site']), + Query::equal("deploymentUpdatePolicy", ['branch']), + Query::equal("_key_deploymentVcsProviderBranch", [$branchName]), + ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { + $rule = $rule + ->setAttribute('deploymentId', $deployment->getId()) + ->setAttribute('deploymentInternalId', $deployment->getInternalId()); + $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + }); + } + } if ($dbForProject->getDocument('builds', $buildId)->getAttribute('status') === 'canceled') { Console::info('Build has been canceled'); @@ -1151,7 +1161,7 @@ class Builds extends Action $rule = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [ Query::equal("projectInternalId", [$project->getInternalId()]), Query::equal("type", ["deployment"]), - Query::equal("value", [$deployment->getId()]) + Query::equal("deploymentInternalId", [$deployment->getInternalId()]), ])); $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php index 7b24a4377a..c4e0b1226f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php @@ -230,7 +230,10 @@ class Create extends Action $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); $domain = ID::unique() . "." . $sitesDomain; - $ruleId = md5($domain); + + // TODO: @christyjacob remove once we migrate the rules in 1.7.x + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain) : ID::unique(); + Authorization::skip( fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php index 512d1b6e5c..27c2358b83 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php @@ -106,7 +106,10 @@ class Create extends Action // Preview deployments for sites $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); $domain = ID::unique() . "." . $sitesDomain; - $ruleId = md5($domain); + + // TODO: @christyjacob remove once we migrate the rules in 1.7.x + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain) : ID::unique(); + Authorization::skip( fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php index 528df58c5f..d434e1565f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php @@ -142,7 +142,10 @@ class Create extends Base $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); $domain = ID::unique() . "." . $sitesDomain; - $ruleId = md5($domain); + + // TODO: @christyjacob remove once we migrate the rules in 1.7.x + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain) : ID::unique(); + Authorization::skip( fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index 9f0a5903f3..760013e827 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -308,7 +308,8 @@ trait FunctionsBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::equal('automation', ['function=' . $functionId])->toString(), + Query::equal('deploymentResourceId', [$functionId])->toString(), + Query::equal('deploymentUpdatePolicy', ['active'])->toString(), Query::equal('type', ['deployment'])->toString(), ], ]); diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index a7e0293409..7758cce5bc 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -343,7 +343,8 @@ trait SitesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::equal('automation', ['site=' . $siteId])->toString(), + Query::equal('deploymentResourceId', [$siteId])->toString(), + Query::equal('deploymentUpdatePolicy', ['active'])->toString(), Query::equal('type', ['deployment'])->toString(), ], ]); @@ -365,9 +366,9 @@ trait SitesBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::equal('value', [$deploymentId])->toString(), + Query::equal('deploymentId', [$deploymentId])->toString(), Query::equal('type', ['deployment'])->toString(), - Query::equal('automation', [''])->toString(), + Query::equal('deploymentUpdatePolicy', [''])->toString(), ], ]); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index c9adc3a116..d307cf6a74 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -116,7 +116,7 @@ class SitesCustomServerTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::equal('automation', ['site=' . $siteId]) + Query::equal('deploymentResourceId', [$siteId]) ] ]);