fix routing with permissions

This commit is contained in:
Dennis Eichhorn 2022-11-20 13:50:53 +01:00
parent 866b5416a4
commit 2e442acc3d
3 changed files with 12 additions and 24 deletions

View File

@ -32,14 +32,6 @@ trait PermissionHandlingTrait
*/
protected array $permissions = [];
/**
* Amount of permissions.
*
* @var int
* @since 1.0.0
*/
private int $pLength = 0;
/**
* Set permissions.
*
@ -54,7 +46,6 @@ trait PermissionHandlingTrait
public function setPermissions(array $permissions) : void
{
$this->permissions = $permissions;
$this->pLength = \count($this->permissions);
}
/**
@ -77,8 +68,6 @@ trait PermissionHandlingTrait
$this->permissions[] = $permission;
}
}
$this->pLength = \count($this->permissions);
}
/**
@ -95,7 +84,6 @@ trait PermissionHandlingTrait
public function addPermission(PermissionAbstract $permission) : void
{
$this->permissions[] = $permission;
++$this->pLength;
}
/**
@ -137,7 +125,7 @@ trait PermissionHandlingTrait
* @param null|int $unit Unit Unit to check (null if all are acceptable)
* @param null|string $app App App to check (null if all are acceptable)
* @param null|string $module Module Module to check (null if all are acceptable)
* @param null|int $type Type (e.g. customer) (null if all are acceptable)
* @param null|int $category Type (e.g. customer) (null if all are acceptable)
* @param null|int $element (e.g. customer id) (null if all are acceptable)
* @param null|int $component (e.g. address) (null if all are acceptable)
*
@ -150,7 +138,7 @@ trait PermissionHandlingTrait
int $unit = null,
string $app = null,
string $module = null,
int $type = null,
int $category = null,
int $element = null,
int $component = null
) : bool
@ -158,7 +146,7 @@ trait PermissionHandlingTrait
$app = $app !== null ? \strtolower($app) : $app;
foreach ($this->permissions as $p) {
if ($p->hasPermission($permission, $unit, $app, $module, $type, $element, $component)) {
if ($p->hasPermission($permission, $unit, $app, $module, $category, $element, $component)) {
return true;
}
}

View File

@ -38,14 +38,14 @@ final class SocketRouter implements RouterInterface
/**
* Add routes from file.
*
* Files need to return a php array of the following structure:
* Files need to return a php array of the following structure (see PermissionHandlingTrait):
* return [
* '{REGEX_PATH}' => [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // can also be static by using :: between namespace and function name
* 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions
* 'permission' => [ // optional
* 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE},
* 'state' => PermissionCategory::{STATE},
* 'category' => PermissionCategory::{STATE},
* ],
* // define different destination for different verb
* ],
@ -159,7 +159,7 @@ final class SocketRouter implements RouterInterface
$d['permission']['unit'] ?? $orgId,
$app,
$d['permission']['module'] ?? null,
$d['permission']['state'] ?? null
$d['permission']['category'] ?? null
)
)
) {

View File

@ -38,16 +38,16 @@ final class WebRouter implements RouterInterface
/**
* Add routes from file.
*
* Files need to return a php array of the following structure:
* Files need to return a php array of the following structure (see PermissionHandlingTrait):
* return [
* '{REGEX_PATH}' => [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // can also be static by using :: between namespace and function name
* 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions
* 'verb' => RouteVerb::{VERB},
* 'csrf' => true,
* 'permission' => [ // optional
* 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE},
* 'state' => PermissionCategory::{STATE},
* 'category' => PermissionCategory::{STATE},
* ],
* // define different destination for different verb
* ],
@ -160,7 +160,7 @@ final class WebRouter implements RouterInterface
}
// if permission check is invalid
if (isset($d['permission']) && !empty($d['permission'])
if (isset($d['permission']) && !empty($d['permission'])
&& ($account === null || $account instanceof NullAccount)
) {
return ['dest' => RouteStatus::NOT_LOGGED_IN];
@ -170,7 +170,7 @@ final class WebRouter implements RouterInterface
$d['permission']['unit'] ?? $orgId,
$app,
$d['permission']['module'] ?? null,
$d['permission']['state'] ?? null
$d['permission']['category'] ?? null
)
)
) {