mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix(organization): attribute key events and audits to the resolved project
Organization requests run through the console project, so the event queue and audit context start out pointing at console. Re-point both at the project named in the route before recording key changes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae6aa8c59d
commit
7f443ef6fe
4 files changed
+24
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Platform\Modules\Organization\Http\Projects\Keys;
|
||||
|
||||
use Appwrite\Auth\Key;
|
||||
use Appwrite\Event\Context\Audit as AuditContext;
|
||||
use Appwrite\Event\Event as QueueEvent;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\SDK\AuthType;
|
||||
@@ -73,6 +74,7 @@ class Create extends Action
|
||||
->inject('team')
|
||||
->inject('authorization')
|
||||
->inject('apiKey')
|
||||
->inject('auditContext')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
@@ -88,6 +90,7 @@ class Create extends Action
|
||||
Document $team,
|
||||
Authorization $authorization,
|
||||
?Key $apiKey,
|
||||
AuditContext $auditContext,
|
||||
) {
|
||||
// Dynamic supported for backwards compatibility
|
||||
if ($apiKey !== null && \in_array($apiKey->getType(), [API_KEY_STANDARD, API_KEY_EPHEMERAL, 'dynamic'], true)) {
|
||||
@@ -96,6 +99,9 @@ class Create extends Action
|
||||
|
||||
$project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey);
|
||||
|
||||
// The request may run through the console project; events and audits belong to the resolved project
|
||||
$queueForEvents->setProject($project);
|
||||
$auditContext->project = $project;
|
||||
$keyId = ($keyId == 'unique()') ? ID::unique() : $keyId;
|
||||
|
||||
$key = new Document([
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Platform\Modules\Organization\Http\Projects\Keys;
|
||||
|
||||
use Appwrite\Auth\Key;
|
||||
use Appwrite\Event\Context\Audit as AuditContext;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\SDK\AuthType;
|
||||
@@ -60,6 +61,7 @@ class Delete extends Action
|
||||
->inject('team')
|
||||
->inject('authorization')
|
||||
->inject('apiKey')
|
||||
->inject('auditContext')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
@@ -72,9 +74,13 @@ class Delete extends Action
|
||||
Document $team,
|
||||
Authorization $authorization,
|
||||
?Key $apiKey,
|
||||
AuditContext $auditContext,
|
||||
) {
|
||||
$project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey);
|
||||
|
||||
// The request may run through the console project; events and audits belong to the resolved project
|
||||
$queueForEvents->setProject($project);
|
||||
$auditContext->project = $project;
|
||||
$key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId));
|
||||
|
||||
if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) {
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Ephemeral;
|
||||
|
||||
use Ahc\Jwt\JWT;
|
||||
use Appwrite\Auth\Key;
|
||||
use Appwrite\Event\Context\Audit as AuditContext;
|
||||
use Appwrite\Event\Event as QueueEvent;
|
||||
use Appwrite\Platform\Modules\Organization\Http\Projects\Keys\Action;
|
||||
use Appwrite\SDK\AuthType;
|
||||
@@ -68,6 +69,7 @@ class Create extends Action
|
||||
->inject('dbForPlatform')
|
||||
->inject('team')
|
||||
->inject('apiKey')
|
||||
->inject('auditContext')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
@@ -80,9 +82,13 @@ class Create extends Action
|
||||
Database $dbForPlatform,
|
||||
Document $team,
|
||||
?Key $apiKey,
|
||||
AuditContext $auditContext,
|
||||
) {
|
||||
$project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey);
|
||||
|
||||
// The request may run through the console project; events and audits belong to the resolved project
|
||||
$queueForEvents->setProject($project);
|
||||
$auditContext->project = $project;
|
||||
$keyId = ID::unique();
|
||||
|
||||
$jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', $duration, 0);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Platform\Modules\Organization\Http\Projects\Keys;
|
||||
|
||||
use Appwrite\Auth\Key;
|
||||
use Appwrite\Event\Context\Audit as AuditContext;
|
||||
use Appwrite\Event\Event as QueueEvent;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\SDK\AuthType;
|
||||
@@ -69,6 +70,7 @@ class Update extends Action
|
||||
->inject('team')
|
||||
->inject('authorization')
|
||||
->inject('apiKey')
|
||||
->inject('auditContext')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
@@ -84,9 +86,13 @@ class Update extends Action
|
||||
Document $team,
|
||||
Authorization $authorization,
|
||||
?Key $apiKey,
|
||||
AuditContext $auditContext,
|
||||
) {
|
||||
$project = $this->getProject($projectId, $team, $dbForPlatform, $apiKey);
|
||||
|
||||
// The request may run through the console project; events and audits belong to the resolved project
|
||||
$queueForEvents->setProject($project);
|
||||
$auditContext->project = $project;
|
||||
$key = $authorization->skip(fn () => $dbForPlatform->getDocument('keys', $keyId));
|
||||
|
||||
if ($key->isEmpty() || $key->getAttribute('resourceType', '') !== 'projects' || $key->getAttribute('resourceInternalId', '') !== $project->getSequence()) {
|
||||
|
||||
Reference in new issue
Block a user