Merge branch '0.7.x' of github.com:appwrite/appwrite into feat-730-new-webhook-events

This commit is contained in:
Eldad Fux
2020-11-21 01:32:57 +02:00
4 changed files with 62 additions and 24 deletions
+8
View File
@@ -172,6 +172,14 @@ $collections = [
'required' => false,
'array' => true,
],
[
'$collection' => Database::SYSTEM_COLLECTION_RULES,
'label' => 'Filter',
'key' => 'filter',
'type' => Database::SYSTEM_VAR_TYPE_TEXT,
'required' => false,
'array' => true,
],
],
],
Database::SYSTEM_COLLECTION_USERS => [
+2 -4
View File
@@ -49,12 +49,10 @@ App::post('/v1/storage/files')
/** @var Appwrite\Event\Event $usage */
$file = $request->getFiles('file');
$read = (empty($read)) ? ['user:'.$user->getId()] : $read;
$write = (empty($write)) ? ['user:'.$user->getId()] : $write;
/*
* Validators
*/
* Validators
*/
//$fileType = new FileType(array(FileType::FILE_TYPE_PNG, FileType::FILE_TYPE_GIF, FileType::FILE_TYPE_JPEG));
$fileSize = new FileSize(App::getEnv('_APP_STORAGE_LIMIT', 0));
$upload = new Upload();
+42 -10
View File
@@ -455,13 +455,28 @@ class Database
foreach ($rules as $key => $rule) {
$key = $rule->getAttribute('key', null);
$filters = $rule->getAttribute('filter', null);
$type = $rule->getAttribute('type', null);
$array = $rule->getAttribute('array', false);
$filters = $rule->getAttribute('filter', []);
$value = $document->getAttribute($key, null);
if (($value !== null) && is_array($filters)) {
foreach ($filters as $filter) {
$value = $this->encodeAttribute($filter, $value);
$document->setAttribute($key, $value);
if (($value !== null)) {
if ($type === self::SYSTEM_VAR_TYPE_DOCUMENT) {
if($array) {
$list = [];
foreach ($value as $child) {
$list[] = $this->encode($child);
}
$document->setAttribute($key, $list);
} else {
$document->setAttribute($key, $this->encode($value));
}
} else {
foreach ($filters as $filter) {
$value = $this->encodeAttribute($filter, $value);
$document->setAttribute($key, $value);
}
}
}
}
@@ -476,13 +491,28 @@ class Database
foreach ($rules as $key => $rule) {
$key = $rule->getAttribute('key', null);
$filters = $rule->getAttribute('filter', null);
$type = $rule->getAttribute('type', null);
$array = $rule->getAttribute('array', false);
$filters = $rule->getAttribute('filter', []);
$value = $document->getAttribute($key, null);
if (($value !== null) && is_array($filters)) {
foreach (array_reverse($filters) as $filter) {
$value = $this->decodeAttribute($filter, $value);
$document->setAttribute($key, $value);
if (($value !== null)) {
if ($type === self::SYSTEM_VAR_TYPE_DOCUMENT) {
if($array) {
$list = [];
foreach ($value as $child) {
$list[] = $this->decode($child);
}
$document->setAttribute($key, $list);
} else {
$document->setAttribute($key, $this->decode($value));
}
} else {
foreach (array_reverse($filters) as $filter) {
$value = $this->decodeAttribute($filter, $value);
$document->setAttribute($key, $value);
}
}
}
}
@@ -499,6 +529,7 @@ class Database
static protected function encodeAttribute(string $name, $value)
{
if (!isset(self::$filters[$name])) {
return $value;
throw new Exception('Filter not found');
}
@@ -520,6 +551,7 @@ class Database
static protected function decodeAttribute(string $name, $value)
{
if (!isset(self::$filters[$name])) {
return $value;
throw new Exception('Filter not found');
}
@@ -221,10 +221,10 @@ class ProjectsConsoleClientTest extends Scope
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('Project Test 2', $response['body']['name']);
// $this->assertArrayHasKey('platforms', $response['body']); // TODO enable when response model is enabled
// $this->assertArrayHasKey('webhooks', $response['body']); // TODO enable when response model is enabled
// $this->assertArrayHasKey('keys', $response['body']); // TODO enable when response model is enabled
// $this->assertArrayHasKey('tasks', $response['body']); // TODO enable when response model is enabled
$this->assertArrayHasKey('platforms', $response['body']);
$this->assertArrayHasKey('webhooks', $response['body']);
$this->assertArrayHasKey('keys', $response['body']);
$this->assertArrayHasKey('tasks', $response['body']);
$projectId = $response['body']['$id'];
@@ -443,7 +443,7 @@ class ProjectsConsoleClientTest extends Scope
$this->assertIsBool($response['body']['security']);
$this->assertEquals(false, $response['body']['security']);
$this->assertEquals('', $response['body']['httpUser']);
// $this->assertEquals('', $response['body']['httpPass']); // TODO add after encrypt refactor
$this->assertEquals('', $response['body']['httpPass']);
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([
'content-type' => 'application/json',
@@ -462,7 +462,7 @@ class ProjectsConsoleClientTest extends Scope
$this->assertIsBool($response['body']['security']);
$this->assertEquals(false, $response['body']['security']);
$this->assertEquals('', $response['body']['httpUser']);
// $this->assertEquals('', $response['body']['httpPass']); // TODO add after encrypt refactor
$this->assertEquals('', $response['body']['httpPass']);
/**
* Test for FAILURE
@@ -759,7 +759,7 @@ class ProjectsConsoleClientTest extends Scope
$this->assertContains('demo:value', $response['body']['httpHeaders']);
$this->assertCount(1, $response['body']['httpHeaders']);
$this->assertEquals('username', $response['body']['httpUser']);
// $this->assertEquals('password', $response['body']['httpPass']); // TODO add after encrypt refactor
$this->assertEquals('password', $response['body']['httpPass']);
$data = array_merge($data, ['taskId' => $response['body']['$id']]);
@@ -901,7 +901,7 @@ class ProjectsConsoleClientTest extends Scope
$this->assertContains('demo:value', $response['body']['httpHeaders']);
$this->assertCount(1, $response['body']['httpHeaders']);
$this->assertEquals('username', $response['body']['httpUser']);
// $this->assertEquals('password', $response['body']['httpPass']); // TODO add after encrypt refactor
$this->assertEquals('password', $response['body']['httpPass']);
/**
* Test for FAILURE
@@ -952,7 +952,7 @@ class ProjectsConsoleClientTest extends Scope
$this->assertContains('demo2:value2', $response['body']['httpHeaders']);
$this->assertCount(2, $response['body']['httpHeaders']);
$this->assertEquals('username1', $response['body']['httpUser']);
// $this->assertEquals('password1', $response['body']['httpPass']); // TODO add after encrypt refactor
$this->assertEquals('password1', $response['body']['httpPass']);
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
'content-type' => 'application/json',
@@ -972,7 +972,7 @@ class ProjectsConsoleClientTest extends Scope
$this->assertContains('demo2:value2', $response['body']['httpHeaders']);
$this->assertCount(2, $response['body']['httpHeaders']);
$this->assertEquals('username1', $response['body']['httpUser']);
// $this->assertEquals('password1', $response['body']['httpPass']); // TODO add after encrypt refactor
$this->assertEquals('password1', $response['body']['httpPass']);
/**
* Test for FAILURE