From 9c2e1c1f4dab02a00d0b98542366c978504d3fd8 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 24 Feb 2025 18:03:11 +1300 Subject: [PATCH] Reapply "Update logs read adapter" This reverts commit 3e2a805d6ca08bb96d9aa82419cd16a0c89d7a51. --- app/controllers/api/account.php | 4 ++-- app/controllers/api/databases.php | 8 ++++---- app/controllers/api/messaging.php | 10 +++++----- app/controllers/api/projects.php | 7 ++++--- app/controllers/api/teams.php | 4 ++-- app/controllers/api/users.php | 6 ++++-- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index a2af6b1ce4..820cc25ff8 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -37,7 +37,7 @@ use libphonenumber\PhoneNumberUtil; use MaxMind\Db\Reader; use Utopia\Abuse\Abuse; use Utopia\App; -use Utopia\Audit\Audit as EventAudit; +use Utopia\Audit\Adapter\Activity; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\DateTime; @@ -2722,7 +2722,7 @@ App::get('/v1/account/logs') $logsDB = $getLogsDB($project); - $audit = new EventAudit($logsDB); + $audit = new Activity($logsDB); $logs = $audit->getLogsByUser( $user->getInternalId(), diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 8761b35cbc..486b2bd886 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -20,7 +20,7 @@ use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use MaxMind\Db\Reader; use Utopia\App; -use Utopia\Audit\Audit; +use Utopia\Audit\Adapter\Activity; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; @@ -677,7 +677,7 @@ App::get('/v1/databases/:databaseId/logs') $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($logsDB); + $audit = new Activity($logsDB); $resource = 'database/' . $databaseId; $logs = $audit->getLogsByResource($resource, $limit, $offset); @@ -1070,7 +1070,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs') $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($logsDB); + $audit = new Activity($logsDB); $resource = 'database/' . $databaseId . '/collection/' . $collectionId; $logs = $audit->getLogsByResource($resource, $limit, $offset); @@ -3725,7 +3725,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($logsDB); + $audit = new Activity($logsDB); $resource = 'database/' . $databaseId . '/collection/' . $collectionId . '/document/' . $document->getId(); $logs = $audit->getLogsByResource($resource, $limit, $offset); diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 76effc4987..b340f3f6d5 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -25,7 +25,7 @@ use Appwrite\Utopia\Database\Validator\Queries\Topics; use Appwrite\Utopia\Response; use MaxMind\Db\Reader; use Utopia\App; -use Utopia\Audit\Audit; +use Utopia\Audit\Adapter\Activity; use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; @@ -1003,7 +1003,7 @@ App::get('/v1/messaging/providers/:providerId/logs') $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($logsDB); + $audit = new Activity($logsDB); $resource = 'provider/' . $providerId; $logs = $audit->getLogsByResource($resource, $limit, $offset); $output = []; @@ -2235,7 +2235,7 @@ App::get('/v1/messaging/topics/:topicId/logs') $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($logsDB); + $audit = new Activity($logsDB); $resource = 'topic/' . $topicId; $logs = $audit->getLogsByResource($resource, $limit, $offset); @@ -2649,7 +2649,7 @@ App::get('/v1/messaging/subscribers/:subscriberId/logs') $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($logsDB); + $audit = new Activity($logsDB); $resource = 'subscriber/' . $subscriberId; $logs = $audit->getLogsByResource($resource, $limit, $offset); @@ -3418,7 +3418,7 @@ App::get('/v1/messaging/messages/:messageId/logs') $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($logsDB); + $audit = new Activity($logsDB); $resource = 'message/' . $messageId; $logs = $audit->getLogsByResource($resource, $limit, $offset); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 48d20cd17f..bc9e3a5810 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -21,7 +21,8 @@ use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use PHPMailer\PHPMailer\PHPMailer; use Utopia\App; -use Utopia\Audit\Audit; +use Utopia\Audit\Adapter\Activity; +use Utopia\Audit\Adapter\Audit; use Utopia\Cache\Cache; use Utopia\Config\Config; use Utopia\Database\Database; @@ -242,8 +243,8 @@ App::post('/v1/projects') } if (!$create && $sharedTablesV1) { - $attributes = \array_map(fn ($attribute) => new Document($attribute), Audit::ATTRIBUTES); - $indexes = \array_map(fn (array $index) => new Document($index), Audit::INDEXES); + $attributes = \array_map(fn ($attribute) => new Document($attribute), $audit->getAttributes()); + $indexes = \array_map(fn (array $index) => new Document($index), $audit->getIndexes()); $dbForProject->createDocument(Database::METADATA, new Document([ '$id' => ID::custom('audit'), '$permissions' => [Permission::create(Role::any())], diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index e8f4930845..1fbf392dc7 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -26,7 +26,7 @@ use libphonenumber\PhoneNumberUtil; use MaxMind\Db\Reader; use Utopia\Abuse\Abuse; use Utopia\App; -use Utopia\Audit\Audit; +use Utopia\Audit\Adapter\Activity; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\DateTime; @@ -1369,7 +1369,7 @@ App::get('/v1/teams/:teamId/logs') $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($getLogsDB); + $audit = new Activity($logsDB); $resource = 'team/' . $team->getId(); $logs = $audit->getLogsByResource($resource, $limit, $offset); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 6b4536134e..a47bbe51ea 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -27,7 +27,7 @@ use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use MaxMind\Db\Reader; use Utopia\App; -use Utopia\Audit\Audit; +use Utopia\Audit\Adapter\Activity; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\DateTime; @@ -868,7 +868,9 @@ App::get('/v1/users/:userId/logs') $limit = $grouped['limit'] ?? APP_LIMIT_COUNT; $offset = $grouped['offset'] ?? 0; - $audit = new Audit($dbForProject); + $logsDB = $getLogsDB($project); + + $audit = new Activity($logsDB); $logs = $audit->getLogsByUser($user->getInternalId(), $limit, $offset);