Merge pull request #5853 from appwrite/fix-audit-user-internal-id
Fix audit user internal
This commit is contained in:
commit
e12a5738aa
|
@ -1,3 +1,8 @@
|
|||
# Version 1.3.8
|
||||
|
||||
## Bugs
|
||||
- Fix audit user internal [#5809](https://github.com/appwrite/appwrite/pull/5809)
|
||||
|
||||
# Version 1.3.7
|
||||
|
||||
## Bugs
|
||||
|
|
|
@ -66,7 +66,7 @@ docker run -it --rm \
|
|||
--volume /var/run/docker.sock:/var/run/docker.sock \
|
||||
--volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
|
||||
--entrypoint="install" \
|
||||
appwrite/appwrite:1.3.7
|
||||
appwrite/appwrite:1.3.8
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
@ -78,7 +78,7 @@ docker run -it --rm ^
|
|||
--volume //var/run/docker.sock:/var/run/docker.sock ^
|
||||
--volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^
|
||||
--entrypoint="install" ^
|
||||
appwrite/appwrite:1.3.7
|
||||
appwrite/appwrite:1.3.8
|
||||
```
|
||||
|
||||
#### PowerShell
|
||||
|
@ -88,7 +88,7 @@ docker run -it --rm `
|
|||
--volume /var/run/docker.sock:/var/run/docker.sock `
|
||||
--volume ${pwd}/appwrite:/usr/src/code/appwrite:rw `
|
||||
--entrypoint="install" `
|
||||
appwrite/appwrite:1.3.7
|
||||
appwrite/appwrite:1.3.8
|
||||
```
|
||||
|
||||
运行后,可以在浏览器上访问 http://localhost 找到 Appwrite 控制台。在非 Linux 的本机主机上完成安装后,服务器可能需要几分钟才能启动。
|
||||
|
|
|
@ -75,7 +75,7 @@ docker run -it --rm \
|
|||
--volume /var/run/docker.sock:/var/run/docker.sock \
|
||||
--volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
|
||||
--entrypoint="install" \
|
||||
appwrite/appwrite:1.3.7
|
||||
appwrite/appwrite:1.3.8
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
@ -87,7 +87,7 @@ docker run -it --rm ^
|
|||
--volume //var/run/docker.sock:/var/run/docker.sock ^
|
||||
--volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^
|
||||
--entrypoint="install" ^
|
||||
appwrite/appwrite:1.3.7
|
||||
appwrite/appwrite:1.3.8
|
||||
```
|
||||
|
||||
#### PowerShell
|
||||
|
@ -97,7 +97,7 @@ docker run -it --rm `
|
|||
--volume /var/run/docker.sock:/var/run/docker.sock `
|
||||
--volume ${pwd}/appwrite:/usr/src/code/appwrite:rw `
|
||||
--entrypoint="install" `
|
||||
appwrite/appwrite:1.3.7
|
||||
appwrite/appwrite:1.3.8
|
||||
```
|
||||
|
||||
Once the Docker installation is complete, go to http://localhost to access the Appwrite console from your browser. Please note that on non-Linux native hosts, the server might take a few minutes to start after completing the installation.
|
||||
|
|
|
@ -1427,7 +1427,7 @@ App::get('/v1/account/logs')
|
|||
|
||||
$audit = new EventAudit($dbForProject);
|
||||
|
||||
$logs = $audit->getLogsByUser($user->getId(), $limit, $offset);
|
||||
$logs = $audit->getLogsByUser($user->getInternalId(), $limit, $offset);
|
||||
|
||||
$output = [];
|
||||
|
||||
|
|
|
@ -566,7 +566,7 @@ App::get('/v1/databases/:databaseId/logs')
|
|||
|
||||
$output[$i] = new Document([
|
||||
'event' => $log['event'],
|
||||
'userId' => ID::custom($log['userId']),
|
||||
'userId' => ID::custom($log['data']['userId']),
|
||||
'userEmail' => $log['data']['userEmail'] ?? null,
|
||||
'userName' => $log['data']['userName'] ?? null,
|
||||
'mode' => $log['data']['mode'] ?? null,
|
||||
|
@ -917,7 +917,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/logs')
|
|||
|
||||
$output[$i] = new Document([
|
||||
'event' => $log['event'],
|
||||
'userId' => $log['userId'],
|
||||
'userId' => $log['data']['userId'],
|
||||
'userEmail' => $log['data']['userEmail'] ?? null,
|
||||
'userName' => $log['data']['userName'] ?? null,
|
||||
'mode' => $log['data']['mode'] ?? null,
|
||||
|
@ -3149,7 +3149,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents/:documen
|
|||
|
||||
$output[$i] = new Document([
|
||||
'event' => $log['event'],
|
||||
'userId' => $log['userId'],
|
||||
'userId' => $log['data']['userId'],
|
||||
'userEmail' => $log['data']['userEmail'] ?? null,
|
||||
'userName' => $log['data']['userName'] ?? null,
|
||||
'mode' => $log['data']['mode'] ?? null,
|
||||
|
|
|
@ -1043,7 +1043,7 @@ App::get('/v1/teams/:teamId/logs')
|
|||
|
||||
$output[$i] = new Document([
|
||||
'event' => $log['event'],
|
||||
'userId' => $log['userId'],
|
||||
'userId' => $log['data']['userId'],
|
||||
'userEmail' => $log['data']['userEmail'] ?? null,
|
||||
'userName' => $log['data']['userName'] ?? null,
|
||||
'mode' => $log['data']['mode'] ?? null,
|
||||
|
|
|
@ -577,7 +577,7 @@ App::get('/v1/users/:userId/logs')
|
|||
|
||||
$audit = new Audit($dbForProject);
|
||||
|
||||
$logs = $audit->getLogsByUser($user->getId(), $limit, $offset);
|
||||
$logs = $audit->getLogsByUser($user->getInternalId(), $limit, $offset);
|
||||
|
||||
$output = [];
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ const APP_LIMIT_LIST_DEFAULT = 25; // Default maximum number of items to return
|
|||
const APP_KEY_ACCCESS = 24 * 60 * 60; // 24 hours
|
||||
const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours
|
||||
const APP_CACHE_BUSTER = 506;
|
||||
const APP_VERSION_STABLE = '1.3.7';
|
||||
const APP_VERSION_STABLE = '1.3.8';
|
||||
const APP_DATABASE_ATTRIBUTE_EMAIL = 'email';
|
||||
const APP_DATABASE_ATTRIBUTE_ENUM = 'enum';
|
||||
const APP_DATABASE_ATTRIBUTE_IP = 'ip';
|
||||
|
|
|
@ -40,8 +40,7 @@ class AuditsV1 extends Worker
|
|||
$dbForProject = $this->getProjectDB($project->getId());
|
||||
$audit = new Audit($dbForProject);
|
||||
$audit->log(
|
||||
userInternalId: $user->getInternalId(),
|
||||
userId: $user->getId(),
|
||||
userId: $user->getInternalId(),
|
||||
// Pass first, most verbose event pattern
|
||||
event: $event,
|
||||
resource: $resource,
|
||||
|
@ -49,6 +48,7 @@ class AuditsV1 extends Worker
|
|||
ip: $ip,
|
||||
location: '',
|
||||
data: [
|
||||
'userId' => $user->getId(),
|
||||
'userName' => $userName,
|
||||
'userEmail' => $userEmail,
|
||||
'mode' => $mode,
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
"appwrite/php-runtimes": "0.11.*",
|
||||
"utopia-php/abuse": "0.25.*",
|
||||
"utopia-php/analytics": "0.2.*",
|
||||
"utopia-php/audit": "0.26.*",
|
||||
"utopia-php/audit": "0.27.*",
|
||||
"utopia-php/cache": "0.8.*",
|
||||
"utopia-php/cli": "0.13.*",
|
||||
"utopia-php/config": "0.2.*",
|
||||
|
|
14
composer.lock
generated
14
composer.lock
generated
|
@ -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": "21b8661eef2ca7648831651b99a11544",
|
||||
"content-hash": "a15f62920dedaf99e321ffd94e89d9f4",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/jwt",
|
||||
|
@ -1906,16 +1906,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/audit",
|
||||
"version": "0.26.0",
|
||||
"version": "0.27.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/audit.git",
|
||||
"reference": "e7228080f14df28737fbb050c180c26d86ac0403"
|
||||
"reference": "bdf89d7fe381bd4c891ad217612580a35e8c7642"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/e7228080f14df28737fbb050c180c26d86ac0403",
|
||||
"reference": "e7228080f14df28737fbb050c180c26d86ac0403",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/bdf89d7fe381bd4c891ad217612580a35e8c7642",
|
||||
"reference": "bdf89d7fe381bd4c891ad217612580a35e8c7642",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1947,9 +1947,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/audit/issues",
|
||||
"source": "https://github.com/utopia-php/audit/tree/0.26.0"
|
||||
"source": "https://github.com/utopia-php/audit/tree/0.27.0"
|
||||
},
|
||||
"time": "2023-04-27T15:43:50+00:00"
|
||||
"time": "2023-05-15T07:04:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/cache",
|
||||
|
|
|
@ -63,6 +63,7 @@ abstract class Migration
|
|||
'1.3.5' => 'V18',
|
||||
'1.3.6' => 'V18',
|
||||
'1.3.7' => 'V18',
|
||||
'1.3.8' => 'V18',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -133,6 +133,16 @@ class V18 extends Migration
|
|||
Console::warning("'options' from {$id}: {$th->getMessage()}");
|
||||
}
|
||||
break;
|
||||
case 'audit':
|
||||
try {
|
||||
/**
|
||||
* Delete 'userInternalId' attribute
|
||||
*/
|
||||
$this->projectDB->deleteAttribute($id, 'userInternalId');
|
||||
} catch (\Throwable $th) {
|
||||
Console::warning("'userInternalId' from {$id}: {$th->getMessage()}");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -195,6 +205,34 @@ class V18 extends Migration
|
|||
Console::warning($th->getMessage());
|
||||
}
|
||||
break;
|
||||
case 'audit':
|
||||
/**
|
||||
* Set the userId to the userInternalId and add userId to data
|
||||
*/
|
||||
try {
|
||||
$userId = $document->getAttribute('userId');
|
||||
$data = $document->getAttribute('data', []);
|
||||
$mode = $data['mode'] ?? 'default';
|
||||
$user = match ($mode) {
|
||||
'admin' => $this->consoleDB->getDocument('users', $userId),
|
||||
default => $this->projectDB->getDocument('users', $userId),
|
||||
};
|
||||
|
||||
if ($user->isEmpty()) {
|
||||
// The audit userId could already be an internal Id.
|
||||
// Otherwise, the user could have been deleted.
|
||||
// Nonetheless, there's nothing else we can do here.
|
||||
break;
|
||||
}
|
||||
$internalId = $user->getInternalId();
|
||||
$document->setAttribute('userId', $internalId);
|
||||
$data = $document->getAttribute('data', []);
|
||||
$data['userId'] = $user->getId();
|
||||
$document->setAttribute('data', $data);
|
||||
} catch (\Throwable $th) {
|
||||
Console::warning($th->getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $document;
|
||||
|
|
Loading…
Reference in a new issue