sylvainjule/bouncer
Composer 安装命令:
composer require sylvainjule/bouncer
包简介
Restrict access of a user role to a specific page (and its children) in the panel.
README 文档
README
Restrict access of a user role to a specific page (and its children) in the panel.
Overview
This plugin is completely free and published under the MIT license. However, if you are using it in a commercial project and want to help me keep up with maintenance, you can consider making a donation of your choice.
1. Installation
Download and copy this repository to /site/plugins/bouncer
Alternatively, you can install it with composer: composer require sylvainjule/bouncer
2. Setup
The intent of this plugin is to limit a user's ability to edit only their Account page + pages (and their children) selected in a Pages field.
- First, create a new user role (for example,
/site/blueprints/users/test.yml) - Set their permissions, and add a
pagesfield:
title: Test permissions: access: panel: true site: true settings: false languages: false users: false # ... user: changeRole: false delete: false update: false # else a user will be able to edit the page they have access to on their profile fields: canaccess: label: 'The user will only be able to access:' type: pages options: query query: site.pages # or any query that suits your needs
- In your
site/config/config.php, tell the plugin whichrole => fieldnameassociations to use:
return [ 'sylvainjule.bouncer.list' => [ 'test' => [ // match the filename without extension of the user blueprint 'fieldname' => 'canaccess' ] ] ];
2.1 Allow additionnal paths
In your site/config/config.php, you can configure for each role some extra paths the user will be able to visit.
It can be useful if you have custom panel areas, for example.
return [ 'sylvainjule.bouncer.list' => [ 'test' => [ // match the filename without extension of the user blueprint 'extra' => [ [ 'title' => 'Area title', 'path' => '/area-path' ] ] ] ] ];
2.2 Optional page switcher
(beta)
Since 1.0.1 a given user can access different pages. You can remove the multiple: false option from the blueprint:
# User role blueprint title: Test fields: canaccess: label: 'The user will only be able to access:' type: pages options: query query: site.pages # or any query that suits your needs
Add a bouncernav section in every page you'd like to display the page switcher on:
// Anywhere in any blueprint (...) sections: bouncernav: type: bouncernav
Then state in your config.php that you want to display the page switcher for a given user role:
return [ 'sylvainjule.bouncer.list' => [ 'test' => [ 'fieldname' => 'canaccess', 'nav' => true ] ] ];
2.3 Fallback path
In your site/config/config.php, you can configure for each role which path to fallback to when the user tries to access a forbidden page.
It is optional: if left empty, the first accessible page from the Pages field associated to the user's role (canaccess, in our example) will be used.
return [ 'sylvainjule.bouncer.list' => [ 'test' => [ // match the filename without extension of the user blueprint 'fallback' => '/fallback-path' ] ] ];
2.4 Movable pages
By default, a restricted user will be able to move pages even to pages it cannot access.
Kirby calls a isMovableTo method to check which pages to disable / enable in the Move page dialog, which is declared in the Page class and cannot be overwritten globally from the plugin.
However if you want to apply the bouncer's restrictions to this page tree and disable restricted pages, the plugin provides a replacement method.
You have to declare a custom Page model for each page in order to apply it:
class ExamplePage extends Page { public function isMovableTo(Kirby\Cms\Page|Kirby\Cms\Site $parent): bool { return Bouncer::isMovableTo($this, $parent); } };
3. Disclaimer
I needed this functionnality for a website and turned it into a plugin. I hope it can prove helpful, but do not intend to extend it or support more refined restriction scenarios with this plugin.
4. License
MIT
sylvainjule/bouncer 适用场景与选型建议
sylvainjule/bouncer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.75k 次下载、GitHub Stars 达 68, 最近一次更新时间为 2020 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sylvainjule/bouncer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sylvainjule/bouncer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 68
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-11
