Read logs DB

This commit is contained in:
Jake Barnby
2025-02-24 13:43:09 +13:00
parent 392b33ef26
commit 61286f7526
5 changed files with 82 additions and 61 deletions
+13 -8
View File
@@ -2706,8 +2706,9 @@ App::get('/v1/account/logs')
->inject('user')
->inject('locale')
->inject('geodb')
->inject('dbForProject')
->action(function (array $queries, Response $response, Document $user, Locale $locale, Reader $geodb, Database $dbForProject) {
->inject('project')
->inject('getLogsDB')
->action(function (array $queries, Response $response, Document $user, Locale $locale, Reader $geodb, Document $project, callable $getLogsDB) {
try {
$queries = Query::parseQueries($queries);
@@ -2719,9 +2720,15 @@ App::get('/v1/account/logs')
$limit = $grouped['limit'] ?? APP_LIMIT_COUNT;
$offset = $grouped['offset'] ?? 0;
$audit = new EventAudit($dbForProject);
$logsDB = $getLogsDB($project);
$logs = $audit->getLogsByUser($user->getInternalId(), $limit, $offset);
$audit = new EventAudit($logsDB);
$logs = $audit->getLogsByUser(
$user->getInternalId(),
$limit,
$offset
);
$output = [];
@@ -2750,10 +2757,8 @@ App::get('/v1/account/logs')
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByUser($user->getInternalId()),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByUser($user->getInternalId()),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
+24 -18
View File
@@ -652,10 +652,14 @@ App::get('/v1/databases/:databaseId/logs')
->param('databaseId', '', new UID(), 'Database ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $databaseId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $databaseId, array $queries, Response $response, Document $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$logsDB = $getLogsDB($project);
$database = $dbForProject->getDocument('databases', $databaseId);
@@ -673,7 +677,7 @@ App::get('/v1/databases/:databaseId/logs')
$limit = $grouped['limit'] ?? APP_LIMIT_COUNT;
$offset = $grouped['offset'] ?? 0;
$audit = new Audit($dbForProject);
$audit = new Audit($logsDB);
$resource = 'database/' . $databaseId;
$logs = $audit->getLogsByResource($resource, $limit, $offset);
@@ -723,10 +727,8 @@ App::get('/v1/databases/:databaseId/logs')
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByResource($resource),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByResource($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
@@ -1041,10 +1043,14 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs')
->param('collectionId', '', new UID(), 'Collection ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Document $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$logsDB = $getLogsDB($project);
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
@@ -1064,7 +1070,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs')
$limit = $grouped['limit'] ?? APP_LIMIT_COUNT;
$offset = $grouped['offset'] ?? 0;
$audit = new Audit($dbForProject);
$audit = new Audit($logsDB);
$resource = 'database/' . $databaseId . '/collection/' . $collectionId;
$logs = $audit->getLogsByResource($resource, $limit, $offset);
@@ -1114,10 +1120,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs')
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByResource($resource),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByResource($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
@@ -3684,10 +3688,14 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen
->param('documentId', '', new UID(), 'Document ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $databaseId, string $collectionId, string $documentId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $databaseId, string $collectionId, string $documentId, array $queries, Response $response, Document $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$logsDB = $getLogsDB($project);
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
@@ -3717,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($dbForProject);
$audit = new Audit($logsDB);
$resource = 'database/' . $databaseId . '/collection/' . $collectionId . '/document/' . $document->getId();
$logs = $audit->getLogsByResource($resource, $limit, $offset);
@@ -3767,10 +3775,8 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByResource($resource),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByResource($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
+33 -24
View File
@@ -978,10 +978,15 @@ App::get('/v1/messaging/providers/:providerId/logs')
->param('providerId', '', new UID(), 'Provider ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $providerId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $providerId, array $queries, Response $response, Document $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$logsDB = $getLogsDB($project);
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@@ -998,7 +1003,7 @@ App::get('/v1/messaging/providers/:providerId/logs')
$limit = $grouped['limit'] ?? APP_LIMIT_COUNT;
$offset = $grouped['offset'] ?? 0;
$audit = new Audit($dbForProject);
$audit = new Audit($logsDB);
$resource = 'provider/' . $providerId;
$logs = $audit->getLogsByResource($resource, $limit, $offset);
$output = [];
@@ -1047,10 +1052,8 @@ App::get('/v1/messaging/providers/:providerId/logs')
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByResource($resource),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByResource($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
@@ -2208,10 +2211,14 @@ App::get('/v1/messaging/topics/:topicId/logs')
->param('topicId', '', new UID(), 'Topic ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $topicId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $topicId, array $queries, Response $response, Document $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$logsDB = $getLogsDB($project);
$topic = $dbForProject->getDocument('topics', $topicId);
if ($topic->isEmpty()) {
@@ -2228,7 +2235,7 @@ App::get('/v1/messaging/topics/:topicId/logs')
$limit = $grouped['limit'] ?? APP_LIMIT_COUNT;
$offset = $grouped['offset'] ?? 0;
$audit = new Audit($dbForProject);
$audit = new Audit($logsDB);
$resource = 'topic/' . $topicId;
$logs = $audit->getLogsByResource($resource, $limit, $offset);
@@ -2278,10 +2285,8 @@ App::get('/v1/messaging/topics/:topicId/logs')
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByResource($resource),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByResource($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
@@ -2620,10 +2625,14 @@ App::get('/v1/messaging/subscribers/:subscriberId/logs')
->param('subscriberId', '', new UID(), 'Subscriber ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $subscriberId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $subscriberId, array $queries, Response $response, Document $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$logsDB = $getLogsDB($project);
$subscriber = $dbForProject->getDocument('subscribers', $subscriberId);
if ($subscriber->isEmpty()) {
@@ -2640,7 +2649,7 @@ App::get('/v1/messaging/subscribers/:subscriberId/logs')
$limit = $grouped['limit'] ?? APP_LIMIT_COUNT;
$offset = $grouped['offset'] ?? 0;
$audit = new Audit($dbForProject);
$audit = new Audit($logsDB);
$resource = 'subscriber/' . $subscriberId;
$logs = $audit->getLogsByResource($resource, $limit, $offset);
@@ -2690,10 +2699,8 @@ App::get('/v1/messaging/subscribers/:subscriberId/logs')
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByResource($resource),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByResource($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
@@ -3387,10 +3394,14 @@ App::get('/v1/messaging/messages/:messageId/logs')
->param('messageId', '', new UID(), 'Message ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $messageId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $messageId, array $queries, Response $response, Document $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$logsDB = $getLogsDB($project);
$message = $dbForProject->getDocument('messages', $messageId);
if ($message->isEmpty()) {
@@ -3407,7 +3418,7 @@ App::get('/v1/messaging/messages/:messageId/logs')
$limit = $grouped['limit'] ?? APP_LIMIT_COUNT;
$offset = $grouped['offset'] ?? 0;
$audit = new Audit($dbForProject);
$audit = new Audit($logsDB);
$resource = 'message/' . $messageId;
$logs = $audit->getLogsByResource($resource, $limit, $offset);
@@ -3457,10 +3468,8 @@ App::get('/v1/messaging/messages/:messageId/logs')
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByResource($resource),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByResource($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
+7 -6
View File
@@ -1345,10 +1345,13 @@ App::get('/v1/teams/:teamId/logs')
->param('teamId', '', new UID(), 'Team ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $teamId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $teamId, array $queries, Response $response, Documnt $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$logsDB = $getLogsDB($project);
$team = $dbForProject->getDocument('teams', $teamId);
@@ -1366,7 +1369,7 @@ App::get('/v1/teams/:teamId/logs')
$limit = $grouped['limit'] ?? APP_LIMIT_COUNT;
$offset = $grouped['offset'] ?? 0;
$audit = new Audit($dbForProject);
$audit = new Audit($getLogsDB);
$resource = 'team/' . $team->getId();
$logs = $audit->getLogsByResource($resource, $limit, $offset);
@@ -1415,9 +1418,7 @@ App::get('/v1/teams/:teamId/logs')
}
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByResource($resource),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByResource($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
+5 -5
View File
@@ -845,10 +845,12 @@ App::get('/v1/users/:userId/logs')
->param('userId', '', new UID(), 'User ID.')
->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true)
->inject('response')
->inject('project')
->inject('getLogsDB')
->inject('dbForProject')
->inject('locale')
->inject('geodb')
->action(function (string $userId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
->action(function (string $userId, array $queries, Response $response, Document $project, callable $getLogsDB, Database $dbForProject, Locale $locale, Reader $geodb) {
$user = $dbForProject->getDocument('users', $userId);
@@ -915,10 +917,8 @@ App::get('/v1/users/:userId/logs')
}
$response->dynamic(new Document([
//'total' => $audit->countLogsByUser($user->getInternalId()),
//'logs' => $output,
'total' => 0,
'logs' => [],
'total' => $audit->countLogsByUser($user->getInternalId()),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});