SubQuery test
This commit is contained in:
parent
7859f35612
commit
5ba2ba4c4c
|
@ -80,7 +80,7 @@ $collections = [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'signed' => true,
|
'signed' => true,
|
||||||
'array' => false,
|
'array' => false,
|
||||||
'filters' => ['json'],
|
'filters' => ['subQuery'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'$id' => 'indexes',
|
'$id' => 'indexes',
|
||||||
|
@ -119,6 +119,17 @@ $collections = [
|
||||||
'$id' => 'attributes',
|
'$id' => 'attributes',
|
||||||
'name' => 'Attributes',
|
'name' => 'Attributes',
|
||||||
'attributes' => [
|
'attributes' => [
|
||||||
|
[
|
||||||
|
'$id' => 'collectionId',
|
||||||
|
'type' => Database::VAR_STRING,
|
||||||
|
'format' => '',
|
||||||
|
'size' => Database::LENGTH_KEY,
|
||||||
|
'signed' => true,
|
||||||
|
'required' => false,
|
||||||
|
'default' => null,
|
||||||
|
'array' => false,
|
||||||
|
'filters' => [],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'$id' => 'type',
|
'$id' => 'type',
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
|
@ -163,6 +174,17 @@ $collections = [
|
||||||
'array' => false,
|
'array' => false,
|
||||||
'filters' => [],
|
'filters' => [],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'$id' => 'default',
|
||||||
|
'type' => Database::VAR_STRING,
|
||||||
|
'format' => '',
|
||||||
|
'size' => 16384,
|
||||||
|
'signed' => true,
|
||||||
|
'required' => false,
|
||||||
|
'default' => null,
|
||||||
|
'array' => false,
|
||||||
|
'filters' => [],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'$id' => 'signed',
|
'$id' => 'signed',
|
||||||
'type' => Database::VAR_BOOLEAN,
|
'type' => Database::VAR_BOOLEAN,
|
||||||
|
@ -180,7 +202,7 @@ $collections = [
|
||||||
'signed' => true,
|
'signed' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'default' => null,
|
'default' => null,
|
||||||
'array' => true,
|
'array' => false,
|
||||||
'filters' => [],
|
'filters' => [],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -190,11 +212,35 @@ $collections = [
|
||||||
'signed' => true,
|
'signed' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'default' => null,
|
'default' => null,
|
||||||
'array' => true,
|
'array' => false,
|
||||||
'filters' => ['json'],
|
'filters' => ['json'],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'$id' => 'filters',
|
||||||
|
'type' => Database::VAR_STRING,
|
||||||
|
'size' => 64,
|
||||||
|
'signed' => true,
|
||||||
|
'required' => false,
|
||||||
|
'default' => null,
|
||||||
|
'array' => true,
|
||||||
|
'filters' => [],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'indexes' => [
|
'indexes' => [
|
||||||
|
// [
|
||||||
|
// '$id' => '_key_unique',
|
||||||
|
// 'type' => Database::INDEX_UNIQUE,
|
||||||
|
// 'attributes' => ['_id', 'collectionId'],
|
||||||
|
// 'lengths' => [Database::LENGTH_KEY, Database::LENGTH_KEY],
|
||||||
|
// 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC],
|
||||||
|
// ],
|
||||||
|
[
|
||||||
|
'$id' => '_key_collection',
|
||||||
|
'type' => Database::INDEX_KEY,
|
||||||
|
'attributes' => ['collectionId'],
|
||||||
|
'lengths' => [Database::LENGTH_KEY],
|
||||||
|
'orders' => [Database::ORDER_ASC],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ $attributesCallback = function ($collectionId, $attribute, $response, $dbForInte
|
||||||
|
|
||||||
$attribute = $dbForInternal->createDocument('attributes', new Document([
|
$attribute = $dbForInternal->createDocument('attributes', new Document([
|
||||||
'$id' => $attributeId,
|
'$id' => $attributeId,
|
||||||
|
'collectionId' => $collectionId,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'status' => 'processing', // processing, available, failed
|
'status' => 'processing', // processing, available, failed
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
|
|
35
app/init.php
35
app/init.php
|
@ -23,7 +23,6 @@ use Appwrite\Auth\Auth;
|
||||||
use Appwrite\Database\Database;
|
use Appwrite\Database\Database;
|
||||||
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||||
use Appwrite\Database\Document;
|
|
||||||
use Appwrite\Event\Event;
|
use Appwrite\Event\Event;
|
||||||
use Appwrite\Network\Validator\Email;
|
use Appwrite\Network\Validator\Email;
|
||||||
use Appwrite\Network\Validator\IP;
|
use Appwrite\Network\Validator\IP;
|
||||||
|
@ -40,7 +39,7 @@ use PHPMailer\PHPMailer\PHPMailer;
|
||||||
use Utopia\Cache\Adapter\Redis as RedisCache;
|
use Utopia\Cache\Adapter\Redis as RedisCache;
|
||||||
use Utopia\Cache\Cache;
|
use Utopia\Cache\Cache;
|
||||||
use Utopia\Database\Adapter\MariaDB;
|
use Utopia\Database\Adapter\MariaDB;
|
||||||
use Utopia\Database\Document as Document2;
|
use Utopia\Database\Document;
|
||||||
use Utopia\Database\Database as Database2;
|
use Utopia\Database\Database as Database2;
|
||||||
use Utopia\Database\Validator\Structure;
|
use Utopia\Database\Validator\Structure;
|
||||||
use Utopia\Database\Validator\Authorization;
|
use Utopia\Database\Validator\Authorization;
|
||||||
|
@ -49,6 +48,7 @@ use Swoole\Database\PDOConfig;
|
||||||
use Swoole\Database\PDOPool;
|
use Swoole\Database\PDOPool;
|
||||||
use Swoole\Database\RedisConfig;
|
use Swoole\Database\RedisConfig;
|
||||||
use Swoole\Database\RedisPool;
|
use Swoole\Database\RedisPool;
|
||||||
|
use Utopia\Database\Query;
|
||||||
|
|
||||||
const APP_NAME = 'Appwrite';
|
const APP_NAME = 'Appwrite';
|
||||||
const APP_DOMAIN = 'appwrite.io';
|
const APP_DOMAIN = 'appwrite.io';
|
||||||
|
@ -138,6 +138,7 @@ if(!empty($user) || !empty($pass)) {
|
||||||
} else {
|
} else {
|
||||||
Resque::setBackend(App::getEnv('_APP_REDIS_HOST', '').':'.App::getEnv('_APP_REDIS_PORT', ''));
|
Resque::setBackend(App::getEnv('_APP_REDIS_HOST', '').':'.App::getEnv('_APP_REDIS_PORT', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DB Filters
|
* DB Filters
|
||||||
*/
|
*/
|
||||||
|
@ -175,6 +176,18 @@ Database::addFilter('encrypt',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Database2::addFilter('subQuery',
|
||||||
|
function($value) {
|
||||||
|
return $value;
|
||||||
|
},
|
||||||
|
function($value, Document $document, Document $collection, Database2 $database) {
|
||||||
|
return $database
|
||||||
|
->find('attributes', [
|
||||||
|
new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()])
|
||||||
|
], 100, 0, ['_id']);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
Database2::addFilter('encrypt',
|
Database2::addFilter('encrypt',
|
||||||
function($value) {
|
function($value) {
|
||||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||||
|
@ -196,6 +209,9 @@ Database2::addFilter('encrypt',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DB Formats
|
||||||
|
*/
|
||||||
Structure::addFormat('email', function() {
|
Structure::addFormat('email', function() {
|
||||||
return new Email();
|
return new Email();
|
||||||
}, Database2::VAR_STRING);
|
}, Database2::VAR_STRING);
|
||||||
|
@ -292,7 +308,6 @@ $register->set('statsd', function () { // Register DB connection
|
||||||
|
|
||||||
return $statsd;
|
return $statsd;
|
||||||
});
|
});
|
||||||
|
|
||||||
$register->set('smtp', function () {
|
$register->set('smtp', function () {
|
||||||
$mail = new PHPMailer(true);
|
$mail = new PHPMailer(true);
|
||||||
|
|
||||||
|
@ -440,8 +455,8 @@ App::setResource('database', function($register) {
|
||||||
|
|
||||||
// Test Mock
|
// Test Mock
|
||||||
App::setResource('clients', function($request, $console, $project) {
|
App::setResource('clients', function($request, $console, $project) {
|
||||||
$console->setAttribute('platforms', [ // Allways allow current host
|
$console->setAttribute('platforms', [ // Always allow current host
|
||||||
'$collection' => Database::SYSTEM_COLLECTION_PLATFORMS,
|
'$collection' => 'platforms',
|
||||||
'name' => 'Current Host',
|
'name' => 'Current Host',
|
||||||
'type' => 'web',
|
'type' => 'web',
|
||||||
'hostname' => $request->getHostname(),
|
'hostname' => $request->getHostname(),
|
||||||
|
@ -509,7 +524,7 @@ App::setResource('user', function($mode, $project, $console, $request, $response
|
||||||
|
|
||||||
if (APP_MODE_ADMIN !== $mode) {
|
if (APP_MODE_ADMIN !== $mode) {
|
||||||
if ($project->isEmpty()) {
|
if ($project->isEmpty()) {
|
||||||
$user = new Document2(['$id' => '', '$collection' => 'users']);
|
$user = new Document(['$id' => '', '$collection' => 'users']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$user = $dbForInternal->getDocument('users', Auth::$unique);
|
$user = $dbForInternal->getDocument('users', Auth::$unique);
|
||||||
|
@ -521,14 +536,14 @@ App::setResource('user', function($mode, $project, $console, $request, $response
|
||||||
|
|
||||||
if ($user->isEmpty() // Check a document has been found in the DB
|
if ($user->isEmpty() // Check a document has been found in the DB
|
||||||
|| !Auth::sessionVerify($user->getAttribute('sessions', []), Auth::$secret)) { // Validate user has valid login token
|
|| !Auth::sessionVerify($user->getAttribute('sessions', []), Auth::$secret)) { // Validate user has valid login token
|
||||||
$user = new Document2(['$id' => '', '$collection' => 'users']);
|
$user = new Document(['$id' => '', '$collection' => 'users']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (APP_MODE_ADMIN === $mode) {
|
if (APP_MODE_ADMIN === $mode) {
|
||||||
if ($user->find('teamId', $project->getAttribute('teamId'), 'memberships')) {
|
if ($user->find('teamId', $project->getAttribute('teamId'), 'memberships')) {
|
||||||
Authorization::setDefaultStatus(false); // Cancel security segmentation for admin users.
|
Authorization::setDefaultStatus(false); // Cancel security segmentation for admin users.
|
||||||
} else {
|
} else {
|
||||||
$user = new Document2(['$id' => '', '$collection' => 'users']);
|
$user = new Document(['$id' => '', '$collection' => 'users']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +566,7 @@ App::setResource('user', function($mode, $project, $console, $request, $response
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token
|
if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token
|
||||||
$user = new Document2(['$id' => '', '$collection' => 'users']);
|
$user = new Document(['$id' => '', '$collection' => 'users']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,7 +595,7 @@ App::setResource('project', function($dbForConsole, $request, $console) {
|
||||||
}, ['dbForConsole', 'request', 'console']);
|
}, ['dbForConsole', 'request', 'console']);
|
||||||
|
|
||||||
App::setResource('console', function() {
|
App::setResource('console', function() {
|
||||||
return new Document2([
|
return new Document([
|
||||||
'$id' => 'console',
|
'$id' => 'console',
|
||||||
'name' => 'Appwrite',
|
'name' => 'Appwrite',
|
||||||
'$collection' => 'projects',
|
'$collection' => 'projects',
|
||||||
|
|
|
@ -33,7 +33,7 @@ $interval = floor((int)$this->getParam('interval', 0) / 86400);
|
||||||
<span data-ls-if="{{log.userName|escape}} === '' && {{log.userEmail}} !== '' && {{log.mode}} !== 'key'"><i class="icon-user"></i> Unknown</span>
|
<span data-ls-if="{{log.userName|escape}} === '' && {{log.userEmail}} !== '' && {{log.mode}} !== 'key'"><i class="icon-user"></i> Unknown</span>
|
||||||
<span data-ls-if="{{log.userName|escape}} === '' && {{log.userEmail}} === '' && {{log.mode}} !== 'key'"><i class="icon-user"></i> Anonymous User</span>
|
<span data-ls-if="{{log.userName|escape}} === '' && {{log.userEmail}} === '' && {{log.mode}} !== 'key'"><i class="icon-user"></i> Anonymous User</span>
|
||||||
<span data-ls-if="{{log.mode}} === 'admin'">
|
<span data-ls-if="{{log.mode}} === 'admin'">
|
||||||
<img src="" data-ls-attrs="src={{log.userName|avatar}}" data-size="45" alt="User Avatar" class="avatar xxs inline margin-end-small" loading="lazy" width="30" height="30" /> <span data-ls-bind="{{log.userName}} (Admin)"></span></span>
|
<img src="" data-ls-attrs="src={{log.userName|avatar}}" data-size="45" alt="User Avatar" class="avatar xxs inline margin-end-small" loading="lazy" width="30" height="30" /> <span data-ls-bind="{{log.userName}} (Admin)"></span></span>
|
||||||
<span data-ls-if="{{log.mode}} === 'key'"> <i class="icon-key"></i> API Key</span>
|
<span data-ls-if="{{log.mode}} === 'key'"> <i class="icon-key"></i> API Key</span>
|
||||||
</td>
|
</td>
|
||||||
<td data-title="Event: "><span data-ls-bind="{{log.event}}"></span></td>
|
<td data-title="Event: "><span data-ls-bind="{{log.event}}"></span></td>
|
||||||
|
|
|
@ -63,7 +63,7 @@ services:
|
||||||
- ./psalm.xml:/usr/src/code/psalm.xml
|
- ./psalm.xml:/usr/src/code/psalm.xml
|
||||||
- ./tests:/usr/src/code/tests
|
- ./tests:/usr/src/code/tests
|
||||||
- ./app:/usr/src/code/app
|
- ./app:/usr/src/code/app
|
||||||
# - ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
||||||
- ./docs:/usr/src/code/docs
|
- ./docs:/usr/src/code/docs
|
||||||
- ./public:/usr/src/code/public
|
- ./public:/usr/src/code/public
|
||||||
- ./src:/usr/src/code/src
|
- ./src:/usr/src/code/src
|
||||||
|
|
Loading…
Reference in a new issue