mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge remote-tracking branch 'origin/0.16.x' into datetime-attributes-merge
# Conflicts: # app/controllers/api/account.php # app/controllers/api/databases.php # app/controllers/api/functions.php # app/controllers/api/projects.php # app/controllers/api/storage.php # app/controllers/api/teams.php # app/controllers/api/users.php # app/controllers/general.php # app/controllers/shared/api.php
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Appwrite\Extend;
|
||||
|
||||
use Utopia\Config\Config;
|
||||
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
@@ -47,7 +49,7 @@ class Exception extends \Exception
|
||||
public const GENERAL_ROUTE_NOT_FOUND = 'general_route_not_found';
|
||||
public const GENERAL_CURSOR_NOT_FOUND = 'general_cursor_not_found';
|
||||
public const GENERAL_SERVER_ERROR = 'general_server_error';
|
||||
public const GENERAL_PROTOCOL_UNSUPPORTED = 'general_protocol_unsupported';
|
||||
public const GENERAL_PROTOCOL_UNSUPPORTED = 'general_protocol_unsupported';
|
||||
|
||||
/** Users */
|
||||
public const USER_COUNT_EXCEEDED = 'user_count_exceeded';
|
||||
@@ -69,6 +71,7 @@ class Exception extends \Exception
|
||||
public const USER_AUTH_METHOD_UNSUPPORTED = 'user_auth_method_unsupported';
|
||||
public const USER_PHONE_ALREADY_EXISTS = 'user_phone_already_exists';
|
||||
public const USER_PHONE_NOT_FOUND = 'user_phone_not_found';
|
||||
public const USER_MISSING_ID = 'user_missing_id';
|
||||
|
||||
/** Teams */
|
||||
public const TEAM_NOT_FOUND = 'team_not_found';
|
||||
@@ -80,6 +83,7 @@ class Exception extends \Exception
|
||||
|
||||
/** Membership */
|
||||
public const MEMBERSHIP_NOT_FOUND = 'membership_not_found';
|
||||
public const MEMBERSHIP_ALREADY_CONFIRMED = 'membership_already_confirmed';
|
||||
|
||||
/** Avatars */
|
||||
public const AVATAR_SET_NOT_FOUND = 'avatar_set_not_found';
|
||||
@@ -116,8 +120,8 @@ class Exception extends \Exception
|
||||
public const EXECUTION_NOT_FOUND = 'execution_not_found';
|
||||
|
||||
/** Databases */
|
||||
public const DATABASE_NOT_FOUND = 'database_not_found';
|
||||
public const DATABASE_ALREADY_EXISTS = 'database_already_exists';
|
||||
public const DATABASE_NOT_FOUND = 'database_not_found';
|
||||
public const DATABASE_ALREADY_EXISTS = 'database_already_exists';
|
||||
|
||||
/** Collections */
|
||||
public const COLLECTION_NOT_FOUND = 'collection_not_found';
|
||||
@@ -152,7 +156,6 @@ class Exception extends \Exception
|
||||
public const PROJECT_PROVIDER_UNSUPPORTED = 'project_provider_unsupported';
|
||||
public const PROJECT_INVALID_SUCCESS_URL = 'project_invalid_success_url';
|
||||
public const PROJECT_INVALID_FAILURE_URL = 'project_invalid_failure_url';
|
||||
public const PROJECT_MISSING_USER_ID = 'project_missing_user_id';
|
||||
public const PROJECT_RESERVED_PROJECT = 'project_reserved_project';
|
||||
public const PROJECT_KEY_EXPIRED = 'project_key_expired';
|
||||
|
||||
@@ -170,14 +173,22 @@ class Exception extends \Exception
|
||||
public const DOMAIN_ALREADY_EXISTS = 'domain_already_exists';
|
||||
public const DOMAIN_VERIFICATION_FAILED = 'domain_verification_failed';
|
||||
|
||||
protected $type = '';
|
||||
|
||||
private $type = '';
|
||||
|
||||
public function __construct(string $message, int $code = 0, string $type = Exception::GENERAL_UNKNOWN, \Throwable $previous = null)
|
||||
public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int $code = null, \Throwable $previous = null)
|
||||
{
|
||||
$this->errors = Config::getParam('errors');
|
||||
$this->type = $type;
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
if (isset($this->errors[$type])) {
|
||||
$this->code = $this->errors[$type]['code'];
|
||||
$this->message = $this->errors[$type]['description'];
|
||||
}
|
||||
|
||||
$this->message = $message ?? $this->message;
|
||||
$this->code = $code ?? $this->code;
|
||||
|
||||
parent::__construct($this->message, $this->code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -201,7 +201,7 @@ class Response extends SwooleResponse
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $payload = [];
|
||||
protected array $payload = [];
|
||||
|
||||
/**
|
||||
* Response constructor.
|
||||
@@ -303,8 +303,7 @@ class Response extends SwooleResponse
|
||||
// Verification
|
||||
// Recovery
|
||||
// Tests (keep last)
|
||||
->setModel(new Mock())
|
||||
;
|
||||
->setModel(new Mock());
|
||||
|
||||
parent::__construct($response);
|
||||
}
|
||||
@@ -394,12 +393,13 @@ class Response extends SwooleResponse
|
||||
|
||||
if ($model->isAny()) {
|
||||
$this->payload = $document->getArrayCopy();
|
||||
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
foreach ($model->getRules() as $key => $rule) {
|
||||
if (!$document->isSet($key) && $rule['require']) { // do not set attribute in response if not required
|
||||
if (!is_null($rule['default'])) {
|
||||
if (!$document->isSet($key) && $rule['required']) { // do not set attribute in response if not required
|
||||
if (\array_key_exists('default', $rule)) {
|
||||
$document->setAttribute($key, $rule['default']);
|
||||
} else {
|
||||
throw new Exception('Model ' . $model->getName() . ' is missing response key: ' . $key);
|
||||
@@ -411,7 +411,7 @@ class Response extends SwooleResponse
|
||||
throw new Exception($key . ' must be an array of type ' . $rule['type']);
|
||||
}
|
||||
|
||||
foreach ($data[$key] as &$item) {
|
||||
foreach ($data[$key] as $index => $item) {
|
||||
if ($item instanceof Document) {
|
||||
if (\is_array($rule['type'])) {
|
||||
foreach ($rule['type'] as $type) {
|
||||
@@ -435,9 +435,13 @@ class Response extends SwooleResponse
|
||||
throw new Exception('Missing model for rule: ' . $ruleType);
|
||||
}
|
||||
|
||||
$item = $this->output($item, $ruleType);
|
||||
$data[$key][$index] = $this->output($item, $ruleType);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($data[$key] instanceof Document) {
|
||||
$data[$key] = $this->output($data[$key], $rule['type']);
|
||||
}
|
||||
}
|
||||
|
||||
$output[$key] = $data[$key];
|
||||
@@ -468,8 +472,7 @@ class Response extends SwooleResponse
|
||||
|
||||
$this
|
||||
->setContentType(Response::CONTENT_TYPE_YAML)
|
||||
->send(yaml_emit($data, YAML_UTF8_ENCODING))
|
||||
;
|
||||
->send(yaml_emit($data, YAML_UTF8_ENCODING));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,22 +17,28 @@ abstract class Model
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $none = false;
|
||||
protected bool $none = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $any = false;
|
||||
protected bool $any = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $public = true;
|
||||
protected bool $public = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $rules = [];
|
||||
protected array $rules = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $conditions = [];
|
||||
|
||||
|
||||
/**
|
||||
* Filter Document Structure
|
||||
@@ -78,12 +84,10 @@ abstract class Model
|
||||
protected function addRule(string $key, array $options): self
|
||||
{
|
||||
$this->rules[$key] = array_merge([
|
||||
'require' => true,
|
||||
'type' => '',
|
||||
'required' => true,
|
||||
'array' => false,
|
||||
'description' => '',
|
||||
'default' => null,
|
||||
'example' => '',
|
||||
'array' => false
|
||||
'example' => ''
|
||||
], $options);
|
||||
|
||||
return $this;
|
||||
@@ -94,7 +98,7 @@ abstract class Model
|
||||
$list = [];
|
||||
|
||||
foreach ($this->rules as $key => $rule) {
|
||||
if ($rule['require'] ?? false) {
|
||||
if ($rule['required'] ?? false) {
|
||||
$list[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class Any extends Model
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $any = true;
|
||||
protected bool $any = true;
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
|
||||
@@ -39,7 +39,6 @@ class Attribute extends Model
|
||||
'description' => 'Is attribute an array?',
|
||||
'default' => false,
|
||||
'example' => false,
|
||||
'require' => false
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@ class AttributeBoolean extends Attribute
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
|
||||
'default' => null,
|
||||
'example' => false,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
'example' => false
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ class AttributeEmail extends Attribute
|
||||
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
|
||||
'default' => null,
|
||||
'example' => 'default@example.com',
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ class AttributeEnum extends Attribute
|
||||
'default' => null,
|
||||
'example' => 'element',
|
||||
'array' => true,
|
||||
'require' => true,
|
||||
])
|
||||
->addRule('format', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -45,8 +44,6 @@ class AttributeEnum extends Attribute
|
||||
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
|
||||
'default' => null,
|
||||
'example' => 'element',
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -29,24 +29,18 @@ class AttributeFloat extends Attribute
|
||||
'description' => 'Minimum value to enforce for new documents.',
|
||||
'default' => null,
|
||||
'example' => 1.5,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
->addRule('max', [
|
||||
'type' => self::TYPE_FLOAT,
|
||||
'description' => 'Maximum value to enforce for new documents.',
|
||||
'default' => null,
|
||||
'example' => 10.5,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
->addRule('default', [
|
||||
'type' => self::TYPE_FLOAT,
|
||||
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
|
||||
'default' => null,
|
||||
'example' => 2.5,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ class AttributeIP extends Attribute
|
||||
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
|
||||
'default' => null,
|
||||
'example' => '192.0.2.0',
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -29,24 +29,18 @@ class AttributeInteger extends Attribute
|
||||
'description' => 'Minimum value to enforce for new documents.',
|
||||
'default' => null,
|
||||
'example' => 1,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
->addRule('max', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Maximum value to enforce for new documents.',
|
||||
'default' => null,
|
||||
'example' => 10,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
->addRule('default', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
|
||||
'default' => null,
|
||||
'example' => 10,
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ class AttributeString extends Attribute
|
||||
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
|
||||
'default' => null,
|
||||
'example' => 'default',
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ class AttributeURL extends Attribute
|
||||
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
|
||||
'default' => null,
|
||||
'example' => 'http://example.com',
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class BaseList extends Model
|
||||
@@ -10,12 +9,12 @@ class BaseList extends Model
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '';
|
||||
protected string $name = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = '';
|
||||
protected string $type = '';
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
|
||||
@@ -10,7 +10,7 @@ class Domain extends Model
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $public = false;
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ class ErrorDev extends Error
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $public = false;
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -41,7 +41,6 @@ class Index extends Model
|
||||
'default' => [],
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class Key extends Model
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $public = false;
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ class Metric extends Model
|
||||
'default' => -1,
|
||||
'example' => 1,
|
||||
])
|
||||
->addRule('timestamp', [
|
||||
->addRule('date', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'The UNIX timestamp at which this metric was aggregated.',
|
||||
'default' => 0,
|
||||
|
||||
@@ -10,7 +10,7 @@ class None extends Model
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $none = true;
|
||||
protected bool $none = true;
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
|
||||
@@ -10,7 +10,7 @@ class Platform extends Model
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $public = false;
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -6,11 +6,6 @@ use Appwrite\Utopia\Response;
|
||||
|
||||
class Preferences extends Any
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $any = true;
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
|
||||
@@ -12,7 +12,7 @@ class Project extends Model
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $public = false;
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ class Webhook extends Model
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $public = false;
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user