1
0
Fork 0
mirror of synced 2024-06-03 11:24:48 +12:00

Merge branch 'master' of github.com:appwrite/appwrite into deprecated-first-and-last

This commit is contained in:
Eldad Fux 2020-06-26 17:43:21 +03:00
commit efc8fd12dc
51 changed files with 388 additions and 303 deletions

View file

@ -18,6 +18,7 @@
- Upgraded Redis Resque queue library to version 1.3.6 - Upgraded Redis Resque queue library to version 1.3.6
- Added container names to docker-compose.yml (@drandell) - Added container names to docker-compose.yml (@drandell)
- Upgraded ClamAV container image to version 1.0.9 - Upgraded ClamAV container image to version 1.0.9
- Optimised function execution by using fully-qualified function calls
## Bug Fixes ## Bug Fixes
@ -31,6 +32,8 @@
- Fixed update form labels and tooltips for Flutter Android apps - Fixed update form labels and tooltips for Flutter Android apps
- Fixed missing custom scopes param for OAuth2 session create API route - Fixed missing custom scopes param for OAuth2 session create API route
- Fixed wrong JSON validation when creating and updating database documnets - Fixed wrong JSON validation when creating and updating database documnets
- Fixed bug where max file size was limited to max of 10MB
- Fixed bug preventing the deletion of the project logo
## Breaking Changes ## Breaking Changes
- **Deprecated** `first` and `last` query params for documents list route in the database API - **Deprecated** `first` and `last` query params for documents list route in the database API

View file

@ -171,6 +171,16 @@ Improve PHP exeution time by using [fully-qualified function calls](https://veew
php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes
``` ```
Coding Standards:
```bash
php-cs-fixer fix app/controllers --rules='{"braces": {"allow_single_line_closure": true}}'
```
```bash
php-cs-fixer fix src --rules='{"braces": {"allow_single_line_closure": true}}'
```
## Tutorials ## Tutorials
From time to time, our team will add tutorials that will help contributors find their way in the Appwrite source code. Below is a list of currently available tutorials: From time to time, our team will add tutorials that will help contributors find their way in the Appwrite source code. Below is a list of currently available tutorials:

View file

@ -130,13 +130,12 @@ RUN \
# Set Upload Limit (default to 100MB) # Set Upload Limit (default to 100MB)
RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
RUN echo "env[TESTME] = your-secret-key" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
# Add logs file # Add logs file
RUN echo "" >> /var/log/appwrite.log RUN echo "" >> /var/log/appwrite.log
# Nginx Configuration (with self-signed ssl certificates) # Nginx Configuration (with self-signed ssl certificates)
COPY ./docker/nginx.conf /etc/nginx/nginx.conf COPY ./docker/nginx.conf.template /etc/nginx/nginx.conf.template
COPY ./docker/ssl/cert.pem /etc/nginx/ssl/cert.pem COPY ./docker/ssl/cert.pem /etc/nginx/ssl/cert.pem
COPY ./docker/ssl/key.pem /etc/nginx/ssl/key.pem COPY ./docker/ssl/key.pem /etc/nginx/ssl/key.pem

View file

@ -1,9 +1,8 @@
<?php <?php
// Init
require_once __DIR__.'/init.php'; require_once __DIR__.'/init.php';
global $utopia, $request, $response, $register, $consoleDB, $project, $service; global $utopia, $request, $response, $register, $consoleDB, $project;
use Utopia\App; use Utopia\App;
use Utopia\Request; use Utopia\Request;
@ -21,9 +20,6 @@ use Appwrite\Network\Validator\Origin;
/* /*
* Configuration files * Configuration files
*/ */
$roles = include __DIR__.'/config/roles.php'; // User roles and scopes
$services = include __DIR__.'/config/services.php'; // List of services
$webhook = new Event('v1-webhooks', 'WebhooksV1'); $webhook = new Event('v1-webhooks', 'WebhooksV1');
$audit = new Event('v1-audits', 'AuditsV1'); $audit = new Event('v1-audits', 'AuditsV1');
$usage = new Event('v1-usage', 'UsageV1'); $usage = new Event('v1-usage', 'UsageV1');
@ -54,7 +50,7 @@ $clients = \array_unique(\array_merge($clientsConsole, \array_map(function ($nod
return false; return false;
})))); }))));
$utopia->init(function () use ($utopia, $request, $response, &$user, $project, $console, $roles, $webhook, $mail, $audit, $usage, $clients) { $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $console, $webhook, $mail, $audit, $usage, $clients) {
$route = $utopia->match($request); $route = $utopia->match($request);
@ -142,6 +138,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
} }
} }
$roles = Config::getParam('roles', []);
$scope = $route->getLabel('scope', 'none'); // Allowed scope for chosen route $scope = $route->getLabel('scope', 'none'); // Allowed scope for chosen route
$scopes = $roles[$role]['scopes']; // Allowed scopes for user role $scopes = $roles[$role]['scopes']; // Allowed scopes for user role
@ -426,14 +423,11 @@ $utopia->get('/.well-known/acme-challenge')
} }
); );
$name = APP_NAME; include_once __DIR__ . '/controllers/shared/api.php';
include_once __DIR__ . '/controllers/shared/web.php';
if (\array_key_exists($service, $services)) { /** @noinspection PhpIncludeInspection */ foreach(Config::getParam('services', []) as $service) {
include_once $services[$service]['controller']; include_once $service['controller'];
$name = APP_NAME.' '.\ucfirst($services[$service]['name']);
} else {
/** @noinspection PhpIncludeInspection */
include_once $services['/']['controller'];
} }
$utopia->run($request, $response); $utopia->run($request, $response);

View file

@ -29,8 +29,6 @@ use DeviceDetector\DeviceDetector;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
use Utopia\Validator\ArrayList; use Utopia\Validator\ArrayList;
include_once __DIR__ . '/../shared/api.php';
$oauthDefaultSuccess = $request->getServer('_APP_HOME').'/auth/oauth2/success'; $oauthDefaultSuccess = $request->getServer('_APP_HOME').'/auth/oauth2/success';
$oauthDefaultFailure = $request->getServer('_APP_HOME').'/auth/oauth2/failure'; $oauthDefaultFailure = $request->getServer('_APP_HOME').'/auth/oauth2/failure';
@ -45,11 +43,11 @@ $utopia->init(function() use (&$oauth2Keys) {
$oauth2Keys[] = 'oauth2'.\ucfirst($key); $oauth2Keys[] = 'oauth2'.\ucfirst($key);
$oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken'; $oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken';
} }
}, 'account');
});
$utopia->post('/v1/account') $utopia->post('/v1/account')
->desc('Create Account') ->desc('Create Account')
->groups(['api', 'account'])
->label('webhook', 'account.create') ->label('webhook', 'account.create')
->label('scope', 'public') ->label('scope', 'public')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -149,6 +147,7 @@ $utopia->post('/v1/account')
$utopia->post('/v1/account/sessions') $utopia->post('/v1/account/sessions')
->desc('Create Account Session') ->desc('Create Account Session')
->groups(['api', 'account'])
->label('webhook', 'account.sessions.create') ->label('webhook', 'account.sessions.create')
->label('scope', 'public') ->label('scope', 'public')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -221,7 +220,7 @@ $utopia->post('/v1/account/sessions')
->setParam('resource', 'users/'.$profile->getId()) ->setParam('resource', 'users/'.$profile->getId())
; ;
if(!Config::getParam('domainVerification')) { if (!Config::getParam('domainVerification')) {
$response $response
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($profile->getId(), $secret)])) ->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($profile->getId(), $secret)]))
; ;
@ -238,6 +237,7 @@ $utopia->post('/v1/account/sessions')
$utopia->get('/v1/account/sessions/oauth2/:provider') $utopia->get('/v1/account/sessions/oauth2/:provider')
->desc('Create Account Session with OAuth2') ->desc('Create Account Session with OAuth2')
->groups(['api', 'account'])
->label('error', __DIR__.'/../../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('scope', 'public') ->label('scope', 'public')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -288,6 +288,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider')
$utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId') $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId')
->desc('OAuth2 Callback') ->desc('OAuth2 Callback')
->groups(['api', 'account'])
->label('error', __DIR__.'/../../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('scope', 'public') ->label('scope', 'public')
->label('docs', false) ->label('docs', false)
@ -310,6 +311,7 @@ $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId')
$utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId') $utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId')
->desc('OAuth2 Callback') ->desc('OAuth2 Callback')
->groups(['api', 'account'])
->label('error', __DIR__.'/../../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('scope', 'public') ->label('scope', 'public')
->label('origin', '*') ->label('origin', '*')
@ -333,6 +335,7 @@ $utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId')
$utopia->get('/v1/account/sessions/oauth2/:provider/redirect') $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
->desc('OAuth2 Redirect') ->desc('OAuth2 Redirect')
->groups(['api', 'account'])
->label('error', __DIR__.'/../../views/general/error.phtml') ->label('error', __DIR__.'/../../views/general/error.phtml')
->label('webhook', 'account.sessions.create') ->label('webhook', 'account.sessions.create')
->label('scope', 'public') ->label('scope', 'public')
@ -496,13 +499,13 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
->setParam('data', ['provider' => $provider]) ->setParam('data', ['provider' => $provider])
; ;
if(!Config::getParam('domainVerification')) { if (!Config::getParam('domainVerification')) {
$response $response
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)]))
; ;
} }
if($state['success'] === $oauthDefaultSuccess) { // Add keys for non-web platforms if ($state['success'] === $oauthDefaultSuccess) { // Add keys for non-web platforms
$state['success'] = URLParser::parse($state['success']); $state['success'] = URLParser::parse($state['success']);
$query = URLParser::parseQuery($state['success']['query']); $query = URLParser::parseQuery($state['success']['query']);
$query['project'] = $project->getId(); $query['project'] = $project->getId();
@ -525,6 +528,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
$utopia->get('/v1/account') $utopia->get('/v1/account')
->desc('Get Account') ->desc('Get Account')
->groups(['api', 'account'])
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
@ -548,6 +552,7 @@ $utopia->get('/v1/account')
$utopia->get('/v1/account/prefs') $utopia->get('/v1/account/prefs')
->desc('Get Account Preferences') ->desc('Get Account Preferences')
->groups(['api', 'account'])
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
@ -570,6 +575,7 @@ $utopia->get('/v1/account/prefs')
$utopia->get('/v1/account/sessions') $utopia->get('/v1/account/sessions')
->desc('Get Account Sessions') ->desc('Get Account Sessions')
->groups(['api', 'account'])
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
@ -628,6 +634,7 @@ $utopia->get('/v1/account/sessions')
$utopia->get('/v1/account/logs') $utopia->get('/v1/account/logs')
->desc('Get Account Logs') ->desc('Get Account Logs')
->groups(['api', 'account'])
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
@ -700,6 +707,7 @@ $utopia->get('/v1/account/logs')
$utopia->patch('/v1/account/name') $utopia->patch('/v1/account/name')
->desc('Update Account Name') ->desc('Update Account Name')
->groups(['api', 'account'])
->label('webhook', 'account.update.name') ->label('webhook', 'account.update.name')
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -737,6 +745,7 @@ $utopia->patch('/v1/account/name')
$utopia->patch('/v1/account/password') $utopia->patch('/v1/account/password')
->desc('Update Account Password') ->desc('Update Account Password')
->groups(['api', 'account'])
->label('webhook', 'account.update.password') ->label('webhook', 'account.update.password')
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -779,6 +788,7 @@ $utopia->patch('/v1/account/password')
$utopia->patch('/v1/account/email') $utopia->patch('/v1/account/email')
->desc('Update Account Email') ->desc('Update Account Email')
->groups(['api', 'account'])
->label('webhook', 'account.update.email') ->label('webhook', 'account.update.email')
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -836,6 +846,7 @@ $utopia->patch('/v1/account/email')
$utopia->patch('/v1/account/prefs') $utopia->patch('/v1/account/prefs')
->desc('Update Account Preferences') ->desc('Update Account Preferences')
->groups(['api', 'account'])
->label('webhook', 'account.update.prefs') ->label('webhook', 'account.update.prefs')
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -876,6 +887,7 @@ $utopia->patch('/v1/account/prefs')
$utopia->delete('/v1/account') $utopia->delete('/v1/account')
->desc('Delete Account') ->desc('Delete Account')
->groups(['api', 'account'])
->label('webhook', 'account.delete') ->label('webhook', 'account.delete')
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -915,7 +927,7 @@ $utopia->delete('/v1/account')
]) ])
; ;
if(!Config::getParam('domainVerification')) { if (!Config::getParam('domainVerification')) {
$response $response
->addHeader('X-Fallback-Cookies', \json_encode([])) ->addHeader('X-Fallback-Cookies', \json_encode([]))
; ;
@ -931,6 +943,7 @@ $utopia->delete('/v1/account')
$utopia->delete('/v1/account/sessions/:sessionId') $utopia->delete('/v1/account/sessions/:sessionId')
->desc('Delete Account Session') ->desc('Delete Account Session')
->groups(['api', 'account'])
->label('scope', 'account') ->label('scope', 'account')
->label('webhook', 'account.sessions.delete') ->label('webhook', 'account.sessions.delete')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -967,7 +980,7 @@ $utopia->delete('/v1/account/sessions/:sessionId')
]) ])
; ;
if(!Config::getParam('domainVerification')) { if (!Config::getParam('domainVerification')) {
$response $response
->addHeader('X-Fallback-Cookies', \json_encode([])) ->addHeader('X-Fallback-Cookies', \json_encode([]))
; ;
@ -990,6 +1003,7 @@ $utopia->delete('/v1/account/sessions/:sessionId')
$utopia->delete('/v1/account/sessions') $utopia->delete('/v1/account/sessions')
->desc('Delete All Account Sessions') ->desc('Delete All Account Sessions')
->groups(['api', 'account'])
->label('scope', 'account') ->label('scope', 'account')
->label('webhook', 'account.sessions.delete') ->label('webhook', 'account.sessions.delete')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
@ -1020,7 +1034,7 @@ $utopia->delete('/v1/account/sessions')
]) ])
; ;
if(!Config::getParam('domainVerification')) { if (!Config::getParam('domainVerification')) {
$response $response
->addHeader('X-Fallback-Cookies', \json_encode([])) ->addHeader('X-Fallback-Cookies', \json_encode([]))
; ;
@ -1040,6 +1054,7 @@ $utopia->delete('/v1/account/sessions')
$utopia->post('/v1/account/recovery') $utopia->post('/v1/account/recovery')
->desc('Create Password Recovery') ->desc('Create Password Recovery')
->groups(['api', 'account'])
->label('scope', 'public') ->label('scope', 'public')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
@ -1138,6 +1153,7 @@ $utopia->post('/v1/account/recovery')
$utopia->put('/v1/account/recovery') $utopia->put('/v1/account/recovery')
->desc('Complete Password Recovery') ->desc('Complete Password Recovery')
->groups(['api', 'account'])
->label('scope', 'public') ->label('scope', 'public')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
@ -1207,6 +1223,7 @@ $utopia->put('/v1/account/recovery')
$utopia->post('/v1/account/verification') $utopia->post('/v1/account/verification')
->desc('Create Email Verification') ->desc('Create Email Verification')
->groups(['api', 'account'])
->label('scope', 'account') ->label('scope', 'account')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
@ -1293,6 +1310,7 @@ $utopia->post('/v1/account/verification')
$utopia->put('/v1/account/verification') $utopia->put('/v1/account/verification')
->desc('Complete Email Verification') ->desc('Complete Email Verification')
->groups(['api', 'account'])
->label('scope', 'public') ->label('scope', 'public')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')

View file

@ -18,15 +18,13 @@ use BaconQrCode\Writer;
use Utopia\Config\Config; use Utopia\Config\Config;
use Utopia\Validator\HexColor; use Utopia\Validator\HexColor;
include_once __DIR__ . '/../shared/api.php';
$types = [ $types = [
'browsers' => include __DIR__.'/../../config/avatars/browsers.php', 'browsers' => include __DIR__.'/../../config/avatars/browsers.php',
'credit-cards' => include __DIR__.'/../../config/avatars/credit-cards.php', 'credit-cards' => include __DIR__.'/../../config/avatars/credit-cards.php',
'flags' => include __DIR__.'/../../config/avatars/flags.php', 'flags' => include __DIR__.'/../../config/avatars/flags.php',
]; ];
$avatarCallback = function ($type, $code, $width, $height, $quality) use ($types, $response, $request) { $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types, $response) {
$code = \strtolower($code); $code = \strtolower($code);
$type = \strtolower($type); $type = \strtolower($type);
@ -86,12 +84,11 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types
echo $data; echo $data;
unset($resize); unset($resize);
exit(0);
}; };
$utopia->get('/v1/avatars/credit-cards/:code') $utopia->get('/v1/avatars/credit-cards/:code')
->desc('Get Credit Card Icon') ->desc('Get Credit Card Icon')
->groups(['api', 'avatars'])
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['credit-cards'])); }, 'Credit Card Code. Possible values: '.\implode(', ', \array_keys($types['credit-cards'])).'.') ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['credit-cards'])); }, 'Credit Card Code. Possible values: '.\implode(', ', \array_keys($types['credit-cards'])).'.')
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
@ -102,11 +99,13 @@ $utopia->get('/v1/avatars/credit-cards/:code')
->label('sdk.method', 'getCreditCard') ->label('sdk.method', 'getCreditCard')
->label('sdk.methodType', 'location') ->label('sdk.methodType', 'location')
->label('sdk.description', '/docs/references/avatars/get-credit-card.md') ->label('sdk.description', '/docs/references/avatars/get-credit-card.md')
->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('credit-cards', $code, $width, $height, $quality); ->action(function ($code, $width, $height, $quality) use ($avatarCallback) {
return $avatarCallback('credit-cards', $code, $width, $height, $quality);
}); });
$utopia->get('/v1/avatars/browsers/:code') $utopia->get('/v1/avatars/browsers/:code')
->desc('Get Browser Icon') ->desc('Get Browser Icon')
->groups(['api', 'avatars'])
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['browsers'])); }, 'Browser Code.') ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['browsers'])); }, 'Browser Code.')
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
@ -117,11 +116,13 @@ $utopia->get('/v1/avatars/browsers/:code')
->label('sdk.method', 'getBrowser') ->label('sdk.method', 'getBrowser')
->label('sdk.methodType', 'location') ->label('sdk.methodType', 'location')
->label('sdk.description', '/docs/references/avatars/get-browser.md') ->label('sdk.description', '/docs/references/avatars/get-browser.md')
->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('browsers', $code, $width, $height, $quality); ->action(function ($code, $width, $height, $quality) use ($avatarCallback) {
return $avatarCallback('browsers', $code, $width, $height, $quality);
}); });
$utopia->get('/v1/avatars/flags/:code') $utopia->get('/v1/avatars/flags/:code')
->desc('Get Country Flag') ->desc('Get Country Flag')
->groups(['api', 'avatars'])
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['flags'])); }, 'Country Code. ISO Alpha-2 country code format.') ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['flags'])); }, 'Country Code. ISO Alpha-2 country code format.')
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
@ -132,11 +133,13 @@ $utopia->get('/v1/avatars/flags/:code')
->label('sdk.method', 'getFlag') ->label('sdk.method', 'getFlag')
->label('sdk.methodType', 'location') ->label('sdk.methodType', 'location')
->label('sdk.description', '/docs/references/avatars/get-flag.md') ->label('sdk.description', '/docs/references/avatars/get-flag.md')
->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('flags', $code, $width, $height, $quality); ->action(function ($code, $width, $height, $quality) use ($avatarCallback) {
return $avatarCallback('flags', $code, $width, $height, $quality);
}); });
$utopia->get('/v1/avatars/image') $utopia->get('/v1/avatars/image')
->desc('Get Image from URL') ->desc('Get Image from URL')
->groups(['api', 'avatars'])
->param('url', '', function () { return new URL(); }, 'Image URL which you want to crop.') ->param('url', '', function () { return new URL(); }, 'Image URL which you want to crop.')
->param('width', 400, function () { return new Range(0, 2000); }, 'Resize preview image width, Pass an integer between 0 to 2000.', true) ->param('width', 400, function () { return new Range(0, 2000); }, 'Resize preview image width, Pass an integer between 0 to 2000.', true)
->param('height', 400, function () { return new Range(0, 2000); }, 'Resize preview image height, Pass an integer between 0 to 2000.', true) ->param('height', 400, function () { return new Range(0, 2000); }, 'Resize preview image height, Pass an integer between 0 to 2000.', true)
@ -199,13 +202,12 @@ $utopia->get('/v1/avatars/image')
echo $data; echo $data;
unset($resize); unset($resize);
exit(0);
} }
); );
$utopia->get('/v1/avatars/favicon') $utopia->get('/v1/avatars/favicon')
->desc('Get Favicon') ->desc('Get Favicon')
->groups(['api', 'avatars'])
->param('url', '', function () { return new URL(); }, 'Website URL which you want to fetch the favicon from.') ->param('url', '', function () { return new URL(); }, 'Website URL which you want to fetch the favicon from.')
->label('scope', 'avatars.read') ->label('scope', 'avatars.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
@ -353,13 +355,12 @@ $utopia->get('/v1/avatars/favicon')
echo $data; echo $data;
unset($resize); unset($resize);
exit(0);
} }
); );
$utopia->get('/v1/avatars/qr') $utopia->get('/v1/avatars/qr')
->desc('Get QR Code') ->desc('Get QR Code')
->groups(['api', 'avatars'])
->param('text', '', function () { return new Text(512); }, 'Plain text to be converted to QR code image.') ->param('text', '', function () { return new Text(512); }, 'Plain text to be converted to QR code image.')
->param('size', 400, function () { return new Range(0, 1000); }, 'QR code size. Pass an integer between 0 to 1000. Defaults to 400.', true) ->param('size', 400, function () { return new Range(0, 1000); }, 'QR code size. Pass an integer between 0 to 1000. Defaults to 400.', true)
->param('margin', 1, function () { return new Range(0, 10); }, 'Margin from edge. Pass an integer between 0 to 10. Defaults to 1.', true) ->param('margin', 1, function () { return new Range(0, 10); }, 'Margin from edge. Pass an integer between 0 to 10. Defaults to 1.', true)
@ -393,6 +394,7 @@ $utopia->get('/v1/avatars/qr')
$utopia->get('/v1/avatars/initials') $utopia->get('/v1/avatars/initials')
->desc('Get User Initials') ->desc('Get User Initials')
->groups(['api', 'avatars'])
->param('name', '', function () { return new Text(512); }, 'Full Name. When empty, current user name or email will be used.', true) ->param('name', '', function () { return new Text(512); }, 'Full Name. When empty, current user name or email will be used.', true)
->param('width', 500, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('width', 500, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
->param('height', 500, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 500, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
@ -430,7 +432,7 @@ $utopia->get('/v1/avatars/initials')
$initials .= (isset($w[0])) ? $w[0] : ''; $initials .= (isset($w[0])) ? $w[0] : '';
$code += (isset($w[0])) ? \ord($w[0]) : 0; $code += (isset($w[0])) ? \ord($w[0]) : 0;
if($key == 1) { if ($key == 1) {
break; break;
} }
} }

View file

@ -25,12 +25,9 @@ use Appwrite\Database\Exception\Structure as StructureException;
use DeviceDetector\DeviceDetector; use DeviceDetector\DeviceDetector;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
include_once __DIR__ . '/../shared/api.php';
$isDev = (App::MODE_TYPE_PRODUCTION !== $utopia->getMode());
$utopia->post('/v1/database/collections') $utopia->post('/v1/database/collections')
->desc('Create Collection') ->desc('Create Collection')
->groups(['api', 'database'])
->label('webhook', 'database.collections.create') ->label('webhook', 'database.collections.create')
->label('scope', 'collections.write') ->label('scope', 'collections.write')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
@ -104,6 +101,7 @@ $utopia->post('/v1/database/collections')
$utopia->get('/v1/database/collections') $utopia->get('/v1/database/collections')
->desc('List Collections') ->desc('List Collections')
->groups(['api', 'database'])
->label('scope', 'collections.read') ->label('scope', 'collections.read')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
@ -152,6 +150,7 @@ $utopia->get('/v1/database/collections')
$utopia->get('/v1/database/collections/:collectionId') $utopia->get('/v1/database/collections/:collectionId')
->desc('Get Collection') ->desc('Get Collection')
->groups(['api', 'database'])
->label('scope', 'collections.read') ->label('scope', 'collections.read')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
@ -172,6 +171,7 @@ $utopia->get('/v1/database/collections/:collectionId')
// $utopia->get('/v1/database/collections/:collectionId/logs') // $utopia->get('/v1/database/collections/:collectionId/logs')
// ->desc('Get Collection Logs') // ->desc('Get Collection Logs')
// ->groups(['api', 'database'])
// ->label('scope', 'collections.read') // ->label('scope', 'collections.read')
// ->label('sdk.platform', [APP_PLATFORM_SERVER]) // ->label('sdk.platform', [APP_PLATFORM_SERVER])
// ->label('sdk.namespace', 'database') // ->label('sdk.namespace', 'database')
@ -180,7 +180,7 @@ $utopia->get('/v1/database/collections/:collectionId')
// ->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.') // ->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.')
// ->action( // ->action(
// function ($collectionId) use ($response, $register, $projectDB, $project) { // function ($collectionId) use ($response, $register, $projectDB, $project) {
// $collection = $projectDB->getDocument($collectionId); // $collection = $projectDB->getDocument($collectionId, false);
// if (empty($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { // if (empty($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
// throw new Exception('Collection not found', 404); // throw new Exception('Collection not found', 404);
@ -236,6 +236,7 @@ $utopia->get('/v1/database/collections/:collectionId')
$utopia->put('/v1/database/collections/:collectionId') $utopia->put('/v1/database/collections/:collectionId')
->desc('Update Collection') ->desc('Update Collection')
->groups(['api', 'database'])
->label('scope', 'collections.write') ->label('scope', 'collections.write')
->label('webhook', 'database.collections.update') ->label('webhook', 'database.collections.update')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
@ -308,6 +309,7 @@ $utopia->put('/v1/database/collections/:collectionId')
$utopia->delete('/v1/database/collections/:collectionId') $utopia->delete('/v1/database/collections/:collectionId')
->desc('Delete Collection') ->desc('Delete Collection')
->groups(['api', 'database'])
->label('scope', 'collections.write') ->label('scope', 'collections.write')
->label('webhook', 'database.collections.delete') ->label('webhook', 'database.collections.delete')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
@ -345,6 +347,7 @@ $utopia->delete('/v1/database/collections/:collectionId')
$utopia->post('/v1/database/collections/:collectionId/documents') $utopia->post('/v1/database/collections/:collectionId/documents')
->desc('Create Document') ->desc('Create Document')
->groups(['api', 'database'])
->label('webhook', 'database.documents.create') ->label('webhook', 'database.documents.create')
->label('scope', 'documents.write') ->label('scope', 'documents.write')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
@ -370,7 +373,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
throw new Exception('$id is not allowed for creating new documents, try update instead', 400); throw new Exception('$id is not allowed for creating new documents, try update instead', 400);
} }
$collection = $projectDB->getDocument($collectionId/*, $isDev*/); $collection = $projectDB->getDocument($collectionId, false);
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
throw new Exception('Collection not found', 404); throw new Exception('Collection not found', 404);
@ -385,7 +388,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
// Read parent document + validate not 404 + validate read / write permission like patch method // Read parent document + validate not 404 + validate read / write permission like patch method
// Add payload to parent document property // Add payload to parent document property
if ((!empty($parentDocument)) && (!empty($parentProperty))) { if ((!empty($parentDocument)) && (!empty($parentProperty))) {
$parentDocument = $projectDB->getDocument($parentDocument); $parentDocument = $projectDB->getDocument($parentDocument, false);
if (empty($parentDocument->getArrayCopy())) { // Check empty if (empty($parentDocument->getArrayCopy())) { // Check empty
throw new Exception('No parent document found', 404); throw new Exception('No parent document found', 404);
@ -425,7 +428,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
$key = (isset($rule['key'])) ? $rule['key'] : ''; $key = (isset($rule['key'])) ? $rule['key'] : '';
$default = (isset($rule['default'])) ? $rule['default'] : null; $default = (isset($rule['default'])) ? $rule['default'] : null;
if(!isset($data[$key])) { if (!isset($data[$key])) {
$data[$key] = $default; $data[$key] = $default;
} }
} }
@ -464,6 +467,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
$utopia->get('/v1/database/collections/:collectionId/documents') $utopia->get('/v1/database/collections/:collectionId/documents')
->desc('List Documents') ->desc('List Documents')
->groups(['api', 'database'])
->label('scope', 'documents.read') ->label('scope', 'documents.read')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
@ -478,8 +482,8 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
->param('orderCast', 'string', function () { return new WhiteList(array('int', 'string', 'date', 'time', 'datetime')); }, 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true) ->param('orderCast', 'string', function () { return new WhiteList(array('int', 'string', 'date', 'time', 'datetime')); }, 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true)
->param('search', '', function () { return new Text(256); }, 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children.', true) ->param('search', '', function () { return new Text(256); }, 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children.', true)
->action( ->action(
function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search) use ($response, $projectDB, $isDev) { function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search) use ($response, $projectDB, $utopia) {
$collection = $projectDB->getDocument($collectionId, $isDev); $collection = $projectDB->getDocument($collectionId, false);
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
throw new Exception('Collection not found', 404); throw new Exception('Collection not found', 404);
@ -497,7 +501,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
]), ]),
]); ]);
if ($isDev) { if ($utopia->isDevelopment()) {
$collection $collection
->setAttribute('debug', $projectDB->getDebug()) ->setAttribute('debug', $projectDB->getDebug())
->setAttribute('limit', $limit) ->setAttribute('limit', $limit)
@ -523,6 +527,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
$utopia->get('/v1/database/collections/:collectionId/documents/:documentId') $utopia->get('/v1/database/collections/:collectionId/documents/:documentId')
->desc('Get Document') ->desc('Get Document')
->groups(['api', 'database'])
->label('scope', 'documents.read') ->label('scope', 'documents.read')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
@ -531,9 +536,9 @@ $utopia->get('/v1/database/collections/:collectionId/documents/:documentId')
->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).') ->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
->param('documentId', null, function () { return new UID(); }, 'Document unique ID.') ->param('documentId', null, function () { return new UID(); }, 'Document unique ID.')
->action( ->action(
function ($collectionId, $documentId) use ($response, $request, $projectDB, $isDev) { function ($collectionId, $documentId) use ($response, $request, $projectDB) {
$document = $projectDB->getDocument($documentId, $isDev); $document = $projectDB->getDocument($documentId, false);
$collection = $projectDB->getDocument($collectionId, $isDev); $collection = $projectDB->getDocument($collectionId, false);
if (empty($document->getArrayCopy()) || $document->getCollection() != $collection->getId()) { // Check empty if (empty($document->getArrayCopy()) || $document->getCollection() != $collection->getId()) { // Check empty
throw new Exception('No document found', 404); throw new Exception('No document found', 404);
@ -568,6 +573,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents/:documentId')
$utopia->patch('/v1/database/collections/:collectionId/documents/:documentId') $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId')
->desc('Update Document') ->desc('Update Document')
->groups(['api', 'database'])
->label('webhook', 'database.documents.update') ->label('webhook', 'database.documents.update')
->label('scope', 'documents.write') ->label('scope', 'documents.write')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
@ -580,9 +586,9 @@ $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId')
->param('read', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('read', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->action( ->action(
function ($collectionId, $documentId, $data, $read, $write) use ($response, $projectDB, &$output, $webhook, $audit, $isDev) { function ($collectionId, $documentId, $data, $read, $write) use ($response, $projectDB, $webhook, $audit) {
$collection = $projectDB->getDocument($collectionId/*, $isDev*/); $collection = $projectDB->getDocument($collectionId, false);
$document = $projectDB->getDocument($documentId, $isDev); $document = $projectDB->getDocument($documentId, false);
$data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array $data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array
@ -647,6 +653,7 @@ $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId')
$utopia->delete('/v1/database/collections/:collectionId/documents/:documentId') $utopia->delete('/v1/database/collections/:collectionId/documents/:documentId')
->desc('Delete Document') ->desc('Delete Document')
->groups(['api', 'database'])
->label('scope', 'documents.write') ->label('scope', 'documents.write')
->label('webhook', 'database.documents.delete') ->label('webhook', 'database.documents.delete')
->label('sdk.namespace', 'database') ->label('sdk.namespace', 'database')
@ -656,9 +663,9 @@ $utopia->delete('/v1/database/collections/:collectionId/documents/:documentId')
->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).') ->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
->param('documentId', null, function () { return new UID(); }, 'Document unique ID.') ->param('documentId', null, function () { return new UID(); }, 'Document unique ID.')
->action( ->action(
function ($collectionId, $documentId) use ($response, $projectDB, $audit, $webhook, $isDev) { function ($collectionId, $documentId) use ($response, $projectDB, $audit, $webhook) {
$collection = $projectDB->getDocument($collectionId, $isDev); $collection = $projectDB->getDocument($collectionId, false);
$document = $projectDB->getDocument($documentId, $isDev); $document = $projectDB->getDocument($documentId, false);
if (empty($document->getArrayCopy()) || $document->getCollection() != $collectionId) { // Check empty if (empty($document->getArrayCopy()) || $document->getCollection() != $collectionId) { // Check empty
throw new Exception('No document found', 404); throw new Exception('No document found', 404);

View file

@ -14,6 +14,7 @@ global $utopia;
$utopia->post('/v1/graphql') $utopia->post('/v1/graphql')
->desc('GraphQL Endpoint') ->desc('GraphQL Endpoint')
->groups(['api', 'graphql'])
->label('scope', 'public') ->label('scope', 'public')
->action( ->action(
function () { function () {

View file

@ -9,6 +9,7 @@ use Appwrite\ClamAV\Network;
$utopia->get('/v1/health') $utopia->get('/v1/health')
->desc('Get HTTP') ->desc('Get HTTP')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -22,6 +23,7 @@ $utopia->get('/v1/health')
$utopia->get('/v1/health/version') $utopia->get('/v1/health/version')
->desc('Get Version') ->desc('Get Version')
->groups(['api', 'health'])
->label('scope', 'public') ->label('scope', 'public')
->action( ->action(
function () use ($response) { function () use ($response) {
@ -31,6 +33,7 @@ $utopia->get('/v1/health/version')
$utopia->get('/v1/health/db') $utopia->get('/v1/health/db')
->desc('Get DB') ->desc('Get DB')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -46,6 +49,7 @@ $utopia->get('/v1/health/db')
$utopia->get('/v1/health/cache') $utopia->get('/v1/health/cache')
->desc('Get Cache') ->desc('Get Cache')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -61,6 +65,7 @@ $utopia->get('/v1/health/cache')
$utopia->get('/v1/health/time') $utopia->get('/v1/health/time')
->desc('Get Time') ->desc('Get Time')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -108,6 +113,7 @@ $utopia->get('/v1/health/time')
$utopia->get('/v1/health/queue/webhooks') $utopia->get('/v1/health/queue/webhooks')
->desc('Get Webhooks Queue') ->desc('Get Webhooks Queue')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -121,6 +127,7 @@ $utopia->get('/v1/health/queue/webhooks')
$utopia->get('/v1/health/queue/tasks') $utopia->get('/v1/health/queue/tasks')
->desc('Get Tasks Queue') ->desc('Get Tasks Queue')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -134,6 +141,7 @@ $utopia->get('/v1/health/queue/tasks')
$utopia->get('/v1/health/queue/logs') $utopia->get('/v1/health/queue/logs')
->desc('Get Logs Queue') ->desc('Get Logs Queue')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -147,6 +155,7 @@ $utopia->get('/v1/health/queue/logs')
$utopia->get('/v1/health/queue/usage') $utopia->get('/v1/health/queue/usage')
->desc('Get Usage Queue') ->desc('Get Usage Queue')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -160,6 +169,7 @@ $utopia->get('/v1/health/queue/usage')
$utopia->get('/v1/health/queue/certificates') $utopia->get('/v1/health/queue/certificates')
->desc('Get Certificate Queue') ->desc('Get Certificate Queue')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -173,6 +183,7 @@ $utopia->get('/v1/health/queue/certificates')
$utopia->get('/v1/health/queue/functions') $utopia->get('/v1/health/queue/functions')
->desc('Get Functions Queue') ->desc('Get Functions Queue')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -186,6 +197,7 @@ $utopia->get('/v1/health/queue/functions')
$utopia->get('/v1/health/storage/local') $utopia->get('/v1/health/storage/local')
->desc('Get Local Storage') ->desc('Get Local Storage')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -193,7 +205,6 @@ $utopia->get('/v1/health/storage/local')
->label('sdk.description', '/docs/references/health/get-storage-local.md') ->label('sdk.description', '/docs/references/health/get-storage-local.md')
->action( ->action(
function () use ($response) { function () use ($response) {
foreach ([ foreach ([
'Uploads' => APP_STORAGE_UPLOADS, 'Uploads' => APP_STORAGE_UPLOADS,
'Cache' => APP_STORAGE_CACHE, 'Cache' => APP_STORAGE_CACHE,
@ -217,6 +228,7 @@ $utopia->get('/v1/health/storage/local')
$utopia->get('/v1/health/anti-virus') $utopia->get('/v1/health/anti-virus')
->desc('Get Anti virus') ->desc('Get Anti virus')
->groups(['api', 'health'])
->label('scope', 'health.read') ->label('scope', 'health.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'health') ->label('sdk.namespace', 'health')
@ -224,7 +236,7 @@ $utopia->get('/v1/health/anti-virus')
->label('sdk.description', '/docs/references/health/get-storage-anti-virus.md') ->label('sdk.description', '/docs/references/health/get-storage-anti-virus.md')
->action( ->action(
function () use ($request, $response) { function () use ($request, $response) {
if($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled if ($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled
throw new Exception('Anitvirus is disabled'); throw new Exception('Anitvirus is disabled');
} }
@ -239,6 +251,7 @@ $utopia->get('/v1/health/anti-virus')
$utopia->get('/v1/health/stats') // Currently only used internally $utopia->get('/v1/health/stats') // Currently only used internally
->desc('Get System Stats') ->desc('Get System Stats')
->groups(['api', 'health'])
->label('scope', 'god') ->label('scope', 'god')
// ->label('sdk.platform', [APP_PLATFORM_SERVER]) // ->label('sdk.platform', [APP_PLATFORM_SERVER])
// ->label('sdk.namespace', 'health') // ->label('sdk.namespace', 'health')

View file

@ -6,10 +6,9 @@ use Utopia\App;
use Utopia\Locale\Locale; use Utopia\Locale\Locale;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
include_once __DIR__ . '/../shared/api.php';
$utopia->get('/v1/locale') $utopia->get('/v1/locale')
->desc('Get User Locale') ->desc('Get User Locale')
->groups(['api', 'locale'])
->label('scope', 'locale.read') ->label('scope', 'locale.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'locale') ->label('sdk.namespace', 'locale')
@ -68,6 +67,7 @@ $utopia->get('/v1/locale')
$utopia->get('/v1/locale/countries') $utopia->get('/v1/locale/countries')
->desc('List Countries') ->desc('List Countries')
->groups(['api', 'locale'])
->label('scope', 'locale.read') ->label('scope', 'locale.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'locale') ->label('sdk.namespace', 'locale')
@ -85,6 +85,7 @@ $utopia->get('/v1/locale/countries')
$utopia->get('/v1/locale/countries/eu') $utopia->get('/v1/locale/countries/eu')
->desc('List EU Countries') ->desc('List EU Countries')
->groups(['api', 'locale'])
->label('scope', 'locale.read') ->label('scope', 'locale.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'locale') ->label('sdk.namespace', 'locale')
@ -110,6 +111,7 @@ $utopia->get('/v1/locale/countries/eu')
$utopia->get('/v1/locale/countries/phones') $utopia->get('/v1/locale/countries/phones')
->desc('List Countries Phone Codes') ->desc('List Countries Phone Codes')
->groups(['api', 'locale'])
->label('scope', 'locale.read') ->label('scope', 'locale.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'locale') ->label('sdk.namespace', 'locale')
@ -135,6 +137,7 @@ $utopia->get('/v1/locale/countries/phones')
$utopia->get('/v1/locale/continents') $utopia->get('/v1/locale/continents')
->desc('List Continents') ->desc('List Continents')
->groups(['api', 'locale'])
->label('scope', 'locale.read') ->label('scope', 'locale.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'locale') ->label('sdk.namespace', 'locale')
@ -153,6 +156,7 @@ $utopia->get('/v1/locale/continents')
$utopia->get('/v1/locale/currencies') $utopia->get('/v1/locale/currencies')
->desc('List Currencies') ->desc('List Currencies')
->groups(['api', 'locale'])
->label('scope', 'locale.read') ->label('scope', 'locale.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'locale') ->label('sdk.namespace', 'locale')
@ -169,6 +173,7 @@ $utopia->get('/v1/locale/currencies')
$utopia->get('/v1/locale/languages') $utopia->get('/v1/locale/languages')
->desc('List Languages') ->desc('List Languages')
->groups(['api', 'locale'])
->label('scope', 'locale.read') ->label('scope', 'locale.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'locale') ->label('sdk.namespace', 'locale')

View file

@ -21,12 +21,11 @@ use Appwrite\OpenSSL\OpenSSL;
use Appwrite\Network\Validator\CNAME; use Appwrite\Network\Validator\CNAME;
use Cron\CronExpression; use Cron\CronExpression;
include_once __DIR__ . '/../shared/api.php';
$scopes = include __DIR__.'/../../../app/config/scopes.php'; $scopes = include __DIR__.'/../../../app/config/scopes.php';
$utopia->post('/v1/projects') $utopia->post('/v1/projects')
->desc('Create Project') ->desc('Create Project')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'create') ->label('sdk.method', 'create')
@ -89,6 +88,7 @@ $utopia->post('/v1/projects')
$utopia->get('/v1/projects') $utopia->get('/v1/projects')
->desc('List Projects') ->desc('List Projects')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'list') ->label('sdk.method', 'list')
@ -122,6 +122,7 @@ $utopia->get('/v1/projects')
$utopia->get('/v1/projects/:projectId') $utopia->get('/v1/projects/:projectId')
->desc('Get Project') ->desc('Get Project')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'get') ->label('sdk.method', 'get')
@ -149,6 +150,7 @@ $utopia->get('/v1/projects/:projectId')
$utopia->get('/v1/projects/:projectId/usage') $utopia->get('/v1/projects/:projectId/usage')
->desc('Get Project') ->desc('Get Project')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'getUsage') ->label('sdk.method', 'getUsage')
@ -310,6 +312,7 @@ $utopia->get('/v1/projects/:projectId/usage')
$utopia->patch('/v1/projects/:projectId') $utopia->patch('/v1/projects/:projectId')
->desc('Update Project') ->desc('Update Project')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'update') ->label('sdk.method', 'update')
@ -355,6 +358,7 @@ $utopia->patch('/v1/projects/:projectId')
$utopia->patch('/v1/projects/:projectId/oauth2') $utopia->patch('/v1/projects/:projectId/oauth2')
->desc('Update Project OAuth2') ->desc('Update Project OAuth2')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'updateOAuth2') ->label('sdk.method', 'updateOAuth2')
@ -396,6 +400,7 @@ $utopia->patch('/v1/projects/:projectId/oauth2')
$utopia->delete('/v1/projects/:projectId') $utopia->delete('/v1/projects/:projectId')
->desc('Delete Project') ->desc('Delete Project')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'delete') ->label('sdk.method', 'delete')
@ -415,7 +420,7 @@ $utopia->delete('/v1/projects/:projectId')
$deletes->setParam('document', $project->getArrayCopy()); $deletes->setParam('document', $project->getArrayCopy());
foreach(['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms) foreach (['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms)
$list = $project->getAttribute('webhooks', []); $list = $project->getAttribute('webhooks', []);
foreach ($list as $document) { /* @var $document Document */ foreach ($list as $document) { /* @var $document Document */
@ -441,6 +446,7 @@ $utopia->delete('/v1/projects/:projectId')
$utopia->post('/v1/projects/:projectId/webhooks') $utopia->post('/v1/projects/:projectId/webhooks')
->desc('Create Webhook') ->desc('Create Webhook')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'createWebhook') ->label('sdk.method', 'createWebhook')
@ -505,6 +511,7 @@ $utopia->post('/v1/projects/:projectId/webhooks')
$utopia->get('/v1/projects/:projectId/webhooks') $utopia->get('/v1/projects/:projectId/webhooks')
->desc('List Webhooks') ->desc('List Webhooks')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'listWebhooks') ->label('sdk.method', 'listWebhooks')
@ -537,6 +544,7 @@ $utopia->get('/v1/projects/:projectId/webhooks')
$utopia->get('/v1/projects/:projectId/webhooks/:webhookId') $utopia->get('/v1/projects/:projectId/webhooks/:webhookId')
->desc('Get Webhook') ->desc('Get Webhook')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'getWebhook') ->label('sdk.method', 'getWebhook')
@ -570,6 +578,7 @@ $utopia->get('/v1/projects/:projectId/webhooks/:webhookId')
$utopia->put('/v1/projects/:projectId/webhooks/:webhookId') $utopia->put('/v1/projects/:projectId/webhooks/:webhookId')
->desc('Update Webhook') ->desc('Update Webhook')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'updateWebhook') ->label('sdk.method', 'updateWebhook')
@ -625,6 +634,7 @@ $utopia->put('/v1/projects/:projectId/webhooks/:webhookId')
$utopia->delete('/v1/projects/:projectId/webhooks/:webhookId') $utopia->delete('/v1/projects/:projectId/webhooks/:webhookId')
->desc('Delete Webhook') ->desc('Delete Webhook')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'deleteWebhook') ->label('sdk.method', 'deleteWebhook')
@ -656,6 +666,7 @@ $utopia->delete('/v1/projects/:projectId/webhooks/:webhookId')
$utopia->post('/v1/projects/:projectId/keys') $utopia->post('/v1/projects/:projectId/keys')
->desc('Create Key') ->desc('Create Key')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'createKey') ->label('sdk.method', 'createKey')
@ -702,6 +713,7 @@ $utopia->post('/v1/projects/:projectId/keys')
$utopia->get('/v1/projects/:projectId/keys') $utopia->get('/v1/projects/:projectId/keys')
->desc('List Keys') ->desc('List Keys')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'listKeys') ->label('sdk.method', 'listKeys')
@ -720,6 +732,7 @@ $utopia->get('/v1/projects/:projectId/keys')
$utopia->get('/v1/projects/:projectId/keys/:keyId') $utopia->get('/v1/projects/:projectId/keys/:keyId')
->desc('Get Key') ->desc('Get Key')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'getKey') ->label('sdk.method', 'getKey')
@ -745,6 +758,7 @@ $utopia->get('/v1/projects/:projectId/keys/:keyId')
$utopia->put('/v1/projects/:projectId/keys/:keyId') $utopia->put('/v1/projects/:projectId/keys/:keyId')
->desc('Update Key') ->desc('Update Key')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'updateKey') ->label('sdk.method', 'updateKey')
@ -781,6 +795,7 @@ $utopia->put('/v1/projects/:projectId/keys/:keyId')
$utopia->delete('/v1/projects/:projectId/keys/:keyId') $utopia->delete('/v1/projects/:projectId/keys/:keyId')
->desc('Delete Key') ->desc('Delete Key')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'deleteKey') ->label('sdk.method', 'deleteKey')
@ -812,6 +827,7 @@ $utopia->delete('/v1/projects/:projectId/keys/:keyId')
$utopia->post('/v1/projects/:projectId/tasks') $utopia->post('/v1/projects/:projectId/tasks')
->desc('Create Task') ->desc('Create Task')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'createTask') ->label('sdk.method', 'createTask')
@ -894,6 +910,7 @@ $utopia->post('/v1/projects/:projectId/tasks')
$utopia->get('/v1/projects/:projectId/tasks') $utopia->get('/v1/projects/:projectId/tasks')
->desc('List Tasks') ->desc('List Tasks')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'listTasks') ->label('sdk.method', 'listTasks')
@ -926,6 +943,7 @@ $utopia->get('/v1/projects/:projectId/tasks')
$utopia->get('/v1/projects/:projectId/tasks/:taskId') $utopia->get('/v1/projects/:projectId/tasks/:taskId')
->desc('Get Task') ->desc('Get Task')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'getTask') ->label('sdk.method', 'getTask')
@ -958,6 +976,7 @@ $utopia->get('/v1/projects/:projectId/tasks/:taskId')
$utopia->put('/v1/projects/:projectId/tasks/:taskId') $utopia->put('/v1/projects/:projectId/tasks/:taskId')
->desc('Update Task') ->desc('Update Task')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'updateTask') ->label('sdk.method', 'updateTask')
@ -1028,6 +1047,7 @@ $utopia->put('/v1/projects/:projectId/tasks/:taskId')
$utopia->delete('/v1/projects/:projectId/tasks/:taskId') $utopia->delete('/v1/projects/:projectId/tasks/:taskId')
->desc('Delete Task') ->desc('Delete Task')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'deleteTask') ->label('sdk.method', 'deleteTask')
@ -1059,6 +1079,7 @@ $utopia->delete('/v1/projects/:projectId/tasks/:taskId')
$utopia->post('/v1/projects/:projectId/platforms') $utopia->post('/v1/projects/:projectId/platforms')
->desc('Create Platform') ->desc('Create Platform')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'createPlatform') ->label('sdk.method', 'createPlatform')
@ -1112,6 +1133,7 @@ $utopia->post('/v1/projects/:projectId/platforms')
$utopia->get('/v1/projects/:projectId/platforms') $utopia->get('/v1/projects/:projectId/platforms')
->desc('List Platforms') ->desc('List Platforms')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'listPlatforms') ->label('sdk.method', 'listPlatforms')
@ -1132,6 +1154,7 @@ $utopia->get('/v1/projects/:projectId/platforms')
$utopia->get('/v1/projects/:projectId/platforms/:platformId') $utopia->get('/v1/projects/:projectId/platforms/:platformId')
->desc('Get Platform') ->desc('Get Platform')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'getPlatform') ->label('sdk.method', 'getPlatform')
@ -1157,6 +1180,7 @@ $utopia->get('/v1/projects/:projectId/platforms/:platformId')
$utopia->put('/v1/projects/:projectId/platforms/:platformId') $utopia->put('/v1/projects/:projectId/platforms/:platformId')
->desc('Update Platform') ->desc('Update Platform')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'updatePlatform') ->label('sdk.method', 'updatePlatform')
@ -1198,6 +1222,7 @@ $utopia->put('/v1/projects/:projectId/platforms/:platformId')
$utopia->delete('/v1/projects/:projectId/platforms/:platformId') $utopia->delete('/v1/projects/:projectId/platforms/:platformId')
->desc('Delete Platform') ->desc('Delete Platform')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'deletePlatform') ->label('sdk.method', 'deletePlatform')
@ -1229,6 +1254,7 @@ $utopia->delete('/v1/projects/:projectId/platforms/:platformId')
$utopia->post('/v1/projects/:projectId/domains') $utopia->post('/v1/projects/:projectId/domains')
->desc('Create Domain') ->desc('Create Domain')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'createDomain') ->label('sdk.method', 'createDomain')
@ -1250,7 +1276,7 @@ $utopia->post('/v1/projects/:projectId/domains')
$target = new Domain($request->getServer('_APP_DOMAIN_TARGET', '')); $target = new Domain($request->getServer('_APP_DOMAIN_TARGET', ''));
if(!$target->isKnown() || $target->isTest()) { if (!$target->isKnown() || $target->isTest()) {
throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500); throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500);
} }
@ -1291,6 +1317,7 @@ $utopia->post('/v1/projects/:projectId/domains')
$utopia->get('/v1/projects/:projectId/domains') $utopia->get('/v1/projects/:projectId/domains')
->desc('List Domains') ->desc('List Domains')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'listDomains') ->label('sdk.method', 'listDomains')
@ -1311,6 +1338,7 @@ $utopia->get('/v1/projects/:projectId/domains')
$utopia->get('/v1/projects/:projectId/domains/:domainId') $utopia->get('/v1/projects/:projectId/domains/:domainId')
->desc('Get Domain') ->desc('Get Domain')
->groups(['api', 'projects'])
->label('scope', 'projects.read') ->label('scope', 'projects.read')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'getDomain') ->label('sdk.method', 'getDomain')
@ -1336,6 +1364,7 @@ $utopia->get('/v1/projects/:projectId/domains/:domainId')
$utopia->patch('/v1/projects/:projectId/domains/:domainId/verification') $utopia->patch('/v1/projects/:projectId/domains/:domainId/verification')
->desc('Update Domain Verification Status') ->desc('Update Domain Verification Status')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'updateDomainVerification') ->label('sdk.method', 'updateDomainVerification')
@ -1357,18 +1386,18 @@ $utopia->patch('/v1/projects/:projectId/domains/:domainId/verification')
$target = new Domain($request->getServer('_APP_DOMAIN_TARGET', '')); $target = new Domain($request->getServer('_APP_DOMAIN_TARGET', ''));
if(!$target->isKnown() || $target->isTest()) { if (!$target->isKnown() || $target->isTest()) {
throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500); throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500);
} }
if($domain->getAttribute('verification') === true) { if ($domain->getAttribute('verification') === true) {
return $response->json($domain->getArrayCopy()); return $response->json($domain->getArrayCopy());
} }
// Verify Domain with DNS records // Verify Domain with DNS records
$validator = new CNAME($target->get()); $validator = new CNAME($target->get());
if(!$validator->isValid($domain->getAttribute('domain', ''))) { if (!$validator->isValid($domain->getAttribute('domain', ''))) {
throw new Exception('Failed to verify domain', 401); throw new Exception('Failed to verify domain', 401);
} }
@ -1392,6 +1421,7 @@ $utopia->patch('/v1/projects/:projectId/domains/:domainId/verification')
$utopia->delete('/v1/projects/:projectId/domains/:domainId') $utopia->delete('/v1/projects/:projectId/domains/:domainId')
->desc('Delete Domain') ->desc('Delete Domain')
->groups(['api', 'projects'])
->label('scope', 'projects.write') ->label('scope', 'projects.write')
->label('sdk.namespace', 'projects') ->label('sdk.namespace', 'projects')
->label('sdk.method', 'deleteDomain') ->label('sdk.method', 'deleteDomain')

View file

@ -23,8 +23,6 @@ use Appwrite\Storage\Compression\Algorithms\GZIP;
use Appwrite\Resize\Resize; use Appwrite\Resize\Resize;
use Appwrite\OpenSSL\OpenSSL; use Appwrite\OpenSSL\OpenSSL;
include_once __DIR__ . '/../shared/api.php';
Storage::addDevice('local', new Local(APP_STORAGE_UPLOADS.'/app-'.$project->getId())); Storage::addDevice('local', new Local(APP_STORAGE_UPLOADS.'/app-'.$project->getId()));
$fileLogos = [ // Based on this list @see http://stackoverflow.com/a/4212908/2299554 $fileLogos = [ // Based on this list @see http://stackoverflow.com/a/4212908/2299554
@ -135,6 +133,7 @@ $mimes = [
$utopia->post('/v1/storage/files') $utopia->post('/v1/storage/files')
->desc('Create File') ->desc('Create File')
->groups(['api', 'storage'])
->label('scope', 'files.write') ->label('scope', 'files.write')
->label('webhook', 'storage.files.create') ->label('webhook', 'storage.files.create')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
@ -198,7 +197,7 @@ $utopia->post('/v1/storage/files')
$mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption $mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption
if($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled if ($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled
$antiVirus = new Network('clamav', 3310); $antiVirus = new Network('clamav', 3310);
// Check if file size is exceeding allowed limit // Check if file size is exceeding allowed limit
@ -216,7 +215,7 @@ $utopia->post('/v1/storage/files')
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM)); $iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
$data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag); $data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag);
if(!$device->write($path, $data)) { if (!$device->write($path, $data)) {
throw new Exception('Failed to save file', 500); throw new Exception('Failed to save file', 500);
} }
@ -271,6 +270,7 @@ $utopia->post('/v1/storage/files')
$utopia->get('/v1/storage/files') $utopia->get('/v1/storage/files')
->desc('List Files') ->desc('List Files')
->groups(['api', 'storage'])
->label('scope', 'files.read') ->label('scope', 'files.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'storage') ->label('sdk.namespace', 'storage')
@ -304,6 +304,7 @@ $utopia->get('/v1/storage/files')
$utopia->get('/v1/storage/files/:fileId') $utopia->get('/v1/storage/files/:fileId')
->desc('Get File') ->desc('Get File')
->groups(['api', 'storage'])
->label('scope', 'files.read') ->label('scope', 'files.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'storage') ->label('sdk.namespace', 'storage')
@ -324,6 +325,7 @@ $utopia->get('/v1/storage/files/:fileId')
$utopia->get('/v1/storage/files/:fileId/preview') $utopia->get('/v1/storage/files/:fileId/preview')
->desc('Get File Preview') ->desc('Get File Preview')
->groups(['api', 'storage'])
->label('scope', 'files.read') ->label('scope', 'files.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'storage') ->label('sdk.namespace', 'storage')
@ -337,8 +339,6 @@ $utopia->get('/v1/storage/files/:fileId/preview')
->param('quality', 100, function () { return new Range(0, 100); }, 'Preview image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->param('quality', 100, function () { return new Range(0, 100); }, 'Preview image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
->param('background', '', function () { return new HexColor(); }, 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true) ->param('background', '', function () { return new HexColor(); }, 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true)
->param('output', null, function () use ($outputs) { return new WhiteList(\array_merge(\array_keys($outputs), [null])); }, 'Output format type (jpeg, jpg, png, gif and webp).', true) ->param('output', null, function () use ($outputs) { return new WhiteList(\array_merge(\array_keys($outputs), [null])); }, 'Output format type (jpeg, jpg, png, gif and webp).', true)
//->param('storage', 'local', function () {return new WhiteList(array('local'));}, 'Selected storage device. defaults to local')
//->param('token', '', function () {return new Text(128);}, 'Preview token', true)
->action( ->action(
function ($fileId, $width, $height, $quality, $background, $output) use ($request, $response, $projectDB, $project, $inputs, $outputs, $fileLogos) { function ($fileId, $width, $height, $quality, $background, $output) use ($request, $response, $projectDB, $project, $inputs, $outputs, $fileLogos) {
$storage = 'local'; $storage = 'local';
@ -370,7 +370,7 @@ $utopia->get('/v1/storage/files/:fileId/preview')
$cipher = $file->getAttribute('fileOpenSSLCipher'); $cipher = $file->getAttribute('fileOpenSSLCipher');
$mime = $file->getAttribute('mimeType'); $mime = $file->getAttribute('mimeType');
if(!\in_array($mime, $inputs)) { if (!\in_array($mime, $inputs)) {
$path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default']; $path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default'];
$algorithm = null; $algorithm = null;
$cipher = null; $cipher = null;
@ -448,6 +448,7 @@ $utopia->get('/v1/storage/files/:fileId/preview')
$utopia->get('/v1/storage/files/:fileId/download') $utopia->get('/v1/storage/files/:fileId/download')
->desc('Get File for Download') ->desc('Get File for Download')
->groups(['api', 'storage'])
->label('scope', 'files.read') ->label('scope', 'files.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'storage') ->label('sdk.namespace', 'storage')
@ -501,6 +502,7 @@ $utopia->get('/v1/storage/files/:fileId/download')
$utopia->get('/v1/storage/files/:fileId/view') $utopia->get('/v1/storage/files/:fileId/view')
->desc('Get File for View') ->desc('Get File for View')
->groups(['api', 'storage'])
->label('scope', 'files.read') ->label('scope', 'files.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'storage') ->label('sdk.namespace', 'storage')
@ -571,6 +573,7 @@ $utopia->get('/v1/storage/files/:fileId/view')
$utopia->put('/v1/storage/files/:fileId') $utopia->put('/v1/storage/files/:fileId')
->desc('Update File') ->desc('Update File')
->groups(['api', 'storage'])
->label('scope', 'files.write') ->label('scope', 'files.write')
->label('webhook', 'storage.files.update') ->label('webhook', 'storage.files.update')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
@ -616,6 +619,7 @@ $utopia->put('/v1/storage/files/:fileId')
$utopia->delete('/v1/storage/files/:fileId') $utopia->delete('/v1/storage/files/:fileId')
->desc('Delete File') ->desc('Delete File')
->groups(['api', 'storage'])
->label('scope', 'files.write') ->label('scope', 'files.write')
->label('webhook', 'storage.files.delete') ->label('webhook', 'storage.files.delete')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
@ -658,6 +662,7 @@ $utopia->delete('/v1/storage/files/:fileId')
// $utopia->get('/v1/storage/files/:fileId/scan') // $utopia->get('/v1/storage/files/:fileId/scan')
// ->desc('Scan Storage') // ->desc('Scan Storage')
// ->groups(['api', 'storage'])
// ->label('scope', 'god') // ->label('scope', 'god')
// ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) // ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
// ->label('sdk.namespace', 'storage') // ->label('sdk.namespace', 'storage')

View file

@ -20,10 +20,9 @@ use Appwrite\Database\Validator\Authorization;
use Appwrite\Database\Exception\Duplicate; use Appwrite\Database\Exception\Duplicate;
use Appwrite\Template\Template; use Appwrite\Template\Template;
include_once __DIR__ . '/../shared/api.php';
$utopia->post('/v1/teams') $utopia->post('/v1/teams')
->desc('Create Team') ->desc('Create Team')
->groups(['api', 'teams'])
->label('scope', 'teams.write') ->label('scope', 'teams.write')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')
@ -87,6 +86,7 @@ $utopia->post('/v1/teams')
$utopia->get('/v1/teams') $utopia->get('/v1/teams')
->desc('List Teams') ->desc('List Teams')
->groups(['api', 'teams'])
->label('scope', 'teams.read') ->label('scope', 'teams.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')
@ -116,6 +116,7 @@ $utopia->get('/v1/teams')
$utopia->get('/v1/teams/:teamId') $utopia->get('/v1/teams/:teamId')
->desc('Get Team') ->desc('Get Team')
->groups(['api', 'teams'])
->label('scope', 'teams.read') ->label('scope', 'teams.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')
@ -136,6 +137,7 @@ $utopia->get('/v1/teams/:teamId')
$utopia->put('/v1/teams/:teamId') $utopia->put('/v1/teams/:teamId')
->desc('Update Team') ->desc('Update Team')
->groups(['api', 'teams'])
->label('scope', 'teams.write') ->label('scope', 'teams.write')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')
@ -165,6 +167,7 @@ $utopia->put('/v1/teams/:teamId')
$utopia->delete('/v1/teams/:teamId') $utopia->delete('/v1/teams/:teamId')
->desc('Delete Team') ->desc('Delete Team')
->groups(['api', 'teams'])
->label('scope', 'teams.write') ->label('scope', 'teams.write')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')
@ -204,6 +207,7 @@ $utopia->delete('/v1/teams/:teamId')
$utopia->post('/v1/teams/:teamId/memberships') $utopia->post('/v1/teams/:teamId/memberships')
->desc('Create Team Membership') ->desc('Create Team Membership')
->groups(['api', 'teams'])
->label('scope', 'teams.write') ->label('scope', 'teams.write')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')
@ -305,12 +309,11 @@ $utopia->post('/v1/teams/:teamId/memberships')
'secret' => Auth::hash($secret), 'secret' => Auth::hash($secret),
]); ]);
if(APP_MODE_ADMIN === $mode) { // Allow admin to create membership if (APP_MODE_ADMIN === $mode) { // Allow admin to create membership
Authorization::disable(); Authorization::disable();
$membership = $projectDB->createDocument($membership->getArrayCopy()); $membership = $projectDB->createDocument($membership->getArrayCopy());
Authorization::reset(); Authorization::reset();
} } else {
else {
$membership = $projectDB->createDocument($membership->getArrayCopy()); $membership = $projectDB->createDocument($membership->getArrayCopy());
} }
@ -343,7 +346,7 @@ $utopia->post('/v1/teams/:teamId/memberships')
->setParam('{{text-cta}}', '#ffffff') ->setParam('{{text-cta}}', '#ffffff')
; ;
if(APP_MODE_ADMIN !== $mode) { // No need in comfirmation when in admin mode if (APP_MODE_ADMIN !== $mode) { // No need in comfirmation when in admin mode
$mail $mail
->setParam('event', 'teams.membership.create') ->setParam('event', 'teams.membership.create')
->setParam('recipient', $email) ->setParam('recipient', $email)
@ -380,6 +383,7 @@ $utopia->post('/v1/teams/:teamId/memberships')
$utopia->get('/v1/teams/:teamId/memberships') $utopia->get('/v1/teams/:teamId/memberships')
->desc('Get Team Memberships') ->desc('Get Team Memberships')
->groups(['api', 'teams'])
->label('scope', 'teams.read') ->label('scope', 'teams.read')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')
@ -432,12 +436,12 @@ $utopia->get('/v1/teams/:teamId/memberships')
} }
$response->json(['sum' => $projectDB->getSum(), 'memberships' => $users]); $response->json(['sum' => $projectDB->getSum(), 'memberships' => $users]);
} }
); );
$utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
->desc('Update Team Membership Status') ->desc('Update Team Membership Status')
->groups(['api', 'teams'])
->label('scope', 'public') ->label('scope', 'public')
->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.platform', [APP_PLATFORM_CLIENT])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')
@ -542,7 +546,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
->setParam('resource', 'teams/'.$teamId) ->setParam('resource', 'teams/'.$teamId)
; ;
if(!Config::getParam('domainVerification')) { if (!Config::getParam('domainVerification')) {
$response $response
->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)]))
; ;
@ -569,6 +573,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
$utopia->delete('/v1/teams/:teamId/memberships/:inviteId') $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
->desc('Delete Team Membership') ->desc('Delete Team Membership')
->groups(['api', 'teams'])
->label('scope', 'teams.write') ->label('scope', 'teams.write')
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
->label('sdk.namespace', 'teams') ->label('sdk.namespace', 'teams')

View file

@ -21,10 +21,9 @@ use Appwrite\Database\Validator\UID;
use DeviceDetector\DeviceDetector; use DeviceDetector\DeviceDetector;
use GeoIp2\Database\Reader; use GeoIp2\Database\Reader;
include_once __DIR__ . '/../shared/api.php';
$utopia->post('/v1/users') $utopia->post('/v1/users')
->desc('Create User') ->desc('Create User')
->groups(['api', 'users'])
->label('scope', 'users.write') ->label('scope', 'users.write')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -93,6 +92,7 @@ $utopia->post('/v1/users')
$utopia->get('/v1/users') $utopia->get('/v1/users')
->desc('List Users') ->desc('List Users')
->groups(['api', 'users'])
->label('scope', 'users.read') ->label('scope', 'users.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -147,6 +147,7 @@ $utopia->get('/v1/users')
$utopia->get('/v1/users/:userId') $utopia->get('/v1/users/:userId')
->desc('Get User') ->desc('Get User')
->groups(['api', 'users'])
->label('scope', 'users.read') ->label('scope', 'users.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -188,6 +189,7 @@ $utopia->get('/v1/users/:userId')
$utopia->get('/v1/users/:userId/prefs') $utopia->get('/v1/users/:userId/prefs')
->desc('Get User Preferences') ->desc('Get User Preferences')
->groups(['api', 'users'])
->label('scope', 'users.read') ->label('scope', 'users.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -217,6 +219,7 @@ $utopia->get('/v1/users/:userId/prefs')
$utopia->get('/v1/users/:userId/sessions') $utopia->get('/v1/users/:userId/sessions')
->desc('Get User Sessions') ->desc('Get User Sessions')
->groups(['api', 'users'])
->label('scope', 'users.read') ->label('scope', 'users.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -280,6 +283,7 @@ $utopia->get('/v1/users/:userId/sessions')
$utopia->get('/v1/users/:userId/logs') $utopia->get('/v1/users/:userId/logs')
->desc('Get User Logs') ->desc('Get User Logs')
->groups(['api', 'users'])
->label('scope', 'users.read') ->label('scope', 'users.read')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -360,6 +364,7 @@ $utopia->get('/v1/users/:userId/logs')
$utopia->patch('/v1/users/:userId/status') $utopia->patch('/v1/users/:userId/status')
->desc('Update User Status') ->desc('Update User Status')
->groups(['api', 'users'])
->label('scope', 'users.write') ->label('scope', 'users.write')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -408,6 +413,7 @@ $utopia->patch('/v1/users/:userId/status')
$utopia->patch('/v1/users/:userId/prefs') $utopia->patch('/v1/users/:userId/prefs')
->desc('Update User Preferences') ->desc('Update User Preferences')
->groups(['api', 'users'])
->label('scope', 'users.write') ->label('scope', 'users.write')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -450,6 +456,7 @@ $utopia->patch('/v1/users/:userId/prefs')
$utopia->delete('/v1/users/:userId/sessions/:sessionId') $utopia->delete('/v1/users/:userId/sessions/:sessionId')
->desc('Delete User Session') ->desc('Delete User Session')
->groups(['api', 'users'])
->label('scope', 'users.write') ->label('scope', 'users.write')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')
@ -482,6 +489,7 @@ $utopia->delete('/v1/users/:userId/sessions/:sessionId')
$utopia->delete('/v1/users/:userId/sessions') $utopia->delete('/v1/users/:userId/sessions')
->desc('Delete User Sessions') ->desc('Delete User Sessions')
->groups(['api', 'users'])
->label('scope', 'users.write') ->label('scope', 'users.write')
->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.platform', [APP_PLATFORM_SERVER])
->label('sdk.namespace', 'users') ->label('sdk.namespace', 'users')

View file

@ -22,7 +22,6 @@ $utopia->get('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -37,7 +36,6 @@ $utopia->post('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -52,7 +50,6 @@ $utopia->patch('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -67,7 +64,6 @@ $utopia->put('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -82,7 +78,6 @@ $utopia->delete('/v1/mock/tests/foo')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -97,7 +92,6 @@ $utopia->get('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -112,7 +106,6 @@ $utopia->post('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -127,7 +120,6 @@ $utopia->patch('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -142,7 +134,6 @@ $utopia->put('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -157,7 +148,6 @@ $utopia->delete('/v1/mock/tests/bar')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(
function ($x, $y, $z) { function ($x, $y, $z) {
} }
); );
@ -180,19 +170,19 @@ $utopia->post('/v1/mock/tests/general/upload')
$file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']]; $file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']];
foreach ($file['name'] as $i => $name) { foreach ($file['name'] as $i => $name) {
if($name !== 'file.png') { if ($name !== 'file.png') {
throw new Exception('Wrong file name', 400); throw new Exception('Wrong file name', 400);
} }
} }
foreach ($file['size'] as $i => $size) { foreach ($file['size'] as $i => $size) {
if($size !== 38756) { if ($size !== 38756) {
throw new Exception('Wrong file size', 400); throw new Exception('Wrong file size', 400);
} }
} }
foreach ($file['tmp_name'] as $i => $tmpName) { foreach ($file['tmp_name'] as $i => $tmpName) {
if(\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') { if (\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
throw new Exception('Wrong file uploaded', 400); throw new Exception('Wrong file uploaded', 400);
} }
} }
@ -242,7 +232,7 @@ $utopia->get('/v1/mock/tests/general/get-cookie')
->label('sdk.description', 'Mock a get cookie request for SDK tests') ->label('sdk.description', 'Mock a get cookie request for SDK tests')
->action( ->action(
function () use ($request) { function () use ($request) {
if($request->getCookie('cookieName', '') !== 'cookieValue') { if ($request->getCookie('cookieName', '') !== 'cookieValue') {
throw new Exception('Missing cookie value', 400); throw new Exception('Missing cookie value', 400);
} }
} }
@ -285,15 +275,15 @@ $utopia->get('/v1/mock/tests/general/oauth2/token')
->param('code', '', function () { return new Text(100); }, 'OAuth2 state.') ->param('code', '', function () { return new Text(100); }, 'OAuth2 state.')
->action( ->action(
function ($clientId, $redirectURI, $clientSecret, $code) use ($response) { function ($clientId, $redirectURI, $clientSecret, $code) use ($response) {
if($clientId != '1') { if ($clientId != '1') {
throw new Exception('Invalid client ID'); throw new Exception('Invalid client ID');
} }
if($clientSecret != '123456') { if ($clientSecret != '123456') {
throw new Exception('Invalid client secret'); throw new Exception('Invalid client secret');
} }
if($code != 'abcdef') { if ($code != 'abcdef') {
throw new Exception('Invalid token'); throw new Exception('Invalid token');
} }
@ -308,7 +298,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/user')
->param('token', '', function () { return new Text(100); }, 'OAuth2 Access Token.') ->param('token', '', function () { return new Text(100); }, 'OAuth2 Access Token.')
->action( ->action(
function ($token) use ($response) { function ($token) use ($response) {
if($token != '123456') { if ($token != '123456') {
throw new Exception('Invalid token'); throw new Exception('Invalid token');
} }
@ -345,12 +335,11 @@ $utopia->get('/v1/mock/tests/general/oauth2/failure')
); );
$utopia->shutdown(function() use ($response, $request, &$result, $utopia) { $utopia->shutdown(function() use ($response, $request, &$result, $utopia) {
$route = $utopia->match($request); $route = $utopia->match($request);
$path = APP_STORAGE_CACHE.'/tests.json'; $path = APP_STORAGE_CACHE.'/tests.json';
$tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : []; $tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : [];
if(!\is_array($tests)) { if (!\is_array($tests)) {
throw new Exception('Failed to read results', 500); throw new Exception('Failed to read results', 500);
} }
@ -358,9 +347,9 @@ $utopia->shutdown(function() use ($response, $request, &$result, $utopia) {
$tests = \array_merge($tests, $result); $tests = \array_merge($tests, $result);
if(!\file_put_contents($path, \json_encode($tests), LOCK_EX)) { if (!\file_put_contents($path, \json_encode($tests), LOCK_EX)) {
throw new Exception('Failed to save resutls', 500); throw new Exception('Failed to save resutls', 500);
} }
$response->json(['result' => $route->getMethod() . ':' . $route->getURL() . ':passed']); $response->json(['result' => $route->getMethod() . ':' . $route->getURL() . ':passed']);
}); }, 'mock');

View file

@ -7,10 +7,9 @@ use Utopia\Abuse\Adapters\TimeLimit;
global $utopia, $request, $response, $register, $user, $project; global $utopia, $request, $response, $register, $user, $project;
$utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) { $utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) {
$route = $utopia->match($request); $route = $utopia->match($request);
if(empty($project->getId()) && $route->getLabel('abuse-limit', 0) > 0) { // Abuse limit requires an active project scope if (empty($project->getId()) && $route->getLabel('abuse-limit', 0) > 0) { // Abuse limit requires an active project scope
throw new Exception('Missing or unknown project ID', 400); throw new Exception('Missing or unknown project ID', 400);
} }
@ -37,7 +36,6 @@ $utopia->init(function () use ($utopia, $request, $response, $register, $user, $
$abuse = new Abuse($timeLimit); $abuse = new Abuse($timeLimit);
if ($timeLimit->limit()) { if ($timeLimit->limit()) {
$response $response
->addHeader('X-RateLimit-Limit', $timeLimit->limit()) ->addHeader('X-RateLimit-Limit', $timeLimit->limit())
->addHeader('X-RateLimit-Remaining', $timeLimit->remaining()) ->addHeader('X-RateLimit-Remaining', $timeLimit->remaining())
@ -48,4 +46,4 @@ $utopia->init(function () use ($utopia, $request, $response, $register, $user, $
if ($abuse->check() && $request->getServer('_APP_OPTIONS_ABUSE', 'enabled') !== 'disabled') { if ($abuse->check() && $request->getServer('_APP_OPTIONS_ABUSE', 'enabled') !== 'disabled') {
throw new Exception('Too many requests', 429); throw new Exception('Too many requests', 429);
} }
}); }, 'api');

View file

@ -2,36 +2,31 @@
use Utopia\View; use Utopia\View;
use Utopia\Config\Config; use Utopia\Config\Config;
use Utopia\Locale\Locale;
Locale::$exceptions = false;
$roles = [
['type' => 'owner', 'label' => 'Owner'],
['type' => 'developer', 'label' => 'Developer'],
['type' => 'admin', 'label' => 'Admin'],
];
$layout = new View(__DIR__.'/../../views/layouts/default.phtml'); $layout = new View(__DIR__.'/../../views/layouts/default.phtml');
/* AJAX check */
if (!empty($request->getQuery('version', ''))) {
$layout->setPath(__DIR__.'/../../views/layouts/empty.phtml');
}
$layout
->setParam('title', APP_NAME)
->setParam('protocol', Config::getParam('protocol'))
->setParam('domain', $domain)
->setParam('home', $request->getServer('_APP_HOME'))
->setParam('setup', $request->getServer('_APP_SETUP'))
->setParam('class', 'unknown')
->setParam('icon', '/images/favicon.png')
->setParam('roles', $roles)
->setParam('env', $utopia->getMode())
;
$utopia->init(function () use ($utopia, $response, $request, $layout) { $utopia->init(function () use ($utopia, $response, $request, $layout) {
/* AJAX check */
if (!empty($request->getQuery('version', ''))) {
$layout->setPath(__DIR__.'/../../views/layouts/empty.phtml');
}
$layout
->setParam('title', APP_NAME)
->setParam('protocol', Config::getParam('protocol'))
->setParam('domain', Config::getParam('domain'))
->setParam('home', $request->getServer('_APP_HOME'))
->setParam('setup', $request->getServer('_APP_SETUP'))
->setParam('class', 'unknown')
->setParam('icon', '/images/favicon.png')
->setParam('roles', [
['type' => 'owner', 'label' => 'Owner'],
['type' => 'developer', 'label' => 'Developer'],
['type' => 'admin', 'label' => 'Admin'],
])
->setParam('env', $utopia->getMode())
;
$time = (60 * 60 * 24 * 45); // 45 days cache $time = (60 * 60 * 24 * 45); // 45 days cache
$isDev = (\Utopia\App::MODE_TYPE_DEVELOPMENT == Config::getParam('env')); $isDev = (\Utopia\App::MODE_TYPE_DEVELOPMENT == Config::getParam('env'));
@ -47,4 +42,4 @@ $utopia->init(function () use ($utopia, $response, $request, $layout) {
->setParam('isDev', $isDev) ->setParam('isDev', $isDev)
->setParam('class', $scope) ->setParam('class', $scope)
; ;
}); }, 'web');

View file

@ -1,7 +1,5 @@
<?php <?php
include_once __DIR__ . '/../shared/web.php';
global $utopia, $response, $request, $layout, $projectDB; global $utopia, $response, $request, $layout, $projectDB;
use Utopia\View; use Utopia\View;
@ -17,7 +15,7 @@ $utopia->init(function () use ($layout) {
->setParam('description', 'Appwrite Console allows you to easily manage, monitor, and control your entire backend API and tools.') ->setParam('description', 'Appwrite Console allows you to easily manage, monitor, and control your entire backend API and tools.')
->setParam('analytics', 'UA-26264668-5') ->setParam('analytics', 'UA-26264668-5')
; ;
}); }, 'console');
$utopia->shutdown(function () use ($response, $request, $layout) { $utopia->shutdown(function () use ($response, $request, $layout) {
$header = new View(__DIR__.'/../../views/console/comps/header.phtml'); $header = new View(__DIR__.'/../../views/console/comps/header.phtml');
@ -34,10 +32,10 @@ $utopia->shutdown(function () use ($response, $request, $layout) {
; ;
$response->send($layout->render()); $response->send($layout->render());
}); }, 'console');
$utopia->get('/error/:code') $utopia->get('/error/:code')
->desc('Error page') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->param('code', null, new \Utopia\Validator\Numeric(), 'Valid status code number', false) ->param('code', null, new \Utopia\Validator\Numeric(), 'Valid status code number', false)
@ -54,6 +52,7 @@ $utopia->get('/error/:code')
}); });
$utopia->get('/console') $utopia->get('/console')
->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout, $request) { ->action(function () use ($layout, $request) {
@ -69,6 +68,7 @@ $utopia->get('/console')
}); });
$utopia->get('/console/account') $utopia->get('/console/account')
->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -86,7 +86,7 @@ $utopia->get('/console/account')
}); });
$utopia->get('/console/notifications') $utopia->get('/console/notifications')
->desc('Platform console notifications') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -98,7 +98,7 @@ $utopia->get('/console/notifications')
}); });
$utopia->get('/console/home') $utopia->get('/console/home')
->desc('Platform console project home') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -110,7 +110,7 @@ $utopia->get('/console/home')
}); });
$utopia->get('/console/settings') $utopia->get('/console/settings')
->desc('Platform console project settings') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($request, $layout) { ->action(function () use ($request, $layout) {
@ -129,7 +129,7 @@ $utopia->get('/console/settings')
}); });
$utopia->get('/console/webhooks') $utopia->get('/console/webhooks')
->desc('Platform console project webhooks') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -145,7 +145,7 @@ $utopia->get('/console/webhooks')
}); });
$utopia->get('/console/keys') $utopia->get('/console/keys')
->desc('Platform console project keys') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -160,7 +160,7 @@ $utopia->get('/console/keys')
}); });
$utopia->get('/console/tasks') $utopia->get('/console/tasks')
->desc('Platform console project tasks') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -172,7 +172,7 @@ $utopia->get('/console/tasks')
}); });
$utopia->get('/console/database') $utopia->get('/console/database')
->desc('Platform console project settings') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -184,7 +184,7 @@ $utopia->get('/console/database')
}); });
$utopia->get('/console/database/collection') $utopia->get('/console/database/collection')
->desc('Platform console project database collection') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->param('id', '', function () { return new UID(); }, 'Collection unique ID.') ->param('id', '', function () { return new UID(); }, 'Collection unique ID.')
@ -213,11 +213,10 @@ $utopia->get('/console/database/collection')
->addHeader('Expires', 0) ->addHeader('Expires', 0)
->addHeader('Pragma', 'no-cache') ->addHeader('Pragma', 'no-cache')
; ;
}); });
$utopia->get('/console/database/document') $utopia->get('/console/database/document')
->desc('Platform console project database document') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->param('collection', '', function () { return new UID(); }, 'Collection unique ID.') ->param('collection', '', function () { return new UID(); }, 'Collection unique ID.')
@ -247,7 +246,7 @@ $utopia->get('/console/database/document')
}); });
$utopia->get('/console/storage') $utopia->get('/console/storage')
->desc('Platform console project settings') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($request, $layout) { ->action(function () use ($request, $layout) {
@ -265,7 +264,7 @@ $utopia->get('/console/storage')
}); });
$utopia->get('/console/users') $utopia->get('/console/users')
->desc('Platform console project settings') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -279,7 +278,7 @@ $utopia->get('/console/users')
}); });
$utopia->get('/console/users/user') $utopia->get('/console/users/user')
->desc('Platform console project user') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -291,7 +290,7 @@ $utopia->get('/console/users/user')
}); });
$utopia->get('/console/users/teams/team') $utopia->get('/console/users/teams/team')
->desc('Platform console project team') ->groups(['web', 'console'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'console') ->label('scope', 'console')
->action(function () use ($layout) { ->action(function () use ($layout) {

View file

@ -1,7 +1,5 @@
<?php <?php
include_once __DIR__ . '/../shared/web.php';
global $utopia, $response, $request, $layout; global $utopia, $response, $request, $layout;
use Utopia\View; use Utopia\View;
@ -9,27 +7,30 @@ use Utopia\Config\Config;
use Utopia\Validator\WhiteList; use Utopia\Validator\WhiteList;
use Utopia\Validator\Range; use Utopia\Validator\Range;
$header = new View(__DIR__.'/../../views/home/comps/header.phtml'); $utopia->init(function () use ($layout) {
$footer = new View(__DIR__.'/../../views/home/comps/footer.phtml'); $header = new View(__DIR__.'/../../views/home/comps/header.phtml');
$footer = new View(__DIR__.'/../../views/home/comps/footer.phtml');
$footer $footer
->setParam('version', Config::getParam('version')) ->setParam('version', Config::getParam('version'))
; ;
$layout $layout
->setParam('title', APP_NAME) ->setParam('title', APP_NAME)
->setParam('description', '') ->setParam('description', '')
->setParam('class', 'home') ->setParam('class', 'home')
->setParam('platforms', Config::getParam('platforms')) ->setParam('platforms', Config::getParam('platforms'))
->setParam('header', [$header]) ->setParam('header', [$header])
->setParam('footer', [$footer]) ->setParam('footer', [$footer])
; ;
}, 'home');
$utopia->shutdown(function () use ($response, $layout) { $utopia->shutdown(function () use ($response, $layout) {
$response->send($layout->render()); $response->send($layout->render());
}); }, 'home');
$utopia->get('/') $utopia->get('/')
->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action( ->action(
@ -39,7 +40,7 @@ $utopia->get('/')
); );
$utopia->get('/auth/signin') $utopia->get('/auth/signin')
->desc('Login page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -51,7 +52,7 @@ $utopia->get('/auth/signin')
}); });
$utopia->get('/auth/signup') $utopia->get('/auth/signup')
->desc('Registration page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -63,7 +64,7 @@ $utopia->get('/auth/signup')
}); });
$utopia->get('/auth/recovery') $utopia->get('/auth/recovery')
->desc('Password recovery page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action(function () use ($request, $layout) { ->action(function () use ($request, $layout) {
@ -75,7 +76,7 @@ $utopia->get('/auth/recovery')
}); });
$utopia->get('/auth/confirm') $utopia->get('/auth/confirm')
->desc('Account confirmation page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -87,7 +88,7 @@ $utopia->get('/auth/confirm')
}); });
$utopia->get('/auth/join') $utopia->get('/auth/join')
->desc('Account team join page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -99,7 +100,7 @@ $utopia->get('/auth/join')
}); });
$utopia->get('/auth/recovery/reset') $utopia->get('/auth/recovery/reset')
->desc('Password recovery page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -112,7 +113,7 @@ $utopia->get('/auth/recovery/reset')
$utopia->get('/auth/oauth2/success') $utopia->get('/auth/oauth2/success')
->desc('Registration page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -127,7 +128,7 @@ $utopia->get('/auth/oauth2/success')
}); });
$utopia->get('/auth/oauth2/failure') $utopia->get('/auth/oauth2/failure')
->desc('Registration page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->action(function () use ($layout) { ->action(function () use ($layout) {
@ -142,7 +143,7 @@ $utopia->get('/auth/oauth2/failure')
}); });
$utopia->get('/error/:code') $utopia->get('/error/:code')
->desc('Error page') ->groups(['web', 'home'])
->label('permission', 'public') ->label('permission', 'public')
->label('scope', 'home') ->label('scope', 'home')
->param('code', null, new \Utopia\Validator\Numeric(), 'Valid status code number', false) ->param('code', null, new \Utopia\Validator\Numeric(), 'Valid status code number', false)
@ -159,13 +160,16 @@ $utopia->get('/error/:code')
}); });
$utopia->get('/open-api-2.json') $utopia->get('/open-api-2.json')
->groups(['web', 'home'])
->label('scope', 'public') ->label('scope', 'public')
->label('docs', false) ->label('docs', false)
->param('platform', APP_PLATFORM_CLIENT, function () {return new WhiteList([APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER, APP_PLATFORM_CONSOLE]);}, 'Choose target platform.', true) ->param('platform', APP_PLATFORM_CLIENT, function () {return new WhiteList([APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER, APP_PLATFORM_CONSOLE]);}, 'Choose target platform.', true)
->param('extensions', 0, function () {return new Range(0, 1);}, 'Show extra data.', true) ->param('extensions', 0, function () {return new Range(0, 1);}, 'Show extra data.', true)
->param('tests', 0, function () {return new Range(0, 1);}, 'Include only test services.', true) ->param('tests', 0, function () {return new Range(0, 1);}, 'Include only test services.', true)
->action( ->action(
function ($platform, $extensions, $tests) use ($response, $request, $utopia, $services) { function ($platform, $extensions, $tests) use ($response, $request, $utopia) {
$services = Config::getParam('services', []);
function fromCamelCase($input) function fromCamelCase($input)
{ {
\preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches); \preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
@ -183,11 +187,11 @@ $utopia->get('/open-api-2.json')
} }
foreach ($services as $service) { /* @noinspection PhpIncludeInspection */ foreach ($services as $service) { /* @noinspection PhpIncludeInspection */
if($tests && !isset($service['tests'])) { if ($tests && !isset($service['tests'])) {
continue; continue;
} }
if($tests && !$service['tests']) { if ($tests && !$service['tests']) {
continue; continue;
} }
@ -347,19 +351,19 @@ $utopia->get('/open-api-2.json')
]; ];
if ($extensions) { if ($extensions) {
if(isset($output['securityDefinitions']['Project'])) { if (isset($output['securityDefinitions']['Project'])) {
$output['securityDefinitions']['Project']['extensions'] = ['demo' => '5df5acd0d48c2']; $output['securityDefinitions']['Project']['extensions'] = ['demo' => '5df5acd0d48c2'];
} }
if(isset($output['securityDefinitions']['Key'])) { if (isset($output['securityDefinitions']['Key'])) {
$output['securityDefinitions']['Key']['extensions'] = ['demo' => '919c2d18fb5d4...a2ae413da83346ad2']; $output['securityDefinitions']['Key']['extensions'] = ['demo' => '919c2d18fb5d4...a2ae413da83346ad2'];
} }
if(isset($output['securityDefinitions']['Locale'])) { if (isset($output['securityDefinitions']['Locale'])) {
$output['securityDefinitions']['Locale']['extensions'] = ['demo' => 'en']; $output['securityDefinitions']['Locale']['extensions'] = ['demo' => 'en'];
} }
if(isset($output['securityDefinitions']['Mode'])) { if (isset($output['securityDefinitions']['Mode'])) {
$output['securityDefinitions']['Mode']['extensions'] = ['demo' => '']; $output['securityDefinitions']['Mode']['extensions'] = ['demo' => ''];
} }
} }
@ -374,7 +378,7 @@ $utopia->get('/open-api-2.json')
continue; continue;
} }
if($platform !== APP_PLATFORM_CONSOLE && !\in_array($platforms[$platform], $route->getLabel('sdk.platform', []))) { if ($platform !== APP_PLATFORM_CONSOLE && !\in_array($platforms[$platform], $route->getLabel('sdk.platform', []))) {
continue; continue;
} }

View file

@ -62,6 +62,8 @@ Config::load('providers', __DIR__.'/../app/config/providers.php');
Config::load('platforms', __DIR__.'/../app/config/platforms.php'); Config::load('platforms', __DIR__.'/../app/config/platforms.php');
Config::load('locales', __DIR__.'/../app/config/locales.php'); Config::load('locales', __DIR__.'/../app/config/locales.php');
Config::load('collections', __DIR__.'/../app/config/collections.php'); Config::load('collections', __DIR__.'/../app/config/collections.php');
Config::load('roles', __DIR__.'/../app/config/roles.php'); // User roles and scopes
Config::load('services', __DIR__.'/../app/config/services.php'); // List of services
Config::setParam('env', $utopia->getMode()); Config::setParam('env', $utopia->getMode());
Config::setParam('domain', $request->getServer('HTTP_HOST', '')); Config::setParam('domain', $request->getServer('HTTP_HOST', ''));

View file

@ -4,6 +4,8 @@ export PHP_VERSION=$PHP_VERSION
chown -Rf www-data.www-data /usr/share/nginx/html/ chown -Rf www-data.www-data /usr/share/nginx/html/
sed 's/%_APP_STORAGE_LIMIT%/'$_APP_STORAGE_LIMIT'/g' /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
# Function to update the fpm configuration to make the service environment variables available # Function to update the fpm configuration to make the service environment variables available
function setEnvironmentVariable() { function setEnvironmentVariable() {
if [ -z "$2" ]; then if [ -z "$2" ]; then

View file

@ -32,7 +32,7 @@
"appwrite/php-clamav": "1.0.*", "appwrite/php-clamav": "1.0.*",
"utopia-php/framework": "0.3.5", "utopia-php/framework": "0.4.0",
"utopia-php/abuse": "0.2.*", "utopia-php/abuse": "0.2.*",
"utopia-php/audit": "0.3.*", "utopia-php/audit": "0.3.*",
"utopia-php/cache": "0.2.*", "utopia-php/cache": "0.2.*",

44
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9deec50e5a99197511b5efbcaa9593bd", "content-hash": "7f6cbe77fe2e0f8bdff33c37a4d9ca11",
"packages": [ "packages": [
{ {
"name": "appwrite/php-clamav", "name": "appwrite/php-clamav",
@ -459,24 +459,24 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/guzzle/promises.git", "url": "https://github.com/guzzle/promises.git",
"reference": "89b1a76b7fda5853401297dc4b2a093cba1fda23" "reference": "bbf3b200bc83c1e9298580a9f99b9be248543467"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/89b1a76b7fda5853401297dc4b2a093cba1fda23", "url": "https://api.github.com/repos/guzzle/promises/zipball/bbf3b200bc83c1e9298580a9f99b9be248543467",
"reference": "89b1a76b7fda5853401297dc4b2a093cba1fda23", "reference": "bbf3b200bc83c1e9298580a9f99b9be248543467",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.6" "php": ">=5.5"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^5.7.27 || ^7.5" "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^7.5"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.4-dev" "dev-master": "1.3-dev"
} }
}, },
"autoload": { "autoload": {
@ -502,7 +502,7 @@
"keywords": [ "keywords": [
"promise" "promise"
], ],
"time": "2020-02-15T23:33:03+00:00" "time": "2020-06-21T23:10:57+00:00"
}, },
{ {
"name": "guzzlehttp/psr7", "name": "guzzlehttp/psr7",
@ -1546,16 +1546,16 @@
}, },
{ {
"name": "utopia-php/domains", "name": "utopia-php/domains",
"version": "0.2.0", "version": "0.2.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/domains.git", "url": "https://github.com/utopia-php/domains.git",
"reference": "1665e1d9932afa3be63b5c1e0dcfe01fe77d8e73" "reference": "98e85296867a59c9d712d6ed768a5c5b2b297b43"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/domains/zipball/1665e1d9932afa3be63b5c1e0dcfe01fe77d8e73", "url": "https://api.github.com/repos/utopia-php/domains/zipball/98e85296867a59c9d712d6ed768a5c5b2b297b43",
"reference": "1665e1d9932afa3be63b5c1e0dcfe01fe77d8e73", "reference": "98e85296867a59c9d712d6ed768a5c5b2b297b43",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1592,20 +1592,20 @@
"upf", "upf",
"utopia" "utopia"
], ],
"time": "2020-02-23T07:40:02+00:00" "time": "2020-06-20T11:47:04+00:00"
}, },
{ {
"name": "utopia-php/framework", "name": "utopia-php/framework",
"version": "0.3.5", "version": "0.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/framework.git", "url": "https://github.com/utopia-php/framework.git",
"reference": "ca2ebe37936983d786f57bae8ee6e006299f4942" "reference": "30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/ca2ebe37936983d786f57bae8ee6e006299f4942", "url": "https://api.github.com/repos/utopia-php/framework/zipball/30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5",
"reference": "ca2ebe37936983d786f57bae8ee6e006299f4942", "reference": "30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1636,7 +1636,7 @@
"php", "php",
"upf" "upf"
], ],
"time": "2020-06-20T11:33:46+00:00" "time": "2020-06-25T18:21:48+00:00"
}, },
{ {
"name": "utopia-php/locale", "name": "utopia-php/locale",
@ -3307,12 +3307,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "3beabd64bdc91558b41f140cc4b14925f0416cb2" "reference": "f32950c872a995a93807909bab69387f47afaa25"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/3beabd64bdc91558b41f140cc4b14925f0416cb2", "url": "https://api.github.com/repos/twigphp/Twig/zipball/f32950c872a995a93807909bab69387f47afaa25",
"reference": "3beabd64bdc91558b41f140cc4b14925f0416cb2", "reference": "f32950c872a995a93807909bab69387f47afaa25",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3364,7 +3364,7 @@
"keywords": [ "keywords": [
"templating" "templating"
], ],
"time": "2020-06-08T10:41:25+00:00" "time": "2020-06-22T15:25:21+00:00"
}, },
{ {
"name": "webmozart/assert", "name": "webmozart/assert",

View file

@ -54,7 +54,6 @@ services:
- ./docs:/usr/share/nginx/html/docs - ./docs:/usr/share/nginx/html/docs
- ./public:/usr/share/nginx/html/public - ./public:/usr/share/nginx/html/public
- ./src:/usr/share/nginx/html/src - ./src:/usr/share/nginx/html/src
- ./docker/nginx.conf:/etc/nginx/nginx.conf
depends_on: depends_on:
- mariadb - mariadb
- redis - redis

View file

@ -16,7 +16,7 @@ http {
tcp_nodelay on; tcp_nodelay on;
keepalive_timeout 65; keepalive_timeout 65;
types_hash_max_size 2048; types_hash_max_size 2048;
client_max_body_size 10M; client_max_body_size %_APP_STORAGE_LIMIT%;
# server_names_hash_bucket_size 64; # server_names_hash_bucket_size 64;
# server_name_in_redirect off; # server_name_in_redirect off;

View file

@ -1,3 +1,3 @@
Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provider to be attached to the verification email. The provided URL should redirect the user back for your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](/docs/client/account#updateAccountVerification). Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](/docs/client/account#updateAccountVerification).
Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface. Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.

View file

@ -16,19 +16,8 @@ ini_set('display_errors', 0);
// error_reporting(E_ALL); // error_reporting(E_ALL);
$path = (isset($_GET['q'])) ? explode('/', $_GET['q']) : []; $path = (isset($_GET['q'])) ? explode('/', $_GET['q']) : [];
$domain = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : '';
array_shift($path); array_shift($path);
$version = array_shift($path); $version = array_shift($path);
switch ($version) { // Switch between API version include __DIR__ . '/../app/app.php';
case 'v1':
$service = $version . '/' . array_shift($path);
include __DIR__ . '/../app/app.php';
break;
case 'console':
default:
$service = $version . '/';
include __DIR__ . '/../app/app.php';
break;
}

View file

@ -44,7 +44,7 @@ abstract class OAuth2
$this->appSecret = $appSecret; $this->appSecret = $appSecret;
$this->callback = $callback; $this->callback = $callback;
$this->state = $state; $this->state = $state;
foreach($scopes as $scope) { foreach ($scopes as $scope) {
$this->addScope($scope); $this->addScope($scope);
} }
} }
@ -89,21 +89,21 @@ abstract class OAuth2
/** /**
* @param $scope * @param $scope
* *
* @return $this * @return $this
*/ */
protected function addScope(string $scope):OAuth2 protected function addScope(string $scope):OAuth2
{ {
// Add a scope to the scopes array if it isn't already present // Add a scope to the scopes array if it isn't already present
if (!\in_array($scope, $this->scopes)){ if (!\in_array($scope, $this->scopes)) {
$this->scopes[] = $scope; $this->scopes[] = $scope;
} }
return $this; return $this;
} }
/** /**
* @return array * @return array
*/ */
protected function getScopes():array protected function getScopes():array
{ {
return $this->scopes; return $this->scopes;

View file

@ -19,7 +19,7 @@ class Apple extends OAuth2
* @var array * @var array
*/ */
protected $scopes = [ protected $scopes = [
"name", "name",
"email" "email"
]; ];
@ -166,7 +166,9 @@ class Apple extends OAuth2
$success = \openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256); $success = \openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256);
if (!$success) return ''; if (!$success) {
return '';
}
return $payload.'.'.$this->encode($this->fromDER($signature, 64)); return $payload.'.'.$this->encode($this->fromDER($signature, 64));
} }
@ -205,8 +207,7 @@ class Apple extends OAuth2
if ('81' === \mb_substr($hex, 2, 2, '8bit')) { // LENGTH > 128 if ('81' === \mb_substr($hex, 2, 2, '8bit')) { // LENGTH > 128
$hex = \mb_substr($hex, 6, null, '8bit'); $hex = \mb_substr($hex, 6, null, '8bit');
} } else {
else {
$hex = \mb_substr($hex, 4, null, '8bit'); $hex = \mb_substr($hex, 4, null, '8bit');
} }
if ('02' !== \mb_substr($hex, 0, 2, '8bit')) { // INTEGER if ('02' !== \mb_substr($hex, 0, 2, '8bit')) { // INTEGER

View file

@ -58,7 +58,7 @@ class Facebook extends OAuth2
'redirect_uri' => $this->callback, 'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret, 'client_secret' => $this->appSecret,
'code' => $code 'code' => $code
]) ])
); );
$accessToken = \json_decode($accessToken, true); $accessToken = \json_decode($accessToken, true);

View file

@ -37,7 +37,6 @@ class Github extends OAuth2
'scope' => \implode(' ', $this->getScopes()), 'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state) 'state' => \json_encode($this->state)
]); ]);
} }
/** /**

View file

@ -4,7 +4,7 @@ namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2;
// Reference Material // Reference Material
// https://docs.gitlab.com/ee/api/oauth2.html // https://docs.gitlab.com/ee/api/oauth2.html
class Gitlab extends OAuth2 class Gitlab extends OAuth2

View file

@ -4,7 +4,7 @@ namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2;
// Reference Material // Reference Material
// https://developers.google.com/oauthplayground/ // https://developers.google.com/oauthplayground/
// https://developers.google.com/identity/protocols/OAuth2 // https://developers.google.com/identity/protocols/OAuth2
// https://developers.google.com/identity/protocols/OAuth2WebServer // https://developers.google.com/identity/protocols/OAuth2WebServer

View file

@ -19,7 +19,7 @@ class Microsoft extends OAuth2
* @var array * @var array
*/ */
protected $scopes = [ protected $scopes = [
'offline_access', 'offline_access',
'user.read' 'user.read'
]; ];

View file

@ -134,4 +134,4 @@ class Mock extends OAuth2
return $this->user; return $this->user;
} }
} }

View file

@ -15,8 +15,8 @@ class Slack extends OAuth2
* @var array * @var array
*/ */
protected $scopes = [ protected $scopes = [
'identity.avatar', 'identity.avatar',
'identity.basic', 'identity.basic',
'identity.email', 'identity.email',
'identity.team' 'identity.team'
]; ];
@ -125,7 +125,6 @@ class Slack extends OAuth2
*/ */
protected function getUser(string $accessToken):array protected function getUser(string $accessToken):array
{ {
if (empty($this->user)) { if (empty($this->user)) {
// https://api.slack.com/methods/users.identity // https://api.slack.com/methods/users.identity
$user = $this->request( $user = $this->request(

View file

@ -137,8 +137,11 @@ class Spotify extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
if (empty($this->user)) { if (empty($this->user)) {
$this->user = \json_decode($this->request('GET', $this->user = \json_decode($this->request(
$this->resourceEndpoint . "me", ['Authorization: Bearer '.\urlencode($accessToken)]), true); 'GET',
$this->resourceEndpoint . "me",
['Authorization: Bearer '.\urlencode($accessToken)]
), true);
} }
return $this->user; return $this->user;

View file

@ -139,8 +139,11 @@ class Twitch extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
if (empty($this->user)) { if (empty($this->user)) {
$this->user = \json_decode($this->request('GET', $this->user = \json_decode($this->request(
$this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true)['data']['0']; 'GET',
$this->resourceEndpoint,
['Authorization: Bearer '.\urlencode($accessToken)]
), true)['data']['0'];
} }
return $this->user; return $this->user;

View file

@ -153,8 +153,11 @@ class Yahoo extends OAuth2
protected function getUser(string $accessToken) protected function getUser(string $accessToken)
{ {
if (empty($this->user)) { if (empty($this->user)) {
$this->user = \json_decode($this->request('GET', $this->user = \json_decode($this->request(
$this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true); 'GET',
$this->resourceEndpoint,
['Authorization: Bearer '.\urlencode($accessToken)]
), true);
} }
return $this->user; return $this->user;

View file

@ -175,7 +175,7 @@ class MySQL extends Adapter
$result = $st->fetch(); $result = $st->fetch();
if($result && isset($result['signature'])) { if ($result && isset($result['signature'])) {
$oldSignature = $result['signature']; $oldSignature = $result['signature'];
if ($signature === $oldSignature) { if ($signature === $oldSignature) {
@ -187,14 +187,14 @@ class MySQL extends Adapter
/** /**
* Check Unique Keys * Check Unique Keys
*/ */
foreach($unique as $key => $value) { foreach ($unique as $key => $value) {
$st = $this->getPDO()->prepare('INSERT INTO `'.$this->getNamespace().'.database.unique` $st = $this->getPDO()->prepare('INSERT INTO `'.$this->getNamespace().'.database.unique`
SET `key` = :key; SET `key` = :key;
'); ');
$st->bindValue(':key', \md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR); $st->bindValue(':key', \md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR);
if(!$st->execute()) { if (!$st->execute()) {
throw new Duplicate('Duplicated Property: '.$key.'='.$value); throw new Duplicate('Duplicated Property: '.$key.'='.$value);
} }
} }

View file

@ -134,7 +134,7 @@ class Document extends ArrayObject
*/ */
public function removeAttribute($key) public function removeAttribute($key)
{ {
if(isset($this[$key])) { if (isset($this[$key])) {
unset($this[$key]); unset($this[$key]);
} }

View file

@ -111,7 +111,7 @@ class Authorization extends Validator
/** /**
* Default value in case we need * Default value in case we need
* to reset Authorization status * to reset Authorization status
* *
* @var bool * @var bool
*/ */
public static $statusDefault = true; public static $statusDefault = true;
@ -119,9 +119,10 @@ class Authorization extends Validator
/** /**
* Change default status. * Change default status.
* This will be used for the * This will be used for the
* value set on the self::reset() method * value set on the self::reset() method
*/ */
public static function setDefaultStatus($status) { public static function setDefaultStatus($status)
{
self::$statusDefault = $status; self::$statusDefault = $status;
self::$status = $status; self::$status = $status;
} }

View file

@ -60,19 +60,19 @@ class DocumentId extends Validator
{ {
$document = $this->database->getDocument($id); $document = $this->database->getDocument($id);
if(!$document) { if (!$document) {
return false; return false;
} }
if(!$document instanceof Document) { if (!$document instanceof Document) {
return false; return false;
} }
if(!$document->getId()) { if (!$document->getId()) {
return false; return false;
} }
if($document->getCollection() !== $this->collection) { if ($document->getCollection() !== $this->collection) {
return false; return false;
} }

View file

@ -34,7 +34,7 @@ class Key extends Validator
*/ */
public function isValid($value) public function isValid($value)
{ {
if(!\is_string($value)) { if (!\is_string($value)) {
return false; return false;
} }

View file

@ -26,7 +26,7 @@ class CNAME extends Validator
/** /**
* Check if CNAME record target value matches selected target * Check if CNAME record target value matches selected target
* *
* @param string $domain * @param string $domain
* *
* @return bool * @return bool
@ -39,12 +39,12 @@ class CNAME extends Validator
return false; return false;
} }
if(!$records || !\is_array($records)) { if (!$records || !\is_array($records)) {
return false; return false;
} }
foreach($records as $record) { foreach ($records as $record) {
if(isset($record['target']) && $record['target'] === $this->target) { if (isset($record['target']) && $record['target'] === $this->target) {
return true; return true;
} }
} }

View file

@ -56,7 +56,7 @@ class Origin extends Validator
*/ */
public function __construct($platforms) public function __construct($platforms)
{ {
foreach($platforms as $platform) { foreach ($platforms as $platform) {
$type = (isset($platform['type'])) ? $platform['type'] : ''; $type = (isset($platform['type'])) ? $platform['type'] : '';
switch ($type) { switch ($type) {
@ -81,7 +81,7 @@ class Origin extends Validator
public function getDescription() public function getDescription()
{ {
if(!\array_key_exists($this->client, $this->platforms)) { if (!\array_key_exists($this->client, $this->platforms)) {
return 'Unsupported platform'; return 'Unsupported platform';
} }
@ -92,7 +92,7 @@ class Origin extends Validator
/** /**
* Check if Origin has been whiltlisted * Check if Origin has been whiltlisted
* for access to the API * for access to the API
* *
* @param string $origin * @param string $origin
* *
* @return bool * @return bool
@ -105,11 +105,11 @@ class Origin extends Validator
$this->host = $host; $this->host = $host;
$this->client = $scheme; $this->client = $scheme;
if(empty($host)) { if (empty($host)) {
return true; return true;
} }
if(\in_array($host, $this->clients)) { if (\in_array($host, $this->clients)) {
return true; return true;
} }

View file

@ -157,16 +157,15 @@ class Local extends Device
*/ */
public function delete(string $path, bool $recursive = false):bool public function delete(string $path, bool $recursive = false):bool
{ {
if(\is_dir($path) && $recursive) { if (\is_dir($path) && $recursive) {
$files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned $files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned
foreach($files as $file) { foreach ($files as $file) {
$this->delete($file, true); $this->delete($file, true);
} }
\rmdir($path); \rmdir($path);
} } elseif (\is_file($path)) {
elseif(\is_file($path)) {
return \unlink($path); return \unlink($path);
} }

View file

@ -78,7 +78,7 @@ class Storage
* *
* @return string * @return string
*/ */
static public function human($bytes, $decimals = 2) public static function human($bytes, $decimals = 2)
{ {
$units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$step = 1024; $step = 1024;

View file

@ -64,7 +64,7 @@ class FileType extends Validator
*/ */
public function isValid($path) public function isValid($path)
{ {
if(!\is_readable($path)) { if (!\is_readable($path)) {
return false; return false;
} }

View file

@ -6,14 +6,14 @@ class URL
{ {
/** /**
* Parse URL * Parse URL
* *
* Take a URL string and split it to array parts * Take a URL string and split it to array parts
* *
* @param string $url * @param string $url
* *
* @return array * @return array
*/ */
static public function parse(string $url):array public static function parse(string $url):array
{ {
$default = [ $default = [
'scheme' => '', 'scheme' => '',
@ -31,15 +31,15 @@ class URL
/** /**
* Un-Parse URL * Un-Parse URL
* *
* Take URL parts and combine them to a valid string * Take URL parts and combine them to a valid string
* *
* @param array $url * @param array $url
* @param array $ommit * @param array $ommit
* *
* @return string * @return string
*/ */
static public function unparse(array $url, array $ommit = []):string public static function unparse(array $url, array $ommit = []):string
{ {
if (isset($url['path']) && \mb_substr($url['path'], 0, 1) !== '/') { if (isset($url['path']) && \mb_substr($url['path'], 0, 1) !== '/') {
$url['path'] = '/'.$url['path']; $url['path'] = '/'.$url['path'];
@ -78,14 +78,14 @@ class URL
/** /**
* Parse Query String * Parse Query String
* *
* Convert query string to array * Convert query string to array
* *
* @param string $query * @param string $query
* *
* @return array * @return array
*/ */
static public function parseQuery(string $query):array public static function parseQuery(string $query):array
{ {
\parse_str($query, $result); \parse_str($query, $result);
@ -94,15 +94,15 @@ class URL
/** /**
* Un-Parse Query String * Un-Parse Query String
* *
* Convert query string array to string * Convert query string array to string
* *
* @param string $query * @param string $query
* *
* @return array * @return array
*/ */
static public function unparseQuery(array $query):string public static function unparseQuery(array $query):string
{ {
return \http_build_query($query); return \http_build_query($query);
} }
} }

View file

@ -173,7 +173,7 @@ class HealthCustomClientTest extends Scope
$this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']); $this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']); $this->assertLessThan(120, $response['body']['size']);
/** /**
* Test for FAILURE * Test for FAILURE