diff --git a/CHANGES.md b/CHANGES.md index 77d4d28f61..35f4a6ce92 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,10 @@ - Renamed *Devices* to *Sessions* - Add Provider Icon to each Session - Add Anonymous Account Placeholder -- Upgraded telegraf docker image version to v1.1.0 +- Upgraded telegraf docker image version to v1.2.0 +- Added new environment variables to the `telegraf` service: + - _APP_INFLUXDB_HOST + - _APP_INFLUXDB_PORT - Added `expires` parameter to Account Recovery and Email Validation URL's ## Bugs diff --git a/app/config/locale/templates/email-base.tpl b/app/config/locale/templates/email-base.tpl index 561ce73855..c9b730f46e 100644 --- a/app/config/locale/templates/email-base.tpl +++ b/app/config/locale/templates/email-base.tpl @@ -56,13 +56,13 @@ .main { background: {{bg-content}}; - border-radius: 3px; + border-radius: 10px; width: 100%; } .wrapper { box-sizing: border-box; - padding: 20px; + padding: 30px 30px 15px 30px; } .content-block { @@ -97,16 +97,15 @@ .btn table td { background-color: {{bg-content}}; - border-radius: 5px; + border-radius: 20px; text-align: center; } .btn a { background-color: {{bg-content}}; - border: solid 1px {{bg-cta}}; - border-radius: 5px; + border-radius: 20px; box-sizing: border-box; - color: #3498db; + color: #577590; cursor: pointer; display: inline-block; font-size: 14px; @@ -123,45 +122,17 @@ .btn-primary a { background-color: {{bg-cta}}; - border-color: {{bg-cta}}; color: {{text-cta}}; } @media only screen and (max-width: 620px) { - table[class=body] h1 { - font-size: 28px !important; - margin-bottom: 10px !important; + .container { + padding: 0; + width: 100%; } - table[class=body] p { - font-size: 16px !important; - } - - table[class=body] .wrapper { - padding: 10px !important; - } - - table[class=body] .content { - padding: 0 !important; - } - - table[class=body] .container { - padding: 0 !important; - width: 100% !important; - } - - table[class=body] .main { - border-left-width: 0 !important; - border-radius: 0 !important; - border-right-width: 0 !important; - } - - table[class=body] .btn table { - width: 100% !important; - } - - table[class=body] .btn a { - width: 100% !important; + .btn-primary a { + font-size: 13px; } } @@ -198,12 +169,11 @@ } .btn-primary table td:hover { - background-color: {{bg-cta-hover}} !important; + opacity: 0.7 !important; } .btn-primary a:hover { - background-color: {{bg-cta-hover}} !important; - border-color: {{bg-cta-hover}} !important; + opacity: 0.7 !important; } } @@ -220,15 +190,17 @@ - +
- {{content}} - {{content}}
+ +   diff --git a/app/config/platforms.php b/app/config/platforms.php index deec77d98e..9f83e63028 100644 --- a/app/config/platforms.php +++ b/app/config/platforms.php @@ -109,19 +109,20 @@ return [ 'gitUserName' => 'appwrite', ], [ - 'key' => 'kotlin', - 'name' => 'Kotlin', - 'url' => '', - 'package' => '', - 'enabled' => false, - 'beta' => false, + 'key' => 'android', + 'name' => 'Android', + 'version' => '0.0.0-SNAPSHOT', + 'url' => 'https://github.com/appwrite/sdk-for-android', + 'package' => 'https://repo1.maven.org/maven2/io/appwrite/sdk-for-android/', + 'enabled' => true, + 'beta' => true, 'dev' => false, 'hidden' => false, 'family' => APP_PLATFORM_CLIENT, 'prism' => 'kotlin', - 'source' => false, - 'gitUrl' => 'git@github.com:appwrite/sdk-for-kotlin.git', - 'gitRepoName' => 'sdk-for-kotlin', + 'source' => \realpath(__DIR__ . '/../sdks/client-android'), + 'gitUrl' => 'git@github.com:appwrite/sdk-for-android.git', + 'gitRepoName' => 'sdk-for-android', 'gitUserName' => 'appwrite', ], // [ diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 26ebcb6d99..87e1175b21 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1468,17 +1468,16 @@ App::post('/v1/account/recovery') $cta = new Template(__DIR__.'/../../config/locale/templates/email-cta.tpl'); $body - ->setParam('{{content}}', $content->render()) + ->setParam('{{content}}', $content->render(false)) ->setParam('{{cta}}', $cta->render()) ->setParam('{{title}}', $locale->getText('account.emails.recovery.title')) ->setParam('{{direction}}', $locale->getText('settings.direction')) ->setParam('{{project}}', $project->getAttribute('name', ['[APP-NAME]'])) ->setParam('{{name}}', $profile->getAttribute('name')) ->setParam('{{redirect}}', $url) - ->setParam('{{bg-body}}', '#f6f6f6') + ->setParam('{{bg-body}}', '#f7f7f7') ->setParam('{{bg-content}}', '#ffffff') - ->setParam('{{bg-cta}}', '#3498db') - ->setParam('{{bg-cta-hover}}', '#34495e') + ->setParam('{{bg-cta}}', '#073b4c') ->setParam('{{text-content}}', '#000000') ->setParam('{{text-cta}}', '#ffffff') ; @@ -1673,17 +1672,16 @@ App::post('/v1/account/verification') $cta = new Template(__DIR__.'/../../config/locale/templates/email-cta.tpl'); $body - ->setParam('{{content}}', $content->render()) + ->setParam('{{content}}', $content->render(false)) ->setParam('{{cta}}', $cta->render()) ->setParam('{{title}}', $locale->getText('account.emails.verification.title')) ->setParam('{{direction}}', $locale->getText('settings.direction')) ->setParam('{{project}}', $project->getAttribute('name', ['[APP-NAME]'])) ->setParam('{{name}}', $user->getAttribute('name')) ->setParam('{{redirect}}', $url) - ->setParam('{{bg-body}}', '#f6f6f6') + ->setParam('{{bg-body}}', '#f7f7f7') ->setParam('{{bg-content}}', '#ffffff') - ->setParam('{{bg-cta}}', '#3498db') - ->setParam('{{bg-cta-hover}}', '#34495e') + ->setParam('{{bg-cta}}', '#073b4c') ->setParam('{{text-content}}', '#000000') ->setParam('{{text-cta}}', '#ffffff') ; diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 0885c0c40b..dbbd59f8c3 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -6,7 +6,6 @@ use Utopia\Storage\Device\Local; use Utopia\Storage\Storage; use Appwrite\ClamAV\Network; use Appwrite\Event\Event; -use RuntimeException; App::get('/v1/health') ->desc('Get HTTP') @@ -268,7 +267,7 @@ App::get('/v1/health/anti-virus') 'status' => (@$antiVirus->ping()) ? 'online' : 'offline', 'version' => @$antiVirus->version(), ]); - } catch( RuntimeException $e) { + } catch( \Exception $e) { $response->json([ 'status' => 'offline', 'version' => '', diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index b3060eaf4b..c4fe8c8494 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -242,6 +242,7 @@ App::get('/v1/storage/files/:fileId/preview') ->param('fileId', '', new UID(), 'File unique ID') ->param('width', 0, new Range(0, 4000), 'Resize preview image width, Pass an integer between 0 to 4000.', true) ->param('height', 0, new Range(0, 4000), 'Resize preview image height, Pass an integer between 0 to 4000.', true) + ->param('gravity', Image::GRAVITY_CENTER, new WhiteList([Image::GRAVITY_CENTER, Image::GRAVITY_NORTH, Image::GRAVITY_NORTHWEST, Image::GRAVITY_NORTHEAST, Image::GRAVITY_WEST, Image::GRAVITY_EAST, Image::GRAVITY_SOUTHWEST, Image::GRAVITY_SOUTH, Image::GRAVITY_SOUTHEAST]), 'Image crop gravity', true) ->param('quality', 100, new Range(0, 100), 'Preview image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->param('borderWidth', 0, new Range(0, 100), 'Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.', true) ->param('borderColor', '', new HexColor(), 'Preview image border color. Use a valid HEX color, no # is needed for prefix.', true) @@ -254,7 +255,7 @@ App::get('/v1/storage/files/:fileId/preview') ->inject('response') ->inject('project') ->inject('projectDB') - ->action(function ($fileId, $width, $height, $quality, $borderWidth, $borderColor, $borderRadius, $opacity, $rotation, $background, $output, $request, $response, $project, $projectDB) { + ->action(function ($fileId, $width, $height, $gravity, $quality, $borderWidth, $borderColor, $borderRadius, $opacity, $rotation, $background, $output, $request, $response, $project, $projectDB) { /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ @@ -342,7 +343,7 @@ App::get('/v1/storage/files/:fileId/preview') $image = new Image($source); - $image->crop((int) $width, (int) $height); + $image->crop((int) $width, (int) $height, $gravity); if (!empty($opacity) || $opacity==0) { $image->setOpacity($opacity); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 598783128e..ed23fb1bb5 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -212,7 +212,8 @@ App::delete('/v1/teams/:teamId') ->inject('response') ->inject('projectDB') ->inject('events') - ->action(function ($teamId, $response, $projectDB, $events) { + ->inject('deletes') + ->action(function ($teamId, $response, $projectDB, $events, $deletes) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $events */ @@ -223,25 +224,15 @@ App::delete('/v1/teams/:teamId') throw new Exception('Team not found', 404); } - $memberships = $projectDB->getCollection([ - 'limit' => 2000, // TODO add members limit - 'offset' => 0, - 'filters' => [ - '$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS, - 'teamId='.$teamId, - ], - ]); - - foreach ($memberships as $member) { - if (!$projectDB->deleteDocument($member->getId())) { - throw new Exception('Failed to remove membership for team from DB', 500); - } - } - if (!$projectDB->deleteDocument($teamId)) { throw new Exception('Failed to remove team from DB', 500); } + $deletes + ->setParam('type', DELETE_TYPE_DOCUMENT) + ->setParam('document', $team) + ; + $events ->setParam('eventData', $response->output($team, Response::MODEL_TEAM)) ; @@ -434,7 +425,7 @@ App::post('/v1/teams/:teamId/memberships') $title = \sprintf($locale->getText('account.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]'])); $body - ->setParam('{{content}}', $content->render()) + ->setParam('{{content}}', $content->render(false)) ->setParam('{{cta}}', $cta->render()) ->setParam('{{title}}', $title) ->setParam('{{direction}}', $locale->getText('settings.direction')) @@ -442,10 +433,9 @@ App::post('/v1/teams/:teamId/memberships') ->setParam('{{team}}', $team->getAttribute('name', '[TEAM-NAME]')) ->setParam('{{owner}}', $user->getAttribute('name', '')) ->setParam('{{redirect}}', $url) - ->setParam('{{bg-body}}', '#f6f6f6') + ->setParam('{{bg-body}}', '#f7f7f7') ->setParam('{{bg-content}}', '#ffffff') - ->setParam('{{bg-cta}}', '#3498db') - ->setParam('{{bg-cta-hover}}', '#34495e') + ->setParam('{{bg-cta}}', '#073b4c') ->setParam('{{text-content}}', '#000000') ->setParam('{{text-cta}}', '#ffffff') ; diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 49e201e1d7..9dd13e34e8 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -8,6 +8,7 @@ use Utopia\Validator\WhiteList; use Appwrite\Network\Validator\Email; use Utopia\Validator\Text; use Utopia\Validator\Range; +use Utopia\Validator\Boolean; use Utopia\Audit\Audit; use Utopia\Audit\Adapters\MySQL as AuditAdapter; use Appwrite\Auth\Auth; @@ -369,6 +370,43 @@ App::patch('/v1/users/:userId/status') $response->dynamic($user, Response::MODEL_USER); }); +App::patch('/v1/users/:userId/verification') + ->desc('Update Email Verification') + ->groups(['api', 'users']) + ->label('event', 'users.update.verification') + ->label('scope', 'users.write') + ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) + ->label('sdk.namespace', 'users') + ->label('sdk.method', 'updateVerification') + ->label('sdk.description', '/docs/references/users/update-user-verification.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_USER) + ->param('userId', '', new UID(), 'User unique ID.') + ->param('emailVerification', false, new Boolean(), 'User Email Verification Status.') + ->inject('response') + ->inject('projectDB') + ->action(function ($userId, $emailVerification, $response, $projectDB) { + /** @var Appwrite\Utopia\Response $response */ + /** @var Appwrite\Database\Database $projectDB */ + + $user = $projectDB->getDocument($userId); + + if (empty($user->getId()) || Database::SYSTEM_COLLECTION_USERS != $user->getCollection()) { + throw new Exception('User not found', 404); + } + + $user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [ + 'emailVerification' => $emailVerification, + ])); + + if (false === $user) { + throw new Exception('Failed saving user to DB', 500); + } + + $response->dynamic($user, Response::MODEL_USER); + }); + App::patch('/v1/users/:userId/prefs') ->desc('Update User Preferences') ->groups(['api', 'users']) diff --git a/app/http.php b/app/http.php index 89ff646d70..2fced63f4d 100644 --- a/app/http.php +++ b/app/http.php @@ -12,16 +12,6 @@ use Swoole\Http\Request as SwooleRequest; use Swoole\Http\Response as SwooleResponse; use Utopia\App; use Utopia\CLI\Console; -use Utopia\Config\Config; -use Utopia\Domains\Domain; - -// xdebug_start_trace('/tmp/trace'); - -ini_set('memory_limit','512M'); -ini_set('display_errors', 1); -ini_set('display_startup_errors', 1); -ini_set('default_socket_timeout', -1); -error_reporting(E_ALL); $http = new Server("0.0.0.0", App::getEnv('PORT', 80)); @@ -68,7 +58,7 @@ Files::load(__DIR__ . '/../public'); include __DIR__ . '/controllers/general.php'; -$http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) { +$http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) use ($register) { $request = new Request($swooleRequest); $response = new Response($swooleResponse); @@ -85,6 +75,17 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo return; } + $db = $register->get('dbPool')->get(); + $redis = $register->get('redisPool')->get(); + + $register->set('db', function () use (&$db) { + return $db; + }); + + $register->set('cache', function () use (&$redis) { + return $redis; + }); + $app = new App('UTC'); try { @@ -104,6 +105,14 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo else { $swooleResponse->end('500: Server Error'); } + } finally { + /** @var PDOPool $dbPool */ + $dbPool = $register->get('dbPool'); + $dbPool->put($db); + + /** @var RedisPool $redisPool */ + $redisPool = $register->get('redisPool'); + $redisPool->put($redis); } }); diff --git a/app/init.php b/app/init.php index e628b56da7..3e83893c7f 100644 --- a/app/init.php +++ b/app/init.php @@ -11,6 +11,12 @@ if (\file_exists(__DIR__.'/../vendor/autoload.php')) { require_once __DIR__.'/../vendor/autoload.php'; } +ini_set('memory_limit','512M'); +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +ini_set('default_socket_timeout', -1); +error_reporting(E_ALL); + use Ahc\Jwt\JWT; use Ahc\Jwt\JWTException; use Appwrite\Auth\Auth; @@ -18,9 +24,10 @@ use Appwrite\Database\Database; use Appwrite\Database\Adapter\MySQL as MySQLAdapter; use Appwrite\Database\Adapter\Redis as RedisAdapter; use Appwrite\Database\Document; +use Appwrite\Database\Pool\PDOPool; +use Appwrite\Database\Pool\RedisPool; use Appwrite\Database\Validator\Authorization; use Appwrite\Event\Event; -use Appwrite\Extend\PDO; use Appwrite\OpenSSL\OpenSSL; use Utopia\App; use Utopia\View; @@ -29,7 +36,6 @@ use Utopia\Locale\Locale; use Utopia\Registry\Registry; use MaxMind\Db\Reader; use PHPMailer\PHPMailer\PHPMailer; -use PDO as PDONative; const APP_NAME = 'Appwrite'; const APP_DOMAIN = 'appwrite.io'; @@ -145,23 +151,32 @@ Database::addFilter('encrypt', /* * Registry */ -$register->set('db', function () { // Register DB connection +$register->set('dbPool', function () { // Register DB connection $dbHost = App::getEnv('_APP_DB_HOST', ''); $dbUser = App::getEnv('_APP_DB_USER', ''); $dbPass = App::getEnv('_APP_DB_PASS', ''); $dbScheme = App::getEnv('_APP_DB_SCHEMA', ''); + $pool = new PDOPool(10, $dbHost, $dbScheme, $dbUser, $dbPass); - $pdo = new PDO("mysql:host={$dbHost};dbname={$dbScheme};charset=utf8mb4", $dbUser, $dbPass, array( - PDONative::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', - PDONative::ATTR_TIMEOUT => 3, // Seconds - PDONative::ATTR_PERSISTENT => true - )); + return $pool; +}); +$register->set('redisPool', function () { + $redisHost = App::getEnv('_APP_REDIS_HOST', ''); + $redisPort = App::getEnv('_APP_REDIS_PORT', ''); + $redisUser = App::getEnv('_APP_REDIS_USER', ''); + $redisPass = App::getEnv('_APP_REDIS_PASS', ''); + $redisAuth = []; - // Connection settings - $pdo->setAttribute(PDONative::ATTR_DEFAULT_FETCH_MODE, PDONative::FETCH_ASSOC); // Return arrays - $pdo->setAttribute(PDONative::ATTR_ERRMODE, PDONative::ERRMODE_EXCEPTION); // Handle all errors with exceptions + if ($redisUser) { + $redisAuth[] = $redisUser; + } + if ($redisPass) { + $redisAuth[] = $redisPass; + } - return $pdo; + $pool = new RedisPool(10, $redisHost, $redisPort, $redisAuth); + + return $pool; }); $register->set('influxdb', function () { // Register DB connection $host = App::getEnv('_APP_INFLUXDB_HOST', ''); @@ -185,25 +200,6 @@ $register->set('statsd', function () { // Register DB connection return $statsd; }); -$register->set('cache', function () { // Register cache connection - $redis = new Redis(); - $redis->pconnect(App::getEnv('_APP_REDIS_HOST', ''), App::getEnv('_APP_REDIS_PORT', '')); - $user = App::getEnv('_APP_REDIS_USER',''); - $pass = App::getEnv('_APP_REDIS_PASS',''); - $auth = []; - if(!empty($user)) { - $auth["user"] = $user; - } - if(!empty($pass)) { - $auth["pass"] = $pass; - } - if(!empty($auth)) { - $redis->auth($auth); - } - $redis->setOption(Redis::OPT_READ_TIMEOUT, -1); - - return $redis; -}); $register->set('smtp', function () { $mail = new PHPMailer(true); @@ -387,7 +383,7 @@ App::setResource('user', function($mode, $project, $console, $request, $response /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $consoleDB */ /** @var Appwrite\Database\Database $projectDB */ - /** @var bool $mode */ + /** @var string $mode */ Authorization::setDefaultStatus(true); diff --git a/app/tasks/sdks.php b/app/tasks/sdks.php index 96d9dbf563..d5f858a7be 100644 --- a/app/tasks/sdks.php +++ b/app/tasks/sdks.php @@ -15,7 +15,7 @@ use Appwrite\SDK\Language\Deno; use Appwrite\SDK\Language\DotNet; use Appwrite\SDK\Language\Flutter; use Appwrite\SDK\Language\Go; -use Appwrite\SDK\Language\Java; +use Appwrite\SDK\Language\Kotlin; use Appwrite\SDK\Language\Swift; $cli @@ -134,9 +134,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND case 'go': $config = new Go(); break; - case 'java': - $config = new Java(); - break; case 'swift': $config = new Swift(); break; @@ -144,6 +141,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND $cover = ''; $config = new DotNet(); break; + case 'android': + $config = new Kotlin(); + break; default: throw new Exception('Language "'.$language['key'].'" not supported'); break; @@ -155,9 +155,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND $sdk ->setName($language['name']) - ->setDescription("Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. - Use the {$language['name']} SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. - For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)") + ->setNamespace('io appwrite') + ->setDescription("Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the {$language['name']} SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)") ->setShortDescription('Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API') ->setLicense($license) ->setLicenseContent($licenseContent) diff --git a/app/views/console/home/index.phtml b/app/views/console/home/index.phtml index db1b9c32fc..021cf89928 100644 --- a/app/views/console/home/index.phtml +++ b/app/views/console/home/index.phtml @@ -240,11 +240,11 @@ $usageStatsEnabled = $this->getParam('usageStatsEnabled',true);
  • -
  • - +
  • +
  • - +
  • @@ -329,6 +329,42 @@ $usageStatsEnabled = $this->getParam('usageStatsEnabled',true); + +