Skip to content

Commit 4146695

Browse files
committed
(fix): add collection read permissions for joins, use enums in e2e tests
1 parent d688701 commit 4146695

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

tests/e2e/Adapter/Scopes/AggregationTests.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private function createProducts(Database $database, string $collection = 'agg_pr
3838
return;
3939
}
4040

41-
$database->createCollection($collection);
41+
$database->createCollection($collection, permissions: [Permission::create(Role::any()), Permission::read(Role::any())]);
4242
$database->createAttribute($collection, new Attribute(key: 'name', type: ColumnType::String, size: 100, required: true));
4343
$database->createAttribute($collection, new Attribute(key: 'category', type: ColumnType::String, size: 50, required: true));
4444
$database->createAttribute($collection, new Attribute(key: 'price', type: ColumnType::Integer, size: 0, required: true));
@@ -74,7 +74,7 @@ private function createOrders(Database $database, string $collection = 'agg_orde
7474
$database->deleteCollection($collection);
7575
}
7676

77-
$database->createCollection($collection);
77+
$database->createCollection($collection, permissions: [Permission::create(Role::any()), Permission::read(Role::any())]);
7878
$database->createAttribute($collection, new Attribute(key: 'product_uid', type: ColumnType::String, size: 255, required: true));
7979
$database->createAttribute($collection, new Attribute(key: 'customer_uid', type: ColumnType::String, size: 255, required: true));
8080
$database->createAttribute($collection, new Attribute(key: 'quantity', type: ColumnType::Integer, size: 0, required: true));
@@ -111,7 +111,7 @@ private function createCustomers(Database $database, string $collection = 'agg_c
111111
$database->deleteCollection($collection);
112112
}
113113

114-
$database->createCollection($collection);
114+
$database->createCollection($collection, permissions: [Permission::create(Role::any()), Permission::read(Role::any())]);
115115
$database->createAttribute($collection, new Attribute(key: 'name', type: ColumnType::String, size: 100, required: true));
116116
$database->createAttribute($collection, new Attribute(key: 'email', type: ColumnType::String, size: 200, required: true));
117117
$database->createAttribute($collection, new Attribute(key: 'country', type: ColumnType::String, size: 50, required: true));
@@ -142,7 +142,7 @@ private function createReviews(Database $database, string $collection = 'agg_rev
142142
$database->deleteCollection($collection);
143143
}
144144

145-
$database->createCollection($collection);
145+
$database->createCollection($collection, permissions: [Permission::create(Role::any()), Permission::read(Role::any())]);
146146
$database->createAttribute($collection, new Attribute(key: 'product_uid', type: ColumnType::String, size: 255, required: true));
147147
$database->createAttribute($collection, new Attribute(key: 'customer_uid', type: ColumnType::String, size: 255, required: true));
148148
$database->createAttribute($collection, new Attribute(key: 'score', type: ColumnType::Integer, size: 0, required: true));
@@ -258,7 +258,7 @@ public function testCountEmptyCollection(): void
258258
if ($database->exists($database->getDatabase(), $col)) {
259259
$database->deleteCollection($col);
260260
}
261-
$database->createCollection($col);
261+
$database->createCollection($col, permissions: [Permission::create(Role::any()), Permission::read(Role::any())]);
262262
$database->createAttribute($col, new Attribute(key: 'value', type: ColumnType::Integer, size: 0, required: true));
263263

264264
$results = $database->find($col, [Query::count('*', 'total')]);
@@ -1106,9 +1106,9 @@ public function testJoinAggregationWithPermissionsGrouped(): void
11061106
$cols = ['jp_apg_o', 'jp_apg_c'];
11071107
$this->cleanupAggCollections($database, $cols);
11081108

1109-
$database->createCollection('jp_apg_c');
1109+
$database->createCollection('jp_apg_c', permissions: [Permission::create(Role::any()), Permission::read(Role::any())]);
11101110
$database->createAttribute('jp_apg_c', new Attribute(key: 'name', type: ColumnType::String, size: 100, required: true));
1111-
$database->createCollection('jp_apg_o', documentSecurity: true);
1111+
$database->createCollection('jp_apg_o', permissions: [Permission::create(Role::any()), Permission::read(Role::any())], documentSecurity: true);
11121112
$database->createAttribute('jp_apg_o', new Attribute(key: 'customer_uid', type: ColumnType::String, size: 255, required: true));
11131113
$database->createAttribute('jp_apg_o', new Attribute(key: 'amount', type: ColumnType::Integer, size: 0, required: true));
11141114

@@ -1173,9 +1173,9 @@ public function testLeftJoinPermissionFiltered(): void
11731173
$cols = ['jp_ljpf_p', 'jp_ljpf_r'];
11741174
$this->cleanupAggCollections($database, $cols);
11751175

1176-
$database->createCollection('jp_ljpf_p', documentSecurity: true);
1176+
$database->createCollection('jp_ljpf_p', permissions: [Permission::create(Role::any()), Permission::read(Role::any())], documentSecurity: true);
11771177
$database->createAttribute('jp_ljpf_p', new Attribute(key: 'name', type: ColumnType::String, size: 100, required: true));
1178-
$database->createCollection('jp_ljpf_r');
1178+
$database->createCollection('jp_ljpf_r', permissions: [Permission::create(Role::any()), Permission::read(Role::any())]);
11791179
$database->createAttribute('jp_ljpf_r', new Attribute(key: 'product_uid', type: ColumnType::String, size: 255, required: true));
11801180
$database->createAttribute('jp_ljpf_r', new Attribute(key: 'score', type: ColumnType::Integer, size: 0, required: true));
11811181

tests/e2e/Adapter/Scopes/AttributeTests.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public function testUpdateAttributeFormat(): void
599599
$max = $attribute['formatOptions']['max'];
600600

601601
return new Range($min, $max);
602-
}, ColumnType::Integer->value);
602+
}, ColumnType::Integer);
603603

604604
$database->updateAttributeFormat($this->getFlowersCollection(), 'price', 'priceRange');
605605
$database->updateAttributeFormatOptions($this->getFlowersCollection(), 'price', ['min' => 1, 'max' => 10000]);
@@ -674,7 +674,7 @@ protected function initFlowersWithPriceFixture(): void
674674
$max = $attribute['formatOptions']['max'];
675675

676676
return new Range($min, $max);
677-
}, ColumnType::Integer->value);
677+
}, ColumnType::Integer);
678678

679679
$database->updateAttributeFormat($this->getFlowersCollection(), 'price', 'priceRange');
680680
$database->updateAttributeFormatOptions($this->getFlowersCollection(), 'price', ['min' => 1, 'max' => 10000]);
@@ -693,7 +693,7 @@ public function testUpdateAttributeStructure(): void
693693
$max = $attribute['formatOptions']['max'];
694694

695695
return new Range($min, $max);
696-
}, ColumnType::Integer->value);
696+
}, ColumnType::Integer);
697697

698698
/** @var Database $database */
699699
$database = $this->getDatabase();

tests/e2e/Adapter/Scopes/CollectionTests.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Utopia\Database\Helpers\Permission;
2020
use Utopia\Database\Helpers\Role;
2121
use Utopia\Database\Hook\Lifecycle;
22-
use Utopia\Database\Hook\QueryTransform;
22+
use Utopia\Database\Hook\Transform;
2323
use Utopia\Database\Index;
2424
use Utopia\Database\Query;
2525
use Utopia\Database\Relationship;
@@ -1081,7 +1081,7 @@ public function testEvents(): void
10811081
];
10821082

10831083
$test = $this;
1084-
$database->addLifecycleHook(new class ($events, $test) implements Lifecycle {
1084+
$database->addHook(new class ($events, $test) implements Lifecycle {
10851085
/** @param array<Event> $events */
10861086
public function __construct(private array &$events, private $test)
10871087
{
@@ -1222,7 +1222,7 @@ public function testTransformations(): void
12221222
'name' => 'value1',
12231223
]));
12241224

1225-
$database->addQueryTransform('test', new class () implements QueryTransform {
1225+
$database->addHook(new class () implements Transform {
12261226
public function transform(Event $event, string $query): string
12271227
{
12281228
return 'SELECT 1';

0 commit comments

Comments
 (0)