From 71ce0c988bcc62f2b9104e509c31d6848ea2708d Mon Sep 17 00:00:00 2001 From: Peter Dulacka Date: Mon, 9 Nov 2020 14:51:37 +0100 Subject: [PATCH] Return only public user meta in the API remp/web#1167 --- README.md | 10 +++++----- src/api/UserMetaListHandler.php | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9108b01..8d297e3 100644 --- a/README.md +++ b/README.md @@ -714,7 +714,7 @@ Response: #### POST `/api/v1/user-meta/list` -Return all the meta information of specified user. You can specify meta information by using the meta information key. +Return all public meta information of specified user. You can specify meta information by using the meta information key. ##### *Headers:* @@ -743,14 +743,14 @@ Response: ```json5 [ { + "user_id": 123, "key" : "foo", - "value" : "bar", - "is_public" : false + "value" : "bar" }, { + "user_id": 123, "key" : "fooz", - "value" : "1", - "is_public" : true + "value" : "1" } ] ``` diff --git a/src/api/UserMetaListHandler.php b/src/api/UserMetaListHandler.php index 19b475f..bf19bc6 100644 --- a/src/api/UserMetaListHandler.php +++ b/src/api/UserMetaListHandler.php @@ -44,7 +44,10 @@ public function handle(ApiAuthorizationInterface $authorization) $userMetaRows = []; foreach ($authorization->getAuthorizedUsers() as $authorizedUser) { - $query = $this->userMetaRepository->userMetaRows($authorizedUser); + $query = $this->userMetaRepository + ->userMetaRows($authorizedUser) + ->where(['is_public' => true]); + if ($key !== null) { $query->where('key = ?', $key); } @@ -60,7 +63,6 @@ public function handle(ApiAuthorizationInterface $authorization) 'user_id' => $data->user_id, 'key' => $data->key, 'value' => $data->value, - 'is_public' => (bool)$data->is_public, ]; }, array_values($userMetaRows));