coresky / acl
ACL的生产级软件
0.545
2024-02-05 08:34 UTC
Requires
- php: >=7.4.0
- energy/air: *
This package is auto-updated.
Last update: 2024-09-24 05:05:45 UTC
README
生产级软件。如果你的应用程序需要访问控制管理器,请使用此产品。
在软件安装阶段可配置CUD操作日志。
简单模式:为用户配置文件创建/读取/更新/删除允许的对象。用户组和不用的用户ID不用于ACL。
扩展模式:用户配置文件、用户组、用户ID的创建/读取/更新/删除 = C/R/U/D,对象或对象ID的允许/拒绝。
用户到配置文件是一对多关系。用户到组是多对多关系。
调整软件
# Rewrite for a_ actions: if ($cnt && 'ctrl' == $surl[0]) { # Where 'ctrl' - tuning value (any of `/^[\w+\-]+$/`) common_c::$tune = array_shift($surl); $cnt--; }
在应用程序代码中的简单用法
您必须将至少\ACM
和控制器的c_acl
类导入应用程序命名空间。
// in the controllers: if (!ACM::Ressence()) return 404; // in the Jet's templates the same way: // @if(ACM::Ressence()) .. code .. ~if
Where Ressence
- R - 字符之一,为C/R/U/D或X。R - 读取访问
- essence - 从acl_object数据库表中获取对象(本质)名称
用于所选对象ID的使用
所选对象ID的访问
if (!$private || ACM::Rtopic($topic_id)) .. # Where $topic_id is ID numeric value, $topic_id cannot be 0 # Access records with obj_id=0 give access to any $topic_id # But you can tune access for defined $topic_id with access records where obj_id=$topic_id (!=0)
您必须将其放在common_c::head_y($action)
中
$sky->profiles = ACM::init([ 'topic' => fn() => (object)$this->t_topic->acl(), 'forum' => fn() => (object)$this->t_forum->acl(), # ...other objects with own access for defined obj_ID ]); # Where each `acl()` method return fields, see example: return [ 'from' => $this->qp('from $_ where private=1'), # must be class SQL object 'order' => 'order by id desc', 'columns' => ['id', 'topic_name || " " || dt', ['topic_name', 'dt']], ]; # Where columns[0] - column for obj_id # Where columns[1] - column for comment # Where columns[0] - array of columns for search filter
您可以使用调用创建所选ID的对象
ACM::object($obj, $obj_id, $desc) : `object record ID` # where $obj - object name, example: "topic" # where $desc - description # object type_id will taken from $obj/0 # you can give access after object created: ACM::access($id, $crud, $uid = 0, $pid = 0, $gid = 0) # where $id is `object record ID`
替换Jet模板
查看根模板调用
#._ magic marker
#if(Plan::view_t(['main', 'acl.jet']))
@inc(acl.)
#else
@inc(.menu)@inc(_access.)
#end
#._ magic marker
所有模板都可以通过文件acl.jet
中的应用程序代码进行更改。您还可以使用原始ACL Jet文件的某些部分,例如使用回溯调用:@inc(_user.profiles)
MySQL改进
-- use enum for object's types: ALTER TABLE tblname CHANGE `obj` `obj` enum('com','per','prj','act','face') DEFAULT NULL, -- add a index: ..
删除旧的ACL日志记录
您可以使用CRON任务等完成此操作
->at('2 2', function() use ($cron) { $cron->sql('delete from $_acl_log where dt ... '); })
虚构ACM类
如果应用程序代码包含对ACL类的引用,但您需要暂时卸载ACL产品,您可以在应用程序的w3文件夹中添加一个虚拟ACM类
<?php class ACM # stub class used when ACL ware do not installed { static function __callStatic($name, $args) { return false; # or true } }