1
0
Fork 0
mirror of synced 2024-07-12 18:05:55 +12:00
appwrite/app/workers/audits.php
Steven Nguyen 58fa7546c1
Update Appwrite to save internal id as audit user id
It's important to use userInternalId so that if a user is recreated
with the same ID, lookups for the user will not return the data
of the old deleted user.

We will still store userId in data so that it can be pulled out and
returned for the log API calls.
2023-07-19 22:49:51 -07:00

64 lines
1.6 KiB
PHP

<?php
use Appwrite\Event\Event;
use Appwrite\Resque\Worker;
use Utopia\Audit\Audit;
use Utopia\CLI\Console;
use Utopia\Database\Document;
require_once __DIR__ . '/../init.php';
Console::title('Audits V1 Worker');
Console::success(APP_NAME . ' audits worker v1 has started');
class AuditsV1 extends Worker
{
public function getName(): string
{
return "audits";
}
public function init(): void
{
}
public function run(): void
{
$event = $this->args['event'];
$payload = $this->args['payload'];
$mode = $this->args['mode'];
$resource = $this->args['resource'];
$userAgent = $this->args['userAgent'];
$ip = $this->args['ip'];
$user = new Document($this->args['user']);
$project = new Document($this->args['project']);
$userName = $user->getAttribute('name', '');
$userEmail = $user->getAttribute('email', '');
$dbForProject = $this->getProjectDB($project->getId());
$audit = new Audit($dbForProject);
$audit->log(
userId: $user->getInternalId(),
// Pass first, most verbose event pattern
event: $event,
resource: $resource,
userAgent: $userAgent,
ip: $ip,
location: '',
data: [
'userId' => $user->getId(),
'userName' => $userName,
'userEmail' => $userEmail,
'mode' => $mode,
'data' => $payload,
]
);
}
public function shutdown(): void
{
}
}