From f3ff50d686dff9416ff97540646c5ea4f437f1d8 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 12 Jun 2021 21:39:59 +0300 Subject: [PATCH] Fixed logs time attribute --- app/controllers/api/account.php | 3 ++- app/controllers/api/users.php | 3 ++- app/http.php | 4 ++-- src/Appwrite/Utopia/Response/Model/Log.php | 6 ++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 09840733f1..f75a7f65c5 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -872,9 +872,10 @@ App::get('/v1/account/logs') $detector = new Detector($log['userAgent']); $output[$i] = new Document(array_merge([ + 'userId' => $log['userId'], 'event' => $log['event'], 'ip' => $log['ip'], - 'time' => \strtotime($log['time']), + 'time' => $log['time'], ], $detector->getOS(), $detector->getClient(), $detector->getDevice())); $record = $geodb->get($log['ip']); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 3a6fcbe482..9ade946cfe 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -277,9 +277,10 @@ App::get('/v1/users/:userId/logs') $clientEngineVersion = (isset($client['engine_version'])) ? $client['engine_version'] : ''; $output[$i] = new Document([ + 'userId' => $log['userId'], 'event' => $log['event'], 'ip' => $log['ip'], - 'time' => \strtotime($log['time']), + 'time' => $log['time'], 'osCode' => $osCode, 'osName' => $osName, diff --git a/app/http.php b/app/http.php index ea2df6b95e..0e67e07c31 100644 --- a/app/http.php +++ b/app/http.php @@ -3,8 +3,6 @@ require_once __DIR__.'/../vendor/autoload.php'; use Appwrite\Database\Validator\Authorization; -use Utopia\Swoole\Files; -use Utopia\Swoole\Request; use Appwrite\Utopia\Response; use Swoole\Process; use Swoole\Http\Server; @@ -16,6 +14,8 @@ use Utopia\Config\Config; use Utopia\Database\Validator\Authorization as Authorization2; use Utopia\Audit\Audit; use Utopia\Abuse\Adapters\TimeLimit; +use Utopia\Swoole\Files; +use Utopia\Swoole\Request; // xdebug_start_trace('/tmp/trace'); diff --git a/src/Appwrite/Utopia/Response/Model/Log.php b/src/Appwrite/Utopia/Response/Model/Log.php index baf2f83347..051fcde841 100644 --- a/src/Appwrite/Utopia/Response/Model/Log.php +++ b/src/Appwrite/Utopia/Response/Model/Log.php @@ -10,6 +10,12 @@ class Log extends Model public function __construct() { $this + ->addRule('userId', [ + 'type' => self::TYPE_STRING, + 'description' => 'Event name.', + 'default' => '', + 'example' => 'account.sessions.create', + ]) ->addRule('event', [ 'type' => self::TYPE_STRING, 'description' => 'Event name.',