Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@startuml | ||
|
||
legend right | ||
|<#FFDDDD> <b>E</b> | <b>Role</b> | | ||
|<#DDFFDD> <b>P</b> | <b>Permission</b> | | ||
endlegend | ||
|
||
!define Role(name,desc) component "desc" as name << (R,#EEEEEE) >> #FFDDDD | ||
!define Permission(name,desc) () name as "desc" #DDFFDD | ||
hide methods | ||
hide stereotypes | ||
|
||
package "Client" { | ||
|
||
Role(client_manager, "client.manager") | ||
|
||
Permission(client_create, "client.create") | ||
Permission(client_update, "client.update") | ||
Permission(client_get_note, "client.get-note") | ||
Permission(client_set_note, "client.set-note") | ||
} | ||
|
||
|
||
client_create -> client_manager | ||
client_update -> client_manager | ||
client_get_note -> client_manager | ||
client_set_note -> client_manager | ||
|
||
client_create -[hidden]-> client_update | ||
client_update -[hidden]-> client_get_note | ||
client_get_note -[hidden]-> client_set_note | ||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* RBAC implementation for HiPanel | ||
* | ||
* @link https://github.com/hiqdev/hipanel-rbac | ||
* @package hipanel-rbac | ||
* @license BSD-3-Clause | ||
* @copyright Copyright (c) 2016-2019, HiQDev (http://hiqdev.com/) | ||
*/ | ||
|
||
namespace hipanel\rbac\console; | ||
|
||
use yii\rbac\PhpManager; | ||
use yii\rbac\Item; | ||
|
||
class PlantUML | ||
{ | ||
/** | ||
* @var PhpManager | ||
*/ | ||
protected $auth; | ||
|
||
public function __construct($auth) | ||
{ | ||
$this->auth = $auth; | ||
} | ||
|
||
public function build() | ||
{ | ||
$path = dirname(__DIR__, 2) . '/docs/test.md'; | ||
|
||
$header = "@startuml"; | ||
$footer = "@enduml"; | ||
$legend = ' | ||
legend right | ||
|<#FFDDDD> <b>E</b> | <b>Role</b> | | ||
|<#DDFFDD> <b>P</b> | <b>Permission</b> | | ||
endlegend | ||
'; | ||
|
||
$defs = ' | ||
!define Role(name,desc) component "desc" as name << (R,#EEEEEE) >> #FFDDDD | ||
!define Permission(name,desc) () name as "desc" #DDFFDD | ||
hide methods | ||
hide stereotypes | ||
'; | ||
|
||
$items = []; | ||
$links = []; | ||
$hidds = []; | ||
|
||
$permissions = $this->auth->getPermissions(); | ||
foreach ($permissions as $name => $perm) { | ||
if ($this->isDeny($name)) { | ||
continue; | ||
} | ||
|
||
$id = $this->toId($name); | ||
$items[] = "Permission($id, \"$name\")"; | ||
|
||
if (!empty($old_id)) { | ||
$hidds[] = "$old_id -[hidden]-> $id"; | ||
} | ||
$old_id = $id; | ||
} | ||
|
||
$items[] = ''; | ||
|
||
foreach ($this->auth->getRoles() as $parent => $role) { | ||
$parent_id = $this->toId($parent); | ||
|
||
$items[] = "Role($parent_id, \"$parent\")"; | ||
foreach ($this->auth->getChildren($parent) as $child => $item) { | ||
$child_id = $this->toId($child); | ||
$links[] = "$child_id -> $parent_id"; | ||
} | ||
} | ||
|
||
$items = $this->joinClientOnly($items); | ||
$links = $this->joinClientOnly($links); | ||
$hidds = $this->joinClientOnly($hidds); | ||
$res = implode("\n", [$header, $legend, $defs, $items, '', $links, '', $hidds, '', $footer, '']); | ||
|
||
return $res; | ||
} | ||
|
||
private function isDeny(string $name): bool | ||
{ | ||
return strncmp($name, 'deny', 4) === 0; | ||
} | ||
|
||
private function toId(string $name): string | ||
{ | ||
return strtr($name, ':.-', '___'); | ||
} | ||
|
||
private function joinClientOnly($arr) | ||
{ | ||
$res = []; | ||
foreach ($arr as $str) { | ||
if (strpos($str, 'client') !== false) { | ||
$res[] = $str; | ||
} | ||
} | ||
|
||
return implode("\n", $res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters