From aeddd0d07056f3898d3de27c9939939dbded1cae Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 14 Jun 2021 16:33:28 +0545 Subject: [PATCH 1/5] buckets collection --- app/config/collections.php | 81 ++++++++++++++++++++++++++++++ src/Appwrite/Database/Database.php | 1 + 2 files changed, 82 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index 6789237c9c..9c4105647b 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1436,6 +1436,87 @@ $collections = [ ], ], ], + Database::SYSTEM_COLLECTION_BUCKETS => [ + '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, + '$id' => Database::SYSTEM_COLLECTION_BUCKETS, + '$permissions' => ['read' => ['*']], + 'name' => 'File', + 'structure' => true, + 'rules' => [ + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Date Created', + 'key' => 'dateCreated', + 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, + 'default' => 0, + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Enabled', + 'key' => 'enabled', + 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, + 'default' => true, + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Name', + 'key' => 'name', + 'type' => Database::SYSTEM_VAR_TYPE_TEXT, + 'default' => '', + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Adapter', + 'key' => 'adapter', + 'type' => Database::SYSTEM_VAR_TYPE_TEXT, + 'default' => '', + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Maximum File Size', + 'key' => 'maximumFileSize', + 'type' => Database::SYSTEM_VAR_TYPE_NUMERIC, + 'default' => 0, + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Allowed File Extensions', + 'key' => 'allowedFileExtensions', + 'type' => Database::SYSTEM_VAR_TYPE_TEXT, + 'default' => '', + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Encryption', + 'key' => 'encrypted', + 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, + 'default' => true, + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Virus Scan', + 'key' => 'antivirus', + 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, + 'default' => true, + 'required' => true, + 'array' => false, + ], + ], + ], Database::SYSTEM_COLLECTION_FUNCTIONS => [ '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, '$id' => Database::SYSTEM_COLLECTION_FUNCTIONS, diff --git a/src/Appwrite/Database/Database.php b/src/Appwrite/Database/Database.php index d0defdec03..685dc82770 100644 --- a/src/Appwrite/Database/Database.php +++ b/src/Appwrite/Database/Database.php @@ -36,6 +36,7 @@ class Database // Storage const SYSTEM_COLLECTION_FILES = 'files'; + const SYSTEM_COLLECTION_BUCKETS = 'buckets'; // Functions const SYSTEM_COLLECTION_FUNCTIONS = 'functions'; From c6d43b06c4985f430ebead728bf0c67733bbe151 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 14 Jun 2021 16:43:18 +0545 Subject: [PATCH 2/5] bucket response model --- src/Appwrite/Utopia/Response.php | 3 +- src/Appwrite/Utopia/Response/Model/Bucket.php | 97 +++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/Appwrite/Utopia/Response/Model/Bucket.php diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index a6ec6891cc..54530b1875 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -78,7 +78,8 @@ class Response extends SwooleResponse // Storage const MODEL_FILE = 'file'; const MODEL_FILE_LIST = 'fileList'; - const MODEL_BUCKET = 'bucket'; // - Missing + const MODEL_BUCKET = 'bucket'; + const MODEL_BUCKET_LIST = 'bucketList'; // Locale const MODEL_LOCALE = 'locale'; diff --git a/src/Appwrite/Utopia/Response/Model/Bucket.php b/src/Appwrite/Utopia/Response/Model/Bucket.php new file mode 100644 index 0000000000..ce22ce90fb --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Bucket.php @@ -0,0 +1,97 @@ +addRule('$id', [ + 'type' => self::TYPE_STRING, + 'description' => 'Bucket ID.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('$permissions', [ + 'type' => Response::MODEL_PERMISSIONS, + 'description' => 'File permissions.', + 'default' => new \stdClass, + 'example' => new \stdClass, + 'array' => false, + ]) + ->addRule('dateCreated', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'File creation date in Unix timestamp.', + 'default' => 0, + 'example' => 1592981250, + ]) + ->addRule('name', [ + 'type' => self::TYPE_STRING, + 'description' => 'Bucket name.', + 'default' => '', + 'example' => 'Documents', + ]) + ->addRule('enabled', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Bucket enabled.', + 'default' => true, + 'example' => false, + ]) + ->addRule('adapter', [ + 'type' => self::TYPE_STRING, + 'description' => 'Storage adapter.', + 'default' => '', + 'example' => 'local', + ]) + ->addRule('maximumFileSize', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Maximum file size supported.', + 'default' => 0, + 'example' => 100, + ]) + ->addRule('allowedFileExtensions', [ + 'type' => self::TYPE_STRING, + 'description' => 'Allowed file extensions.', + 'default' => '', + 'example' => 'jpg,png', + ]) + ->addRule('encrypted', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Bucket is encrypted.', + 'default' => true, + 'example' => false, + ]) + ->addRule('antivirus', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Virus scanning is enabled.', + 'default' => true, + 'example' => false, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'Bucket'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_BUCKET; + } +} From f1dc7887485fb52bd5d9e712c1928b78258d4fb3 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 14 Jun 2021 17:18:49 +0545 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Eldad A. Fux --- app/config/collections.php | 6 +++--- src/Appwrite/Utopia/Response/Model/Bucket.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 9c4105647b..d8268cb35c 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1500,7 +1500,7 @@ $collections = [ [ '$collection' => Database::SYSTEM_COLLECTION_RULES, 'label' => 'Encryption', - 'key' => 'encrypted', + 'key' => 'encryption', 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, 'default' => true, 'required' => true, @@ -1509,7 +1509,7 @@ $collections = [ [ '$collection' => Database::SYSTEM_COLLECTION_RULES, 'label' => 'Virus Scan', - 'key' => 'antivirus', + 'key' => 'antiVirus', 'type' => Database::SYSTEM_VAR_TYPE_BOOLEAN, 'default' => true, 'required' => true, @@ -1829,4 +1829,4 @@ foreach ($auth as $index => $method) { ]; } -return $collections; \ No newline at end of file +return $collections; diff --git a/src/Appwrite/Utopia/Response/Model/Bucket.php b/src/Appwrite/Utopia/Response/Model/Bucket.php index ce22ce90fb..d229a29fcc 100644 --- a/src/Appwrite/Utopia/Response/Model/Bucket.php +++ b/src/Appwrite/Utopia/Response/Model/Bucket.php @@ -60,13 +60,13 @@ class Bucket extends Model 'default' => '', 'example' => 'jpg,png', ]) - ->addRule('encrypted', [ + ->addRule('encryption', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Bucket is encrypted.', 'default' => true, 'example' => false, ]) - ->addRule('antivirus', [ + ->addRule('antiVirus', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Virus scanning is enabled.', 'default' => true, From 81d6c9ea5d281b893000fabfe3f4d8e496842584 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 14 Jun 2021 17:23:56 +0545 Subject: [PATCH 4/5] adapter credentials field --- app/config/collections.php | 10 ++++++++++ src/Appwrite/Utopia/Response/Model/Bucket.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index d8268cb35c..3b28dd368d 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1479,6 +1479,16 @@ $collections = [ 'required' => true, 'array' => false, ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Adapter Crednetials', + 'key' => 'adapterCredentials', + 'type' => Database::SYSTEM_VAR_TYPE_TEXT, + 'default' => '', + 'required' => false, + 'array' => false, + 'filter' => ['json'] + ], [ '$collection' => Database::SYSTEM_COLLECTION_RULES, 'label' => 'Maximum File Size', diff --git a/src/Appwrite/Utopia/Response/Model/Bucket.php b/src/Appwrite/Utopia/Response/Model/Bucket.php index d229a29fcc..e64d4d3b9a 100644 --- a/src/Appwrite/Utopia/Response/Model/Bucket.php +++ b/src/Appwrite/Utopia/Response/Model/Bucket.php @@ -48,6 +48,12 @@ class Bucket extends Model 'default' => '', 'example' => 'local', ]) + ->addRule('adapterCredentials', [ + 'type' => self::TYPE_STRING, + 'description' => 'Storage adapter credentials.', + 'default' => '', + 'example' => ['key' => 'value'], + ]) ->addRule('maximumFileSize', [ 'type' => self::TYPE_INTEGER, 'description' => 'Maximum file size supported.', From 7a3611f6d562f2c8908b6a0146d1492bd82e7b03 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 14 Jun 2021 17:25:06 +0545 Subject: [PATCH 5/5] bucketlist model --- src/Appwrite/Utopia/Response.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 54530b1875..e0b96834e3 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -155,6 +155,7 @@ class Response extends SwooleResponse ->setModel(new BaseList('Sessions List', self::MODEL_SESSION_LIST, 'sessions', self::MODEL_SESSION)) ->setModel(new BaseList('Logs List', self::MODEL_LOG_LIST, 'logs', self::MODEL_LOG, false)) ->setModel(new BaseList('Files List', self::MODEL_FILE_LIST, 'files', self::MODEL_FILE)) + ->setModel(new BaseList('Buckets List', self::MODEL_BUCKET_LIST, 'buckets', self::MODEL_BUCKET)) ->setModel(new BaseList('Teams List', self::MODEL_TEAM_LIST, 'teams', self::MODEL_TEAM)) ->setModel(new BaseList('Memberships List', self::MODEL_MEMBERSHIP_LIST, 'memberships', self::MODEL_MEMBERSHIP)) ->setModel(new BaseList('Functions List', self::MODEL_FUNCTION_LIST, 'functions', self::MODEL_FUNCTION))