Merge remote-tracking branch 'origin/refactor-auth-single-instance' into refactor-auth-single-instance

This commit is contained in:
shimon 2025-11-27 11:54:36 +02:00
commit b76f01b144
13 changed files with 8958 additions and 22 deletions

View file

@ -854,7 +854,7 @@ App::get('/v1/cards/cloud')
$email = $user->getAttribute('email', ''); $email = $user->getAttribute('email', '');
$createdAt = new \DateTime($user->getCreatedAt()); $createdAt = new \DateTime($user->getCreatedAt());
$gitHub = $getUserGitHub($user->getId(), $project, $dbForProject, $dbForPlatform, $logger, $authorization); $gitHub = $getUserGitHub($user->getId(), $project, $dbForProject, $dbForPlatform, $authorization, $logger);
$githubName = $gitHub['name'] ?? ''; $githubName = $gitHub['name'] ?? '';
$githubId = $gitHub['id'] ?? ''; $githubId = $gitHub['id'] ?? '';
@ -1061,7 +1061,7 @@ App::get('/v1/cards/cloud-back')
$userId = $user->getId(); $userId = $user->getId();
$email = $user->getAttribute('email', ''); $email = $user->getAttribute('email', '');
$gitHub = $getUserGitHub($user->getId(), $project, $dbForProject, $dbForPlatform, $logger, $authorization); $gitHub = $getUserGitHub($user->getId(), $project, $dbForProject, $dbForPlatform, $authorization, $logger);
$githubId = $gitHub['id'] ?? ''; $githubId = $gitHub['id'] ?? '';
$isHero = \array_key_exists($email, $heroes); $isHero = \array_key_exists($email, $heroes);
@ -1145,7 +1145,7 @@ App::get('/v1/cards/cloud-og')
$email = $user->getAttribute('email', ''); $email = $user->getAttribute('email', '');
$createdAt = new \DateTime($user->getCreatedAt()); $createdAt = new \DateTime($user->getCreatedAt());
$gitHub = $getUserGitHub($user->getId(), $project, $dbForProject, $dbForPlatform, $logger, $authorization); $gitHub = $getUserGitHub($user->getId(), $project, $dbForProject, $dbForPlatform, $authorization, $logger);
$githubName = $gitHub['name'] ?? ''; $githubName = $gitHub['name'] ?? '';
$githubId = $gitHub['id'] ?? ''; $githubId = $gitHub['id'] ?? '';

View file

@ -434,7 +434,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
} }
} }
ComputeBase::updateEmptyManualRule($project, $resource, $deployment, $dbForPlatform); ComputeBase::updateEmptyManualRule($project, $resource, $deployment, $dbForPlatform, $authorization);
if ($resource->getCollection() === 'sites' && !empty($latestCommentId) && !empty($previewRuleId)) { if ($resource->getCollection() === 'sites' && !empty($latestCommentId) && !empty($previewRuleId)) {
$retries = 0; $retries = 0;

8922
composer.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -53,7 +53,7 @@ class Base extends Action
return $allowedSpecifications[0] ?? APP_COMPUTE_SPECIFICATION_DEFAULT; return $allowedSpecifications[0] ?? APP_COMPUTE_SPECIFICATION_DEFAULT;
} }
public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, Database $dbForPlatform, Build $queueForBuilds, Document $template, GitHub $github, bool $activate, string $referenceType = 'branch', string $reference = ''): Document public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, Database $dbForPlatform, Build $queueForBuilds, Document $template, GitHub $github, bool $activate, Authorization $authorization, string $referenceType = 'branch', string $reference = ''): Document
{ {
$deploymentId = ID::unique(); $deploymentId = ID::unique();
$entrypoint = $function->getAttribute('entrypoint', ''); $entrypoint = $function->getAttribute('entrypoint', '');
@ -134,7 +134,7 @@ class Base extends Action
->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', ''));
$dbForProject->updateDocument('functions', $function->getId(), $function); $dbForProject->updateDocument('functions', $function->getId(), $function);
$this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform); $this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform, $authorization);
$queueForBuilds $queueForBuilds
->setType(BUILD_TYPE_DEPLOYMENT) ->setType(BUILD_TYPE_DEPLOYMENT)
@ -330,7 +330,7 @@ class Base extends Action
} }
} }
$this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform); $this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform, $authorization);
$queueForBuilds $queueForBuilds
->setType(BUILD_TYPE_DEPLOYMENT) ->setType(BUILD_TYPE_DEPLOYMENT)
@ -351,7 +351,7 @@ class Base extends Action
* @param \Utopia\Database\Database $dbForPlatform * @param \Utopia\Database\Database $dbForPlatform
* @return void * @return void
*/ */
public static function updateEmptyManualRule(Document $project, Document $resource, Document $deployment, Database $dbForPlatform) public static function updateEmptyManualRule(Document $project, Document $resource, Document $deployment, Database $dbForPlatform, Authorization $authorization)
{ {
$resourceType = $resource->getCollection() === 'sites' ? 'site' : 'function'; $resourceType = $resource->getCollection() === 'sites' ? 'site' : 'function';
@ -363,8 +363,8 @@ class Base extends Action
Query::equal('type', ['deployment']), Query::equal('type', ['deployment']),
Query::equal('trigger', ['manual']), Query::equal('trigger', ['manual']),
]; ];
$dbForPlatform->forEach('rules', function (Document $rule) use ($deployment, $dbForPlatform) { $dbForPlatform->forEach('rules', function (Document $rule) use ($deployment, $dbForPlatform, $authorization) {
Authorization::skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ $authorization->skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
'deploymentId' => $deployment->getId(), 'deploymentId' => $deployment->getId(),
'deploymentInternalId' => $deployment->getSequence(), 'deploymentInternalId' => $deployment->getSequence(),
]))); ])));

View file

@ -18,6 +18,7 @@ use Utopia\Database\Helpers\ID;
use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Permission;
use Utopia\Database\Helpers\Role; use Utopia\Database\Helpers\Role;
use Utopia\Database\Query; use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\UID; use Utopia\Database\Validator\UID;
use Utopia\Platform\Action; use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP; use Utopia\Platform\Scope\HTTP;
@ -90,6 +91,7 @@ class Create extends Base
->inject('deviceForLocal') ->inject('deviceForLocal')
->inject('queueForBuilds') ->inject('queueForBuilds')
->inject('plan') ->inject('plan')
->inject('authorization')
->callback($this->action(...)); ->callback($this->action(...));
} }
@ -108,7 +110,8 @@ class Create extends Base
Device $deviceForFunctions, Device $deviceForFunctions,
Device $deviceForLocal, Device $deviceForLocal,
Build $queueForBuilds, Build $queueForBuilds,
array $plan array $plan,
Authorization $authorization
) { ) {
$activate = \strval($activate) === 'true' || \strval($activate) === '1'; $activate = \strval($activate) === 'true' || \strval($activate) === '1';
@ -304,7 +307,7 @@ class Create extends Base
} }
} }
$this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform); $this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform, $authorization);
$metadata = null; $metadata = null;

View file

@ -15,6 +15,7 @@ use Utopia\Database\Document;
use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\ID;
use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Permission;
use Utopia\Database\Helpers\Role; use Utopia\Database\Helpers\Role;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\UID; use Utopia\Database\Validator\UID;
use Utopia\Platform\Action; use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP; use Utopia\Platform\Scope\HTTP;
@ -77,6 +78,7 @@ class Create extends Base
->inject('project') ->inject('project')
->inject('queueForBuilds') ->inject('queueForBuilds')
->inject('gitHub') ->inject('gitHub')
->inject('authorization')
->callback($this->action(...)); ->callback($this->action(...));
} }
@ -95,7 +97,8 @@ class Create extends Base
Event $queueForEvents, Event $queueForEvents,
Document $project, Document $project,
Build $queueForBuilds, Build $queueForBuilds,
GitHub $github GitHub $github,
Authorization $authorization
) { ) {
$function = $dbForProject->getDocument('functions', $functionId); $function = $dbForProject->getDocument('functions', $functionId);
@ -128,7 +131,10 @@ class Create extends Base
queueForBuilds: $queueForBuilds, queueForBuilds: $queueForBuilds,
template: $template, template: $template,
github: $github, github: $github,
activate: $activate activate: $activate,
authorization: $authorization,
referenceType: $type,
reference: $reference
); );
$queueForEvents $queueForEvents
@ -172,7 +178,7 @@ class Create extends Base
$dbForProject->updateDocument('functions', $function->getId(), $function); $dbForProject->updateDocument('functions', $function->getId(), $function);
$this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform); $this->updateEmptyManualRule($project, $function, $deployment, $dbForPlatform, $authorization);
$queueForBuilds $queueForBuilds
->setType(BUILD_TYPE_DEPLOYMENT) ->setType(BUILD_TYPE_DEPLOYMENT)

View file

@ -72,6 +72,7 @@ class Create extends Base
->inject('queueForEvents') ->inject('queueForEvents')
->inject('queueForBuilds') ->inject('queueForBuilds')
->inject('gitHub') ->inject('gitHub')
->inject('authorization')
->callback($this->action(...)); ->callback($this->action(...));
} }
@ -87,7 +88,8 @@ class Create extends Base
Document $project, Document $project,
Event $queueForEvents, Event $queueForEvents,
Build $queueForBuilds, Build $queueForBuilds,
GitHub $github GitHub $github,
Authorization $authorization
) { ) {
$function = $dbForProject->getDocument('functions', $functionId); $function = $dbForProject->getDocument('functions', $functionId);
@ -110,6 +112,7 @@ class Create extends Base
template: $template, template: $template,
github: $github, github: $github,
activate: $activate, activate: $activate,
authorization: $authorization,
reference: $reference, reference: $reference,
referenceType: $type referenceType: $type
); );

View file

@ -319,6 +319,7 @@ class Create extends Base
template: $template, template: $template,
github: $github, github: $github,
activate: true, activate: true,
authorization: $authorization,
reference: $providerBranch, reference: $providerBranch,
referenceType: 'branch' referenceType: 'branch'
); );

View file

@ -275,7 +275,7 @@ class Update extends Base
// Redeploy logic // Redeploy logic
if (!$isConnected && !empty($providerRepositoryId)) { if (!$isConnected && !empty($providerRepositoryId)) {
$this->redeployVcsFunction($request, $function, $project, $installation, $dbForProject, $dbForPlatform, $queueForBuilds, new Document(), $github, true); $this->redeployVcsFunction($request, $function, $project, $installation, $dbForProject, $dbForPlatform, $queueForBuilds, new Document(), $github, true, $authorization);
} }
// Inform scheduler if function is still active // Inform scheduler if function is still active

View file

@ -368,7 +368,7 @@ class Create extends Base
} }
} }
$this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform); $this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform, $authorization);
$metadata = null; $metadata = null;

View file

@ -211,7 +211,7 @@ class Create extends Base
])) ]))
); );
$this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform); $this->updateEmptyManualRule($project, $site, $deployment, $dbForPlatform, $authorization);
$queueForBuilds $queueForBuilds
->setType(BUILD_TYPE_DEPLOYMENT) ->setType(BUILD_TYPE_DEPLOYMENT)

View file

@ -97,6 +97,7 @@ class Update extends Base
->inject('dbForPlatform') ->inject('dbForPlatform')
->inject('gitHub') ->inject('gitHub')
->inject('executor') ->inject('executor')
->inject('authorization')
->callback($this->action(...)); ->callback($this->action(...));
} }
@ -127,7 +128,8 @@ class Update extends Base
Build $queueForBuilds, Build $queueForBuilds,
Database $dbForPlatform, Database $dbForPlatform,
GitHub $github, GitHub $github,
Executor $executor Executor $executor,
Authorization $authorization
) { ) {
if (!empty($adapter)) { if (!empty($adapter)) {
$configFramework = Config::getParam('frameworks')[$framework] ?? []; $configFramework = Config::getParam('frameworks')[$framework] ?? [];
@ -272,7 +274,7 @@ class Update extends Base
// Redeploy logic // Redeploy logic
if (!$isConnected && !empty($providerRepositoryId)) { if (!$isConnected && !empty($providerRepositoryId)) {
$this->redeployVcsFunction($request, $site, $project, $installation, $dbForProject, $dbForPlatform, $queueForBuilds, new Document(), $github, true); $this->redeployVcsFunction($request, $site, $project, $installation, $dbForProject, $dbForPlatform, $queueForBuilds, new Document(), $github, true, $authorization);
} }
$queueForEvents->setParam('siteId', $site->getId()); $queueForEvents->setParam('siteId', $site->getId());

View file

@ -44,7 +44,6 @@ class StatsResources extends Action
->inject('dbForPlatform') ->inject('dbForPlatform')
->inject('logError') ->inject('logError')
->inject('queueForStatsResources') ->inject('queueForStatsResources')
->inject('authorization')
->callback($this->action(...)); ->callback($this->action(...));
} }