- Introduce a comprehensive permission system for subusers, including permission nodes and types with support for vehicles, bookings, orders, subusers, and self-serve modules. - Implement `subusers_user`, `subuser_user_grant`, and `subusers_permission_node` classes for managing subuser permissions and grants. - Extend `subuser_grants_o` with methods to retrieve permissions for subusers linked to customers. - Add traits and enumerations to streamline permission handling across modules. - Update subuser session handling to include token-based subuser lookups.
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace modules\subusers\classes;
|
|
|
|
use Exception;
|
|
use modules\subusers\interfaces\subusers_user_i;
|
|
use modules\subusers\traits\subusers_user_t;
|
|
use objects\subusers_o;
|
|
|
|
class subusers_user implements subusers_user_i
|
|
{
|
|
use subusers_user_t;
|
|
public int $subuserId;
|
|
|
|
/**
|
|
* Get a subuser by their ID.
|
|
* @param int $subuserId
|
|
* @return subusers_user|null
|
|
*/
|
|
public static function bySubuserId(int $subuserId): ?subusers_user
|
|
{
|
|
$subuser = new subusers_user();
|
|
$subuser->subuserId = $subuserId;
|
|
return $subuser;
|
|
}
|
|
|
|
/**
|
|
* Get a subuser by their username.
|
|
* @param string $username
|
|
* @return subusers_user
|
|
* @throws Exception If there was an error getting the subuser by username or if the subuser does not exist
|
|
*/
|
|
public static function byUsername(string $username): subusers_user
|
|
{
|
|
return self::bySubuserId((new subusers_o())->getSubuserByUsername($username)->id);
|
|
}
|
|
|
|
/**
|
|
* Get a subuser by their session token.
|
|
* @param string $token
|
|
* @return subusers_user|null
|
|
* @throws Exception If there was an error getting the subuser by session token
|
|
*/
|
|
public static function bySessionToken(string $token): ?subusers_user
|
|
{
|
|
$subusers_o = new subusers_o();
|
|
$subusers_o->getSubuserBySessionToken($token);
|
|
return self::bySubuserId($subusers_o->id);
|
|
}
|
|
} |