Merge branch 'feat-database-indexing' into fix-db-sync-with-master
This commit is contained in:
commit
c1a67fc718
|
@ -212,7 +212,7 @@ $collections = [
|
|||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||
'label' => 'Status',
|
||||
'key' => 'status',
|
||||
'type' => Database::SYSTEM_VAR_TYPE_NUMERIC,
|
||||
'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN,
|
||||
'default' => '',
|
||||
'required' => true,
|
||||
'array' => false,
|
||||
|
|
|
@ -251,7 +251,7 @@ $collections = [
|
|||
],
|
||||
[
|
||||
'$id' => 'status',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_BOOLEAN,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
|
|
|
@ -91,7 +91,7 @@ App::post('/v1/account')
|
|||
'$write' => ['user:'.$userId],
|
||||
'email' => $email,
|
||||
'emailVerification' => false,
|
||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||
'status' => true,
|
||||
'password' => Auth::passwordHash($password),
|
||||
'passwordUpdate' => \time(),
|
||||
'registration' => \time(),
|
||||
|
@ -168,7 +168,7 @@ App::post('/v1/account/sessions')
|
|||
throw new Exception('Invalid credentials', 401); // Wrong password or username
|
||||
}
|
||||
|
||||
if (Auth::USER_STATUS_BLOCKED == $profile->getAttribute('status')) { // Account is blocked
|
||||
if (false === $profile->getAttribute('status')) { // Account is blocked
|
||||
throw new Exception('Invalid credentials. User is blocked', 401); // User is in status blocked
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
'$write' => ['user:'.$userId],
|
||||
'email' => $email,
|
||||
'emailVerification' => true,
|
||||
'status' => Auth::USER_STATUS_ACTIVATED, // Email should already be authenticated by OAuth2 provider
|
||||
'status' => true, // Email should already be authenticated by OAuth2 provider
|
||||
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
||||
'passwordUpdate' => 0,
|
||||
'registration' => \time(),
|
||||
|
@ -491,7 +491,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
}
|
||||
}
|
||||
|
||||
if (Auth::USER_STATUS_BLOCKED == $user->getAttribute('status')) { // Account is blocked
|
||||
if (false === $user->getAttribute('status')) { // Account is blocked
|
||||
throw new Exception('Invalid credentials. User is blocked', 401); // User is in status blocked
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
}
|
||||
|
||||
$user
|
||||
->setAttribute('status', Auth::USER_STATUS_ACTIVATED)
|
||||
->setAttribute('status', true)
|
||||
->setAttribute('sessions', $session, Document::SET_TYPE_APPEND)
|
||||
;
|
||||
|
||||
|
@ -630,7 +630,7 @@ App::post('/v1/account/sessions/anonymous')
|
|||
'$write' => ['user:'.$userId],
|
||||
'email' => null,
|
||||
'emailVerification' => false,
|
||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||
'status' => true,
|
||||
'password' => null,
|
||||
'passwordUpdate' => \time(),
|
||||
'registration' => \time(),
|
||||
|
@ -1144,7 +1144,7 @@ App::delete('/v1/account')
|
|||
/** @var Appwrite\Event\Event $events */
|
||||
|
||||
$protocol = $request->getProtocol();
|
||||
$user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('status', Auth::USER_STATUS_BLOCKED));
|
||||
$user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('status', false));
|
||||
|
||||
//TODO delete all tokens or only current session?
|
||||
//TODO delete all user data according to GDPR. Make sure everything is backed up and backups are deleted later
|
||||
|
@ -1375,8 +1375,8 @@ App::post('/v1/account/recovery')
|
|||
throw new Exception('User not found', 404); // TODO maybe hide this
|
||||
}
|
||||
|
||||
if (Auth::USER_STATUS_BLOCKED == $profile->getAttribute('status')) { // Account is blocked
|
||||
throw new Exception('Invalid credentials. User is blocked', 401); // User is in status blocked
|
||||
if (false === $profile->getAttribute('status')) { // Account is blocked
|
||||
throw new Exception('Invalid credentials. User is blocked', 401);
|
||||
}
|
||||
|
||||
$expire = \time() + Auth::TOKEN_EXPIRATION_RECOVERY;
|
||||
|
|
|
@ -299,7 +299,7 @@ App::post('/v1/database/collections/:collectionId/attributes')
|
|||
$response->dynamic2($attribute, Response::MODEL_ATTRIBUTE);
|
||||
});
|
||||
|
||||
App::get('v1/database/collections/:collectionId/attributes')
|
||||
App::get('/v1/database/collections/:collectionId/attributes')
|
||||
->desc('List Attributes')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'attributes.read')
|
||||
|
@ -337,13 +337,13 @@ App::get('v1/database/collections/:collectionId/attributes')
|
|||
]), Response::MODEL_ATTRIBUTE_LIST);
|
||||
});
|
||||
|
||||
App::get('v1/database/collections/:collectionId/attributes/:attributeId')
|
||||
App::get('/v1/database/collections/:collectionId/attributes/:attributeId')
|
||||
->desc('Get Attribute')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'attributes.read')
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.platform', [APP_PLATFORM_SERVER])
|
||||
->label('sdk.method', 'listAttributes')
|
||||
->label('sdk.method', 'getAttribute')
|
||||
->label('sdk.description', '/docs/references/database/get-attribute.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
|
@ -530,7 +530,7 @@ App::post('/v1/database/collections/:collectionId/indexes')
|
|||
|
||||
});
|
||||
|
||||
App::get('v1/database/collections/:collectionId/indexes')
|
||||
App::get('/v1/database/collections/:collectionId/indexes')
|
||||
->desc('List Indexes')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'indexes.read')
|
||||
|
@ -568,13 +568,13 @@ App::get('v1/database/collections/:collectionId/indexes')
|
|||
]), Response::MODEL_INDEX_LIST);
|
||||
});
|
||||
|
||||
App::get('v1/database/collections/:collectionId/indexes/:indexId')
|
||||
App::get('/v1/database/collections/:collectionId/indexes/:indexId')
|
||||
->desc('Get Index')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'indexes.read')
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.platform', [APP_PLATFORM_SERVER])
|
||||
->label('sdk.method', 'listIndexes')
|
||||
->label('sdk.method', 'getIndex')
|
||||
->label('sdk.description', '/docs/references/database/get-index.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
|
|
|
@ -297,7 +297,7 @@ App::post('/v1/teams/:teamId/memberships')
|
|||
'$write' => ['user:'.$userId],
|
||||
'email' => $email,
|
||||
'emailVerification' => false,
|
||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||
'status' => true,
|
||||
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
||||
/**
|
||||
* Set the password update time to 0 for users created using
|
||||
|
|
|
@ -49,7 +49,7 @@ App::post('/v1/users')
|
|||
'$write' => ['user:'.$userId],
|
||||
'email' => $email,
|
||||
'emailVerification' => false,
|
||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||
'status' => true,
|
||||
'password' => Auth::passwordHash($password),
|
||||
'passwordUpdate' => \time(),
|
||||
'registration' => \time(),
|
||||
|
@ -321,7 +321,7 @@ App::patch('/v1/users/:userId/status')
|
|||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_USER)
|
||||
->param('userId', '', new UID(), 'User unique ID.')
|
||||
->param('status', '', new WhiteList([Auth::USER_STATUS_ACTIVATED, Auth::USER_STATUS_BLOCKED, Auth::USER_STATUS_UNACTIVATED], true, Validator::TYPE_INTEGER), 'User Status code. To activate the user pass '.Auth::USER_STATUS_ACTIVATED.', to block the user pass '.Auth::USER_STATUS_BLOCKED.' and for disabling the user pass '.Auth::USER_STATUS_UNACTIVATED)
|
||||
->param('status', null, new Boolean(true), 'User Status. To activate the user pass `true` and to block the user pass `false`')
|
||||
->inject('response')
|
||||
->inject('dbForInternal')
|
||||
->action(function ($userId, $status, $response, $dbForInternal) {
|
||||
|
@ -334,7 +334,7 @@ App::patch('/v1/users/:userId/status')
|
|||
throw new Exception('User not found', 404);
|
||||
}
|
||||
|
||||
$user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('status', (int)$status));
|
||||
$user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('status', (bool) $status));
|
||||
|
||||
$response->dynamic2($user, Response::MODEL_USER);
|
||||
});
|
||||
|
|
|
@ -229,7 +229,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons
|
|||
if ($key && $user->isEmpty()) {
|
||||
$user = new Document([
|
||||
'$id' => '',
|
||||
'status' => Auth::USER_STATUS_ACTIVATED,
|
||||
'status' => true,
|
||||
'email' => 'app.'.$project->getId().'@service.'.$request->getHostname(),
|
||||
'password' => '',
|
||||
'name' => $project->getAttribute('name', 'Untitled'),
|
||||
|
@ -273,8 +273,8 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons
|
|||
throw new Exception($user->getAttribute('email', 'User').' (role: '.\strtolower($roles[$role]['label']).') missing scope ('.$scope.')', 401);
|
||||
}
|
||||
|
||||
if (Auth::USER_STATUS_BLOCKED == $user->getAttribute('status')) { // Account has not been activated
|
||||
throw new Exception('Invalid credentials. User is blocked', 401); // User is in status blocked
|
||||
if (false === $user->getAttribute('status')) { // Account is blocked
|
||||
throw new Exception('Invalid credentials. User is blocked', 401);
|
||||
}
|
||||
|
||||
if ($user->getAttribute('reset')) {
|
||||
|
|
|
@ -85,15 +85,15 @@ $auth = $this->getParam('auth', []);
|
|||
<small data-ls-bind="{{user.email}}"></span>
|
||||
</td>
|
||||
<td data-title="Status: ">
|
||||
<span data-ls-if="{{user.emailVerification}} === true">
|
||||
<span data-ls-if="{{user.emailVerification}} === true && {{user.status}} === true">
|
||||
<span class="tag green">Verified</span>
|
||||
</span>
|
||||
|
||||
<span data-ls-if="{{user.emailVerification}} !== true">
|
||||
<span data-ls-if="{{user.emailVerification}} !== true && {{user.status}} === true">
|
||||
<span class="tag">Unverified</span>
|
||||
</span>
|
||||
|
||||
<span data-ls-if="{{user.status}} === <?php echo \Appwrite\Auth\Auth::USER_STATUS_BLOCKED; ?>">
|
||||
<span data-ls-if="{{user.status}} === false">
|
||||
<span class="tag red">Blocked</span>
|
||||
</span>
|
||||
</td>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<li data-state="/console/users/user?id={{router.params.id}}&project={{router.params.project}}">
|
||||
<h2>Overview</h2>
|
||||
|
||||
<div data-ls-if="{{user.status}} === <?php echo \Appwrite\Auth\Auth::USER_STATUS_BLOCKED; ?>" style="display: none" class="box padding-small danger margin-bottom-xxl text-align-center">
|
||||
<div data-ls-if="{{user.status}} === false" style="display: none" class="box padding-small danger margin-bottom-xxl text-align-center">
|
||||
This user account is blocked.
|
||||
</div>
|
||||
|
||||
|
@ -99,11 +99,11 @@
|
|||
|
||||
<div class="box danger margin-bottom">
|
||||
<p>This is the area where you can delete this user.</p>
|
||||
|
||||
|
||||
<p>By deleting this user you will lose all data associated with this user.</p>
|
||||
|
||||
|
||||
<p>PLEASE NOTE: User deletion is irreversible.</p>
|
||||
|
||||
|
||||
<form class="inline"
|
||||
data-analytics
|
||||
data-analytics-activity
|
||||
|
@ -122,7 +122,7 @@
|
|||
data-failure-param-alert-text="Failed to delete user"
|
||||
data-failure-param-alert-classname="error">
|
||||
<input type="hidden" name="projectId" data-ls-bind="{{router.params.project}}" />
|
||||
|
||||
|
||||
<button class="danger reverse" type="submit">Delete User</button>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -137,7 +137,7 @@
|
|||
<li class="margin-bottom-small"><i class="icon-angle-circled-right margin-start-tiny margin-end-tiny"></i> <button data-ls-ui-trigger="open-json" class="link text-size-small">View as JSON</button></li>
|
||||
</ul>
|
||||
|
||||
<div data-ls-if="{{user.status}} !== <?php echo \Appwrite\Auth\Auth::USER_STATUS_BLOCKED; ?>" style="display: none">
|
||||
<div data-ls-if="{{user.status}} === true" style="display: none">
|
||||
<form name="users.updateStatus" class="margin-bottom"
|
||||
data-analytics
|
||||
data-analytics-activity
|
||||
|
@ -154,11 +154,11 @@
|
|||
data-failure-param-alert-text="Failed to block user"
|
||||
data-failure-param-alert-classname="error">
|
||||
|
||||
<button name="status" type="submit" class="danger fill" value="<?php echo \Appwrite\Auth\Auth::USER_STATUS_BLOCKED; ?>" data-cast-to="integer">Block Account</button>
|
||||
<button name="status" type="submit" class="danger fill" value="false" data-cast-to="boolean">Block Account</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div data-ls-if="{{user.status}} === <?php echo \Appwrite\Auth\Auth::USER_STATUS_BLOCKED; ?>" style="display: none">
|
||||
<div data-ls-if="{{user.status}} === false" style="display: none">
|
||||
<form name="users.updateStatus" class="margin-bottom"
|
||||
data-analytics
|
||||
data-analytics-activity
|
||||
|
@ -175,7 +175,7 @@
|
|||
data-failure-param-alert-text="Failed to activate user"
|
||||
data-failure-param-alert-classname="error">
|
||||
|
||||
<button name="status" type="submit" class="fill" value="<?php echo \Appwrite\Auth\Auth::USER_STATUS_ACTIVATED; ?>" data-cast-to="integer">Activate Account</button>
|
||||
<button name="status" type="submit" class="fill" value="true" data-cast-to="boolean">Activate Account</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
"appwrite/php-clamav": "1.1.*",
|
||||
"appwrite/php-runtimes": "0.4.*",
|
||||
|
||||
"utopia-php/framework": "0.14.*",
|
||||
"utopia-php/framework": "0.16.*",
|
||||
"utopia-php/abuse": "dev-feat-utopia-db-integration",
|
||||
"utopia-php/analytics": "0.2.*",
|
||||
"utopia-php/audit": "dev-feat-utopia-db-integration",
|
||||
|
|
14
composer.lock
generated
14
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "a063a86696ef1a87348afe4aaaa2eb69",
|
||||
"content-hash": "ea49a8cc41d837be81393c1457051bcb",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/jwt",
|
||||
|
@ -2079,16 +2079,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/framework",
|
||||
"version": "0.14.1",
|
||||
"version": "0.16.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/framework.git",
|
||||
"reference": "632113288bebe41cbef79f0d355bd91609767b8c"
|
||||
"reference": "e7440b91077ccf2f4f3908fde4f31d177f8ea692"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/632113288bebe41cbef79f0d355bd91609767b8c",
|
||||
"reference": "632113288bebe41cbef79f0d355bd91609767b8c",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/e7440b91077ccf2f4f3908fde4f31d177f8ea692",
|
||||
"reference": "e7440b91077ccf2f4f3908fde4f31d177f8ea692",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2122,9 +2122,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/framework/issues",
|
||||
"source": "https://github.com/utopia-php/framework/tree/0.14.1"
|
||||
"source": "https://github.com/utopia-php/framework/tree/0.16.1"
|
||||
},
|
||||
"time": "2021-05-21T06:41:45+00:00"
|
||||
"time": "2021-07-18T10:59:00+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/image",
|
||||
|
|
|
@ -6,13 +6,6 @@ use Appwrite\Database\Document;
|
|||
|
||||
class Auth
|
||||
{
|
||||
/**
|
||||
* User Status.
|
||||
*/
|
||||
const USER_STATUS_UNACTIVATED = 0;
|
||||
const USER_STATUS_ACTIVATED = 1;
|
||||
const USER_STATUS_BLOCKED = 2;
|
||||
|
||||
/**
|
||||
* User Roles.
|
||||
*/
|
||||
|
|
52
src/Appwrite/Migration/Version/V09.php
Normal file
52
src/Appwrite/Migration/Version/V09.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Migration\Version;
|
||||
|
||||
use Appwrite\Migration\Migration;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\CLI\Console;
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Document;
|
||||
|
||||
class V09 extends Migration
|
||||
{
|
||||
public function execute(): void
|
||||
{
|
||||
$project = $this->project;
|
||||
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
|
||||
|
||||
$this->forEachDocument([$this, 'fixDocument']);
|
||||
}
|
||||
|
||||
protected function fixDocument(Document $document)
|
||||
{
|
||||
switch ($document->getAttribute('$collection')) {
|
||||
case Database::SYSTEM_COLLECTION_USERS:
|
||||
/**
|
||||
* Remove deprecated user status 0 and replace with boolean.
|
||||
*/
|
||||
if ($document->getAttribute('status') === 0 || $document->getAttribute('status') === 1) {
|
||||
$document->setAttribute('status', true);
|
||||
}
|
||||
if ($document->getAttribute('status') === 2) {
|
||||
$document->setAttribute('status', false);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($document as &$attr) {
|
||||
if ($attr instanceof Document) {
|
||||
$attr = $this->fixDocument($attr);
|
||||
}
|
||||
|
||||
if (\is_array($attr)) {
|
||||
foreach ($attr as &$child) {
|
||||
if ($child instanceof Document) {
|
||||
$child = $this->fixDocument($child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
}
|
|
@ -327,7 +327,7 @@ class V06 extends Filter {
|
|||
$content['oauth2'.ucfirst($key)] = '';
|
||||
$content['oauth2'.ucfirst($key).'AccessToken'] = '';
|
||||
}
|
||||
$content['status'] = empty($content['status']) ? 0 : $content['status'];
|
||||
$content['status'] = $content['status'] ? 0 : 2;
|
||||
$content['roles'] = Authorization::getRoles() ?? [];
|
||||
return $content;
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ class User extends Model
|
|||
'example' => 1592981250,
|
||||
])
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'User status. 0 for Unactivated, 1 for active and 2 is blocked.',
|
||||
'default' => 0,
|
||||
'example' => 0,
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'User status. Pass `true` for enabled and `false` for disabled.',
|
||||
'default' => true,
|
||||
'example' => true,
|
||||
])
|
||||
->addRule('passwordUpdate', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
|
|
|
@ -102,7 +102,7 @@ class AccountCustomClientTest extends Scope
|
|||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'status' => 2,
|
||||
'status' => false,
|
||||
]);
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
|
|
|
@ -23,7 +23,7 @@ trait UsersBase
|
|||
$this->assertEquals($user['headers']['status-code'], 201);
|
||||
$this->assertEquals($user['body']['name'], 'Project User');
|
||||
$this->assertEquals($user['body']['email'], 'users.service@example.com');
|
||||
$this->assertEquals($user['body']['status'], 0);
|
||||
$this->assertEquals($user['body']['status'], true);
|
||||
$this->assertGreaterThan(0, $user['body']['registration']);
|
||||
|
||||
return ['userId' => $user['body']['$id']];
|
||||
|
@ -45,7 +45,7 @@ trait UsersBase
|
|||
$this->assertEquals($user['headers']['status-code'], 200);
|
||||
$this->assertEquals($user['body']['name'], 'Project User');
|
||||
$this->assertEquals($user['body']['email'], 'users.service@example.com');
|
||||
$this->assertEquals($user['body']['status'], 0);
|
||||
$this->assertEquals($user['body']['status'], true);
|
||||
$this->assertGreaterThan(0, $user['body']['registration']);
|
||||
|
||||
$sessions = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/sessions', array_merge([
|
||||
|
@ -105,11 +105,11 @@ trait UsersBase
|
|||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'status' => 2,
|
||||
'status' => false,
|
||||
]);
|
||||
|
||||
$this->assertEquals($user['headers']['status-code'], 200);
|
||||
$this->assertEquals($user['body']['status'], 2);
|
||||
$this->assertEquals($user['body']['status'], false);
|
||||
|
||||
$user = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
@ -117,7 +117,7 @@ trait UsersBase
|
|||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($user['headers']['status-code'], 200);
|
||||
$this->assertEquals($user['body']['status'], 2);
|
||||
$this->assertEquals($user['body']['status'], false);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class WebhooksCustomClientTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $name);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 0);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], []);
|
||||
|
@ -119,7 +119,7 @@ class WebhooksCustomClientTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $name);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 2);
|
||||
$this->assertEquals($webhook['data']['status'], false);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], []);
|
||||
|
@ -389,7 +389,7 @@ class WebhooksCustomClientTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $newName);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 0);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], []);
|
||||
|
@ -433,7 +433,7 @@ class WebhooksCustomClientTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], 'New Name');
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 0);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], []);
|
||||
|
@ -479,7 +479,7 @@ class WebhooksCustomClientTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], 'New Name');
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 0);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $newEmail);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], []);
|
||||
|
@ -526,7 +526,7 @@ class WebhooksCustomClientTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], 'New Name');
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 0);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], [
|
||||
|
|
|
@ -194,7 +194,7 @@ class WebhooksCustomServerTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $name);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 0);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], []);
|
||||
|
@ -250,7 +250,7 @@ class WebhooksCustomServerTest extends Scope
|
|||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'status' => 2,
|
||||
'status' => false,
|
||||
]);
|
||||
|
||||
$this->assertEquals($user['headers']['status-code'], 200);
|
||||
|
@ -269,7 +269,7 @@ class WebhooksCustomServerTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $data['name']);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 2);
|
||||
$this->assertEquals($webhook['data']['status'], false);
|
||||
$this->assertEquals($webhook['data']['email'], $data['email']);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs']['a'], 'b');
|
||||
|
@ -305,7 +305,7 @@ class WebhooksCustomServerTest extends Scope
|
|||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $data['name']);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], 2);
|
||||
$this->assertEquals($webhook['data']['status'], false);
|
||||
$this->assertEquals($webhook['data']['email'], $data['email']);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs']['a'], 'b');
|
||||
|
|
|
@ -141,7 +141,7 @@ class WebhooksTest extends Scope
|
|||
|
||||
$this->assertNotEmpty($webhook['data']);
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertIsNumeric($webhook['data']['status']);
|
||||
$this->assertIsBool($webhook['data']['status']);
|
||||
$this->assertIsNumeric($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['name'], $name);
|
||||
|
|
50
tests/unit/Migration/MigrationV09Test.php
Normal file
50
tests/unit/Migration/MigrationV09Test.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use ReflectionClass;
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Document;
|
||||
use Appwrite\Migration\Version\V09;
|
||||
|
||||
class MigrationV09Test extends MigrationTest
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->pdo = new \PDO('sqlite::memory:');
|
||||
$this->migration = new V09($this->pdo);
|
||||
$reflector = new ReflectionClass('Appwrite\Migration\Version\V09');
|
||||
$this->method = $reflector->getMethod('fixDocument');
|
||||
$this->method->setAccessible(true);
|
||||
}
|
||||
|
||||
public function testMigration()
|
||||
{
|
||||
$document = $this->fixDocument(new Document([
|
||||
'$id' => uniqid(),
|
||||
'$collection' => Database::SYSTEM_COLLECTION_USERS,
|
||||
'status' => 0
|
||||
]));
|
||||
|
||||
$this->assertIsBool($document->getAttribute('status'));
|
||||
$this->assertEquals(true, $document->getAttribute('status', false));
|
||||
|
||||
$document = $this->fixDocument(new Document([
|
||||
'$id' => uniqid(),
|
||||
'$collection' => Database::SYSTEM_COLLECTION_USERS,
|
||||
'status' => 1
|
||||
]));
|
||||
|
||||
$this->assertIsBool($document->getAttribute('status'));
|
||||
$this->assertEquals(true, $document->getAttribute('status', false));
|
||||
|
||||
$document = $this->fixDocument(new Document([
|
||||
'$id' => uniqid(),
|
||||
'$collection' => Database::SYSTEM_COLLECTION_USERS,
|
||||
'status' => 2
|
||||
]));
|
||||
|
||||
$this->assertIsBool($document->getAttribute('status'));
|
||||
$this->assertEquals(false, $document->getAttribute('status', false));
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ class V06Test extends TestCase
|
|||
'$id' => '5e5ea5c16897e',
|
||||
'name' => 'John Doe',
|
||||
'registration' => 1592981250,
|
||||
'status' => 0,
|
||||
'status' => true,
|
||||
'email' => 'john@appwrite.io',
|
||||
'emailVerification' => false,
|
||||
'prefs' => [
|
||||
|
@ -51,7 +51,6 @@ class V06Test extends TestCase
|
|||
$this->assertEquals($parsedResponse['email'], 'john@appwrite.io');
|
||||
$this->assertEquals($parsedResponse['emailVerification'], false);
|
||||
$this->assertEquals($parsedResponse['prefs'], ['theme' => 'pink', 'timezone' => 'UTC']);
|
||||
$this->assertEquals($parsedResponse['status'], 0);
|
||||
$this->assertEquals($parsedResponse['roles'], Authorization::getRoles() ?? []);
|
||||
}
|
||||
|
||||
|
@ -64,7 +63,7 @@ class V06Test extends TestCase
|
|||
'$id' => '5e5ea5c16897e',
|
||||
'name' => 'John Doe',
|
||||
'registration' => 1592981250,
|
||||
'status' => 0,
|
||||
'status' => true,
|
||||
'email' => 'john@appwrite.io',
|
||||
'emailVerification' => false,
|
||||
'prefs' => [
|
||||
|
@ -88,7 +87,6 @@ class V06Test extends TestCase
|
|||
$this->assertEquals($parsedResponse['users'][0]['email'], 'john@appwrite.io');
|
||||
$this->assertEquals($parsedResponse['users'][0]['emailVerification'], false);
|
||||
$this->assertEquals($parsedResponse['users'][0]['prefs'], ['theme' => 'pink', 'timezone' => 'UTC']);
|
||||
$this->assertEquals($parsedResponse['users'][0]['status'], 0);
|
||||
$this->assertEquals($parsedResponse['users'][0]['roles'], Authorization::getRoles() ?? []);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue