Skip to content

Commit d05e43f

Browse files
committed
Remove deprecated permission type
1 parent cd55117 commit d05e43f

5 files changed

Lines changed: 2 additions & 63 deletions

File tree

src/Database/Database.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ class Database
8080
public const PERMISSION_UPDATE = 'update';
8181
public const PERMISSION_DELETE = 'delete';
8282

83-
// Aggregate permissions
84-
public const PERMISSION_WRITE = 'write';
85-
8683
public const PERMISSIONS = [
8784
self::PERMISSION_CREATE,
8885
self::PERMISSION_READ,

src/Database/Helpers/Permission.php

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static function parse(string $permission): self
9090

9191
$permission = $permissionParts[0];
9292

93-
if (!\in_array($permission, array_merge(Database::PERMISSIONS, [Database::PERMISSION_WRITE]))) {
93+
if (!\in_array($permission, Database::PERMISSIONS)) {
9494
throw new DatabaseException('Invalid permission type: "' . $permission . '".');
9595
}
9696
$fullRole = \str_replace('")', '', $permissionParts[1]);
@@ -140,43 +140,6 @@ public static function parse(string $permission): self
140140
return new self($permission, $role, $identifier, $dimension);
141141
}
142142

143-
/**
144-
* Map aggregate permissions into the set of individual permissions they represent.
145-
*
146-
* @param array<string>|null $permissions
147-
* @param array<string> $allowed
148-
* @return array<string>|null
149-
* @throws Exception
150-
*/
151-
public static function aggregate(?array $permissions, array $allowed = Database::PERMISSIONS): ?array
152-
{
153-
if (\is_null($permissions)) {
154-
return null;
155-
}
156-
$mutated = [];
157-
foreach ($permissions as $i => $permission) {
158-
$permission = self::parse($permission);
159-
foreach (self::$aggregates as $type => $subTypes) {
160-
if ($permission->getPermission() != $type) {
161-
$mutated[] = $permission->toString();
162-
continue;
163-
}
164-
foreach ($subTypes as $subType) {
165-
if (!\in_array($subType, $allowed)) {
166-
continue;
167-
}
168-
$mutated[] = (new self(
169-
$subType,
170-
$permission->getRole(),
171-
$permission->getIdentifier(),
172-
$permission->getDimension()
173-
))->toString();
174-
}
175-
}
176-
}
177-
return \array_values(\array_unique($mutated));
178-
}
179-
180143
/**
181144
* Create a read permission string from the given Role
182145
*
@@ -244,21 +207,4 @@ public static function delete(Role $role): string
244207
);
245208
return $permission->toString();
246209
}
247-
248-
/**
249-
* Create a write permission string from the given Role
250-
*
251-
* @param Role $role
252-
* @return string
253-
*/
254-
public static function write(Role $role): string
255-
{
256-
$permission = new self(
257-
'write',
258-
$role->getRole(),
259-
$role->getIdentifier(),
260-
$role->getDimension()
261-
);
262-
return $permission->toString();
263-
}
264210
}

src/Database/Validator/Permissions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Permissions extends Roles
2222
* @param int $length maximum amount of permissions. 0 means unlimited.
2323
* @param array<string> $allowed allowed permissions. Defaults to all available.
2424
*/
25-
public function __construct(int $length = 0, array $allowed = [...Database::PERMISSIONS, Database::PERMISSION_WRITE])
25+
public function __construct(int $length = 0, array $allowed = Database::PERMISSIONS)
2626
{
2727
$this->length = $length;
2828
$this->allowed = $allowed;

tests/unit/PermissionTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ public function testInputFromRoles(): void
253253

254254
$permission = Permission::delete(Role::guests());
255255
$this->assertEquals('delete("guests")', $permission);
256-
257-
$permission = Permission::write(Role::any());
258-
$this->assertEquals('write("any")', $permission);
259256
}
260257

261258
public function testInvalidFormats(): void

tests/unit/Validator/PermissionsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ public function testDuplicateMethods(): void
316316
Permission::read(Role::any()),
317317
Permission::read(Role::user($user)),
318318
Permission::read(Role::user($user)),
319-
Permission::write(Role::user($user)),
320319
Permission::update(Role::user($user)),
321320
Permission::delete(Role::user($user)),
322321
],

0 commit comments

Comments
 (0)