1
0
Fork 0
mirror of synced 2024-06-29 03:30:34 +12:00

feat: added function to parse user object

This commit is contained in:
Christy Jacob 2020-12-26 16:46:43 +05:30
parent 898d89f322
commit 46114a5920
3 changed files with 51 additions and 5 deletions

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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', [