Work in progress - projects controller
This commit is contained in:
parent
e1ce368f66
commit
814ac68d49
|
@ -7,6 +7,186 @@ $providers = Config::getParam('providers', []);
|
|||
$auth = Config::getParam('auth', []);
|
||||
|
||||
$collections = [
|
||||
'projects' => [
|
||||
'$collection' => Database::COLLECTIONS,
|
||||
'$id' => 'projects',
|
||||
'name' => 'Projects',
|
||||
'attributes' => [
|
||||
[
|
||||
'$id' => 'name',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 128,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'description',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'teamId',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'logo',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => Database::LENGTH_KEY,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'url',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'usersAuthLimit',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'legalName',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'legalCountry',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'legalState',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'legalCity',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'legalAddress',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'legalTaxId',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 256,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => 'platforms',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => 'webhooks',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => 'keys',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => 'tasks',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => 'domains',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => true,
|
||||
'filters' => ['json'],
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
],
|
||||
],
|
||||
|
||||
'users' => [
|
||||
'$collection' => Database::COLLECTIONS,
|
||||
'$id' => 'users',
|
||||
|
@ -760,4 +940,48 @@ $collections = [
|
|||
],
|
||||
];
|
||||
|
||||
/*
|
||||
* Add enabled OAuth2 providers to default data rules
|
||||
*/
|
||||
foreach ($providers as $index => $provider) {
|
||||
if (!$provider['enabled']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$collections['projects']['attributes'][] = [
|
||||
'$id' => 'usersOauth2'.\ucfirst($index).'Appid',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
];
|
||||
|
||||
$collections['projects']['attributes'][] = [
|
||||
'$id' => 'usersOauth2'.\ucfirst($index).'Secret',
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 16384,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($auth as $index => $method) {
|
||||
$collections['projects']['attributes'][] = [
|
||||
'$id' => $method['key'] ?? '',
|
||||
'type' => Database::VAR_BOOLEAN,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
];
|
||||
}
|
||||
|
||||
return $collections;
|
File diff suppressed because it is too large
Load diff
|
@ -17,6 +17,7 @@ use Appwrite\Network\Validator\Origin;
|
|||
use Appwrite\Utopia\Response\Filters\V06;
|
||||
use Appwrite\Utopia\Response\Filters\V07;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\Document as Document2;
|
||||
use Utopia\Database\Validator\Authorization as Authorization2;
|
||||
|
||||
Config::setParam('domainVerification', false);
|
||||
|
@ -28,11 +29,11 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
|
|||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $consoleDB */
|
||||
/** @var Appwrite\Database\Document $console */
|
||||
/** @var Appwrite\Database\Document $project */
|
||||
/** @var Appwrite\Database\Document $user */
|
||||
/** @var Utopia\Database\Document $project */
|
||||
/** @var Utopia\Database\Document $user */
|
||||
/** @var Utopia\Locale\Locale $locale */
|
||||
/** @var array $clients */
|
||||
|
||||
|
||||
$domain = $request->getHostname();
|
||||
$domains = Config::getParam('domains', []);
|
||||
if (!array_key_exists($domain, $domains)) {
|
||||
|
@ -129,8 +130,8 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
|
|||
);
|
||||
|
||||
/*
|
||||
* Response format
|
||||
*/
|
||||
* Response format
|
||||
*/
|
||||
$responseFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', ''));
|
||||
if ($responseFormat) {
|
||||
switch($responseFormat) {
|
||||
|
@ -192,7 +193,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
|
|||
$role = ($user->isEmpty()) ? Auth::USER_ROLE_GUEST : Auth::USER_ROLE_MEMBER;
|
||||
|
||||
// Add user roles
|
||||
$membership = $user->search('teamId', $project->getAttribute('teamId', null), $user->getAttribute('memberships', []));
|
||||
$membership = $user->find('teamId', $project->getAttribute('teamId', null), 'memberships');
|
||||
|
||||
if ($membership) {
|
||||
foreach ($membership->getAttribute('roles', []) as $memberRole) {
|
||||
|
@ -218,14 +219,14 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
|
|||
|
||||
if (!empty($authKey)) { // API Key authentication
|
||||
// Check if given key match project API keys
|
||||
$key = $project->search('secret', $authKey, $project->getAttribute('keys', []));
|
||||
$key = $project->find('secret', $authKey, 'keys');
|
||||
|
||||
/*
|
||||
* Try app auth when we have project key and no user
|
||||
* Mock user to app and grant API key scopes in addition to default app scopes
|
||||
*/
|
||||
if ($key && $user->isEmpty()) {
|
||||
$user = new Document([
|
||||
$user = new Document2([
|
||||
'$id' => '',
|
||||
'status' => Auth::USER_STATUS_ACTIVATED,
|
||||
'email' => 'app.'.$project->getId().'@service.'.$request->getHostname(),
|
||||
|
|
14
app/init.php
14
app/init.php
|
@ -33,6 +33,7 @@ use PDO as PDONative;
|
|||
use Utopia\Cache\Adapter\Redis as RedisCache;
|
||||
use Utopia\Cache\Cache;
|
||||
use Utopia\Database\Adapter\MariaDB;
|
||||
use Utopia\Database\Document as Document2;
|
||||
use Utopia\Database\Database as Database2;
|
||||
use Utopia\Database\Validator\Authorization as Authorization2;
|
||||
|
||||
|
@ -455,18 +456,17 @@ App::setResource('user', function($mode, $project, $console, $request, $response
|
|||
;
|
||||
}
|
||||
|
||||
if (empty($user->getId()) // Check a document has been found in the DB
|
||||
|| Database::SYSTEM_COLLECTION_USERS !== $user->getCollection() // Validate returned document is really a user document
|
||||
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
|
||||
$user = new Document(['$id' => '', '$collection' => Database::SYSTEM_COLLECTION_USERS]);
|
||||
$user = new Document2(['$id' => '', '$collection' => 'users']);
|
||||
}
|
||||
|
||||
if (APP_MODE_ADMIN === $mode) {
|
||||
if (!empty($user->search('teamId', $project->getAttribute('teamId'), $user->getAttribute('memberships')))) {
|
||||
if (!$user->find('teamId', $project->getAttribute('teamId'), 'memberships')) {
|
||||
Authorization::setDefaultStatus(false); // Cancel security segmentation for admin users.
|
||||
Authorization2::setDefaultStatus(false); // Cancel security segmentation for admin users.
|
||||
} else {
|
||||
$user = new Document(['$id' => '', '$collection' => Database::SYSTEM_COLLECTION_USERS]);
|
||||
$user = new Document2(['$id' => '', '$collection' => 'users']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -488,8 +488,8 @@ App::setResource('user', function($mode, $project, $console, $request, $response
|
|||
$user = $dbForInternal->getDocument('users', $jwtUserId);
|
||||
}
|
||||
|
||||
if (empty($user->search('$id', $jwtSessionId, $user->getAttribute('sessions')))) { // Match JWT to active token
|
||||
$user = new Document(['$id' => '', '$collection' => 'users']);
|
||||
if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token
|
||||
$user = new Document2(['$id' => '', '$collection' => 'users']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
"utopia-php/cache": "0.4.*",
|
||||
"utopia-php/cli": "0.11.*",
|
||||
"utopia-php/config": "0.2.*",
|
||||
"utopia-php/database": "v0.x-dev",
|
||||
"utopia-php/database": "dev-feat-new-doc-methods",
|
||||
"utopia-php/locale": "0.3.*",
|
||||
"utopia-php/registry": "0.4.*",
|
||||
"utopia-php/preloader": "0.2.*",
|
||||
|
|
44
composer.lock
generated
44
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": "e1d74c5addc00532630652439c858347",
|
||||
"content-hash": "1d24d85bcbddad6834435b58286703ca",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/jwt",
|
||||
|
@ -1919,11 +1919,11 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/database",
|
||||
"version": "v0.x-dev",
|
||||
"version": "dev-feat-new-doc-methods",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database",
|
||||
"reference": "d54bbae93fea9f60df535e4f669146e24d87761b"
|
||||
"reference": "fe6e0ca2ff26b721516a8db83bff378f428a2caf"
|
||||
},
|
||||
"require": {
|
||||
"ext-mongodb": "*",
|
||||
|
@ -1970,7 +1970,7 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2021-05-09T13:42:23+00:00"
|
||||
"time": "2021-05-15T15:00:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
|
@ -5235,16 +5235,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/console",
|
||||
"version": "v5.2.7",
|
||||
"version": "v5.2.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/console.git",
|
||||
"reference": "90374b8ed059325b49a29b55b3f8bb4062c87629"
|
||||
"reference": "864568fdc0208b3eba3638b6000b69d2386e6768"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/90374b8ed059325b49a29b55b3f8bb4062c87629",
|
||||
"reference": "90374b8ed059325b49a29b55b3f8bb4062c87629",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/864568fdc0208b3eba3638b6000b69d2386e6768",
|
||||
"reference": "864568fdc0208b3eba3638b6000b69d2386e6768",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -5312,7 +5312,7 @@
|
|||
"terminal"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/console/tree/v5.2.7"
|
||||
"source": "https://github.com/symfony/console/tree/v5.2.8"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -5328,7 +5328,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-04-19T14:07:32+00:00"
|
||||
"time": "2021-05-11T15:45:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-intl-grapheme",
|
||||
|
@ -5735,16 +5735,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/string",
|
||||
"version": "v5.2.6",
|
||||
"version": "v5.2.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/string.git",
|
||||
"reference": "ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572"
|
||||
"reference": "01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572",
|
||||
"reference": "ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db",
|
||||
"reference": "01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -5798,7 +5798,7 @@
|
|||
"utf8"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/string/tree/v5.2.6"
|
||||
"source": "https://github.com/symfony/string/tree/v5.2.8"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -5814,7 +5814,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-03-17T17:12:15+00:00"
|
||||
"time": "2021-05-10T14:56:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "theseer/tokenizer",
|
||||
|
@ -5868,16 +5868,16 @@
|
|||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v2.14.4",
|
||||
"version": "v2.14.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "0b4ba691fb99ec7952d25deb36c0a83061b93bbf"
|
||||
"reference": "c9dd15b3a80725bc4919730fae462bddcc960820"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/0b4ba691fb99ec7952d25deb36c0a83061b93bbf",
|
||||
"reference": "0b4ba691fb99ec7952d25deb36c0a83061b93bbf",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/c9dd15b3a80725bc4919730fae462bddcc960820",
|
||||
"reference": "c9dd15b3a80725bc4919730fae462bddcc960820",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -5931,7 +5931,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/twigphp/Twig/issues",
|
||||
"source": "https://github.com/twigphp/Twig/tree/v2.14.4"
|
||||
"source": "https://github.com/twigphp/Twig/tree/v2.14.5"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -5943,7 +5943,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-03-10T10:05:55+00:00"
|
||||
"time": "2021-05-12T08:02:35+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vimeo/psalm",
|
||||
|
|
Loading…
Reference in a new issue