From 46114a5920298215584282a2096303faed8e3f95 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 26 Dec 2020 16:46:43 +0530 Subject: [PATCH] feat: added function to parse user object --- src/Appwrite/Utopia/Response/Filter.php | 3 +- src/Appwrite/Utopia/Response/Filters/V06.php | 51 ++++++++++++++++++-- src/Appwrite/Utopia/Response/Model/User.php | 2 +- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Filter.php b/src/Appwrite/Utopia/Response/Filter.php index 9391624d6e..6974c4ba89 100644 --- a/src/Appwrite/Utopia/Response/Filter.php +++ b/src/Appwrite/Utopia/Response/Filter.php @@ -8,9 +8,10 @@ abstract class Filter { * Parse the content to another format. * * @param array $content + * @param string $model * * @return array */ - abstract function parse(array $content): array; + abstract function parse(array $content, string $model): array; } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Filters/V06.php b/src/Appwrite/Utopia/Response/Filters/V06.php index 389cbb3d26..5d66ad2055 100644 --- a/src/Appwrite/Utopia/Response/Filters/V06.php +++ b/src/Appwrite/Utopia/Response/Filters/V06.php @@ -2,13 +2,58 @@ namespace Appwrite\Utopia\Response\Filter; +use Appwrite\Database\Validator\Authorization; +use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filter; +use Exception; +use Utopia\Config\Config; class V06 extends Filter { - // Convert 0.7 Data format to 0.6 format - public function parse(array $content): array { - return array(); + public function parse(array $content, string $model): array { + + $parsedResponse = array(); + + switch($model) { + case Response::MODEL_PROJECT : + $parsedResponse = $this->parseProject($content); + break; + + case Response::MODEL_USER : + $parsedResponse = $this->parseUser($content); + break; + + default: + throw new Exception('Recevied invlaid model : '.$model); + } + + return $parsedResponse; + } + + private function parseProject(array $content) + { + + } + + private function parseUser(array $content){ + $parsedContent = []; + + $parsedContent['$id'] = $content['$id']; + $parsedContent['registration'] = $content['registration']; + $parsedContent['name'] = $content['name']; + $parsedContent['email'] = $content['email']; + + foreach (Config::getParam('providers') as $key => $provider) { + if (!$provider['enabled']) { + continue; + } + $parsedContent['oauth2'.ucfirst($key)] = ''; + $parsedContent['oauth2'.ucfirst($key).'AccessToken'] = ''; + } + + $parsedContent['roles'] = Authorization::getRoles(); + + return $parsedContent; } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index 79c34db5ef..e11d49ed8f 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -27,7 +27,7 @@ class User extends Model ]) ->addRule('status', [ 'type' => self::TYPE_INTEGER, - 'description' => 'User status. 0 for Unavtivated, 1 for active and 2 is blocked.', + 'description' => 'User status. 0 for Unactivated, 1 for active and 2 is blocked.', 'example' => 0, ]) ->addRule('email', [