1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00

use updated audit library

This commit is contained in:
Torsten Dittmann 2021-11-16 15:54:29 +01:00
parent 19d01c17bb
commit ced8c9ef03
8 changed files with 47 additions and 20 deletions

View file

@ -1201,8 +1201,7 @@ App::get('/v1/account/logs')
/** @var Appwrite\Stats\Stats $usage */
$audit = new Audit($dbForInternal);
$logs = $audit->getLogsByUserAndEvents($user->getId(), [
$auditEvents = [
'account.create',
'account.delete',
'account.update.name',
@ -1218,7 +1217,9 @@ App::get('/v1/account/logs')
'teams.membership.create',
'teams.membership.update',
'teams.membership.delete',
], $limit, $offset);
];
$logs = $audit->getLogsByUserAndEvents($user->getId(), $auditEvents, $limit, $offset);
$output = [];
@ -1248,7 +1249,11 @@ App::get('/v1/account/logs')
$usage
->setParam('users.read', 1)
;
$response->dynamic(new Document(['logs' => $output]), Response::MODEL_LOG_LIST);
$response->dynamic(new Document([
'sum' => $audit->getLogsByUserAndEventsCount($user->getId(), $auditEvents),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
App::get('/v1/account/sessions/:sessionId')

View file

@ -480,8 +480,8 @@ App::get('/v1/database/collections/:collectionId/logs')
}
$audit = new Audit($dbForInternal);
$logs = $audit->getLogsByResource('collection/'.$collection->getId(), $limit, $offset);
$resource = 'collection/'.$collection->getId();
$logs = $audit->getLogsByResource($resource, $limit, $offset);
$output = [];
@ -541,7 +541,10 @@ App::get('/v1/database/collections/:collectionId/logs')
}
}
$response->dynamic(new Document(['logs' => $output]), Response::MODEL_LOG_LIST);
$response->dynamic(new Document([
'sum' => $audit->getLogsByResourceCount($resource),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
App::put('/v1/database/collections/:collectionId')

View file

@ -281,8 +281,7 @@ App::get('/v1/users/:userId/logs')
}
$audit = new Audit($dbForInternal);
$logs = $audit->getLogsByUserAndEvents($user->getId(), [
$auditEvents = [
'account.create',
'account.delete',
'account.update.name',
@ -298,7 +297,9 @@ App::get('/v1/users/:userId/logs')
'teams.membership.create',
'teams.membership.update',
'teams.membership.delete',
], $limit, $offset);
];
$logs = $audit->getLogsByUserAndEvents($user->getId(), $auditEvents, $limit, $offset);
$output = [];
@ -357,7 +358,11 @@ App::get('/v1/users/:userId/logs')
$usage
->setParam('users.read', 1)
;
$response->dynamic(new Document(['logs' => $output]), Response::MODEL_LOG_LIST);
$response->dynamic(new Document([
'sum' => $audit->getLogsByUserAndEventsCount($user->getId(), $auditEvents),
'logs' => $output,
]), Response::MODEL_LOG_LIST);
});
App::patch('/v1/users/:userId/status')

View file

@ -41,7 +41,7 @@
"utopia-php/framework": "0.19.*",
"utopia-php/abuse": "0.6.*",
"utopia-php/analytics": "0.2.*",
"utopia-php/audit": "0.6.*",
"utopia-php/audit": "dev-feat-count-methods",
"utopia-php/cache": "0.4.*",
"utopia-php/cli": "0.11.*",
"utopia-php/config": "0.2.*",

18
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "fa378feaffc446f557a140035a1c77b6",
"content-hash": "14a12f23c3f26ad7650eb3ad912fd078",
"packages": [
{
"name": "adhocore/jwt",
@ -1928,16 +1928,16 @@
},
{
"name": "utopia-php/audit",
"version": "0.6.3",
"version": "dev-feat-count-methods",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/audit.git",
"reference": "d79b467fbc7d03e5e02f12cdeb08761507a60ca0"
"reference": "e9a811cf3b7705e75649db8b5f255a12e0388220"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/audit/zipball/d79b467fbc7d03e5e02f12cdeb08761507a60ca0",
"reference": "d79b467fbc7d03e5e02f12cdeb08761507a60ca0",
"url": "https://api.github.com/repos/utopia-php/audit/zipball/e9a811cf3b7705e75649db8b5f255a12e0388220",
"reference": "e9a811cf3b7705e75649db8b5f255a12e0388220",
"shasum": ""
},
"require": {
@ -1975,9 +1975,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/audit/issues",
"source": "https://github.com/utopia-php/audit/tree/0.6.3"
"source": "https://github.com/utopia-php/audit/tree/feat-count-methods"
},
"time": "2021-08-16T18:49:55+00:00"
"time": "2021-11-16T14:45:05+00:00"
},
{
"name": "utopia-php/cache",
@ -6507,7 +6507,9 @@
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"stability-flags": {
"utopia-php/audit": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {

View file

@ -325,6 +325,7 @@ trait AccountBase
$this->assertIsArray($response['body']['logs']);
$this->assertNotEmpty($response['body']['logs']);
$this->assertCount(2, $response['body']['logs']);
$this->assertIsNumeric($response['body']['sum']);
$this->assertContains($response['body']['logs'][0]['event'], ['account.create', 'account.sessions.create']);
$this->assertEquals($response['body']['logs'][0]['ip'], filter_var($response['body']['logs'][0]['ip'], FILTER_VALIDATE_IP));
@ -383,6 +384,7 @@ trait AccountBase
$this->assertIsArray($responseLimit['body']['logs']);
$this->assertNotEmpty($responseLimit['body']['logs']);
$this->assertCount(1, $responseLimit['body']['logs']);
$this->assertIsNumeric($responseLimit['body']['sum']);
$this->assertEquals($response['body']['logs'][0], $responseLimit['body']['logs'][0]);
@ -400,6 +402,7 @@ trait AccountBase
$this->assertIsArray($responseOffset['body']['logs']);
$this->assertNotEmpty($responseOffset['body']['logs']);
$this->assertCount(1, $responseOffset['body']['logs']);
$this->assertIsNumeric($responseOffset['body']['sum']);
$this->assertEquals($response['body']['logs'][1], $responseOffset['body']['logs'][0]);
@ -417,6 +420,7 @@ trait AccountBase
$this->assertIsArray($responseLimitOffset['body']['logs']);
$this->assertNotEmpty($responseLimitOffset['body']['logs']);
$this->assertCount(1, $responseLimitOffset['body']['logs']);
$this->assertIsNumeric($responseLimitOffset['body']['sum']);
$this->assertEquals($response['body']['logs'][1], $responseLimitOffset['body']['logs'][0]);
/**

View file

@ -138,6 +138,7 @@ class DatabaseConsoleClientTest extends Scope
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']['logs']);
$this->assertIsNumeric($logs['body']['sum']);
$logs = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/logs', array_merge([
'content-type' => 'application/json',
@ -149,6 +150,7 @@ class DatabaseConsoleClientTest extends Scope
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']['logs']);
$this->assertLessThanOrEqual(1, count($logs['body']['logs']));
$this->assertIsNumeric($logs['body']['sum']);
$logs = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/logs', array_merge([
'content-type' => 'application/json',
@ -159,6 +161,7 @@ class DatabaseConsoleClientTest extends Scope
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']['logs']);
$this->assertIsNumeric($logs['body']['sum']);
$logs = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/logs', array_merge([
'content-type' => 'application/json',
@ -171,5 +174,6 @@ class DatabaseConsoleClientTest extends Scope
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']['logs']);
$this->assertLessThanOrEqual(1, count($logs['body']['logs']));
$this->assertIsNumeric($logs['body']['sum']);
}
}

View file

@ -436,6 +436,7 @@ trait UsersBase
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']['logs']);
$this->assertIsNumeric($logs['body']['sum']);
$logs = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/logs', array_merge([
'content-type' => 'application/json',
@ -447,6 +448,7 @@ trait UsersBase
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']['logs']);
$this->assertLessThanOrEqual(1, count($logs['body']['logs']));
$this->assertIsNumeric($logs['body']['sum']);
$logs = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/logs', array_merge([
'content-type' => 'application/json',
@ -457,6 +459,7 @@ trait UsersBase
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']['logs']);
$this->assertIsNumeric($logs['body']['sum']);
$logs = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/logs', array_merge([
'content-type' => 'application/json',
@ -469,6 +472,7 @@ trait UsersBase
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']['logs']);
$this->assertLessThanOrEqual(1, count($logs['body']['logs']));
$this->assertIsNumeric($logs['body']['sum']);
}
/**