mirror of
https://github.com/Karaka-Management/oms-Admin.git
synced 2026-01-27 12:38:39 +00:00
Move permission to framework
This commit is contained in:
parent
8b398f908e
commit
efabb8ef7b
|
|
@ -14,6 +14,8 @@
|
|||
declare(strict_types=1);
|
||||
namespace Modules\Admin\Models;
|
||||
|
||||
use phpOMS\Account\PermissionAbstract;
|
||||
|
||||
/**
|
||||
* InfoManager class.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
declare(strict_types=1);
|
||||
namespace Modules\Admin\Models;
|
||||
|
||||
use phpOMS\Account\PermissionAbstract;
|
||||
|
||||
/**
|
||||
* InfoManager class.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class GroupPermissionMapper extends DataMapperAbstract
|
|||
'group_permission_id' => ['name' => 'group_permission_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'group_permission_group' => ['name' => 'group_permission_group', 'type' => 'int', 'internal' => 'group'],
|
||||
'group_permission_unit' => ['name' => 'group_permission_unit', 'type' => 'int', 'internal' => 'unit'],
|
||||
'group_permission_app' => ['name' => 'group_permission_app', 'type' => 'int', 'internal' => 'app'],
|
||||
'group_permission_app' => ['name' => 'group_permission_app', 'type' => 'string', 'internal' => 'app'],
|
||||
'group_permission_module' => ['name' => 'group_permission_module', 'type' => 'int', 'internal' => 'module'],
|
||||
'group_permission_from' => ['name' => 'group_permission_from', 'type' => 'int', 'internal' => 'from'],
|
||||
'group_permission_type' => ['name' => 'group_permission_type', 'type' => 'int', 'internal' => 'type'],
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
namespace Modules\Admin\Models;
|
||||
|
||||
/**
|
||||
* InfoManager class.
|
||||
*
|
||||
* Handling the info files for modules
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Module
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class PermissionAbstract
|
||||
{
|
||||
protected $id = 0;
|
||||
|
||||
protected $unit = null;
|
||||
|
||||
protected $app = null;
|
||||
|
||||
protected $module = null;
|
||||
|
||||
protected $from = 0;
|
||||
|
||||
protected $type = null;
|
||||
|
||||
protected $element = null;
|
||||
|
||||
protected $component = null;
|
||||
|
||||
protected $permission = 0;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function getUnit()
|
||||
{
|
||||
return $this->unit;
|
||||
}
|
||||
|
||||
public function getApp()
|
||||
{
|
||||
return $this->app;
|
||||
}
|
||||
|
||||
public function getModule()
|
||||
{
|
||||
return $this->module;
|
||||
}
|
||||
|
||||
public function getFrom()
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getElement()
|
||||
{
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
public function getComponent()
|
||||
{
|
||||
return $this->component;
|
||||
}
|
||||
|
||||
public function getPermission() : int
|
||||
{
|
||||
return $this->permission;
|
||||
}
|
||||
|
||||
public function setUnit(int $unit = null) /* : void */
|
||||
{
|
||||
$this->unit = $unit;
|
||||
}
|
||||
|
||||
public function setApp(int $app = null) /* : void */
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public function setModule(int $module = null) /* : void */
|
||||
{
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
public function setFrom(int $from = null) /* : void */
|
||||
{
|
||||
$this->from = $from;
|
||||
}
|
||||
|
||||
public function setType(int $type = null) /* : void */
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function setElement(int $element = null) /* : void */
|
||||
{
|
||||
$this->element = $element;
|
||||
}
|
||||
|
||||
public function setComponent(int $component = null) /* : void */
|
||||
{
|
||||
$this->component = $component;
|
||||
}
|
||||
|
||||
public function setPermission(int $permission = 0) /* : void */
|
||||
{
|
||||
if($permission === 0) {
|
||||
$this->permission = 0;
|
||||
} else {
|
||||
$this->permission |= $permission;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
namespace Modules\Admin\Models;
|
||||
|
||||
/**
|
||||
* InfoManager class.
|
||||
*
|
||||
* Handling the info files for modules
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Module
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class PermissionManager
|
||||
{
|
||||
private $permissions = [];
|
||||
|
||||
private $id = 0;
|
||||
|
||||
public function __construct(int $id, array $permissions)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->permissions = $permissions;
|
||||
}
|
||||
|
||||
public function getId() : int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function hasPermission(int $permission, int $unit = null, int $app = null, int $module = null, int $type = null, $element = null, $component = null) : bool
|
||||
{
|
||||
foreach($this->permissions as $p) {
|
||||
if(($p->getUnit() === $unit || $p->getUnit() === null)
|
||||
&& ($p->getApp() === $app || $p->getApp() === null)
|
||||
&& ($p->getModule() === $module || $p->getModule() === null)
|
||||
&& ($p->getType() === $type || $p->getType() === null)
|
||||
&& ($p->getElement() === $element || $p->getElement() === null)
|
||||
&& ($p->getComponent() === $component || $p->getComponent() === null)
|
||||
&& ($permissions | $p->getPermission()) === $p->getPermission()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user