josephcrowell/wn-passage-plugin 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

josephcrowell/wn-passage-plugin

Composer 安装命令:

composer require josephcrowell/wn-passage-plugin

包简介

Fast, Efficient permission system for controlling access to your website resources

README 文档

README

( Installation code : josephcrowell.wn-passage-plugin ) Requires ( Winter.User )

This plugin adds a front end user group permission system to WinterCMS.

Download the plugin to the plugins directory and logout and log in back into Winter backend. Go to the Passage Permissions page via the side menu in users in the backend and add your permissions.

User Permision / Passage Permission Entry

In the backend under Users (Winter.Users) you will find a sidemenu item called "Passage Permissions". This is where you enter your permission names and an optional description.

In the backend under Users you will find a button at the top called "User Groups". Press button to see groups. When editing a group you will find check boxes at the bottom for each "Passage Permission". This is where you assign permissions for each user group.

User Overrides

In the backend under Users (Winter.Users) you will find a sidemenu item called "User Overrides".

User overrides allow you to add permissions to individual users. You can also remove permission from users by adding a override and unchecking the Grant checkbox.

User Permisions in Pages or Partials

On a page you may restrict access to a portion of view by using the following twig functions:

{% if can('calendar_meetings') %}

<p>This will show only if the user belongs to a Winter.User Usergroup that includes the permission named "calendar_meetings".</p>

{% else %}

<p>This will show if the user DOES NOT belong to a Winter.User Usergroup that include the permission named "calendar_meetings".</p>

{% endif %}



{% if inGroup('my_admins') %}

<p>This will show only if the user belongs to a Winter.User Usergroup that has the code "my_admins".</p>

{% else %}

<p>This will show if the user DOES NOT belong to a Winter.User Usergroup that has the code "my_admins".</p>

{% endif %}


<p>This will show for all users regardless of permissions.</p>


{% if inGroupName('My Admins') %}

<p>This will show only if the user belongs to a Winter.User Usergroup that is named "My Admins".</p>

{% else %}

<p>This will show if the user DOES NOT belong to a Winter.User Usergroup that is named "My Admins".</p>

{% endif %}


<p>This will show for all users regardless of permissions.</p>

Available Twig Functions

  • can('PermissionName') - Check a passage permission name

  • hasPermissionName('PermissionName') - Check a passage permission name

  • hasPermissionNames(['PermissionName1','PermissionName2','PermissionName3']) - Check an array of passage permission names

  • hasPermission(PermissionId) (where PermissionId is an integer) - Check a passage permission id

  • hasPermissions([PermissionId1,PermissionId2,PermissionId3]) - Check an array of passage permission ids

  • inGroupName('GroupName') - Check a passage group name

  • inGroupNames(['Group Name','Group Name 2','Group Name 3']) - Check an array of passage group names

  • inGroup('GroupCode') - Check a passage group code

  • inGroups(['GroupCode1','GroupCode2','GroupCode3']) - Check an array of passage group codes

User Permisions in Your Own Plugins

// Passage Service Methods can be accessed in one of two ways:
use JosephCrowell\Passage\Classes\PermissionsService as PassageService;
$permissions_by_name = PassageService::passagePermissions(); // by Alias

//OR
$permissions_by_name = app('PassageService')::passagePermissions(); // by App Service

// Get all permissions for the user in an array
$permissions_by_name = PassageService::passagePermissions();

/**
* OR
*
* In your plugin you may restrict access to a portion of code:
**/

// check for permission directly using hasPermissionName( $permission_name )
$permissionGranted = PassageService::hasPermissionName('view_magic_dragon');
if($permissionGranted) {
 // Do stuff
}

/**
* OR
*
*  Lets say you have a model that uses a permission field containg the id of a
*   permission permission and want to see if model permission matches.
*
*  Example:
*  $model->perm_id = 5 which came from a dropdown that contained permissions
*  from PassageService::passagePermissions();
**/

$model = Model::first();
// check for permission directly using hasPermission( $permission_id )
if(PassageService::hasPermission($model->perm_id)) {
    // Do Stuff
}else{
    // Do other Stuff if user does NOT have permission
}

/**
* OR
*
*  Get Array of Groups
**/

// You can get array of the users groups keyed by the code of the group
$groups = PassageService::passageGroups()

/**
* OR
*
*  Check group membership by group code
**/

// use hasGroup($group_code) to check membership
$isCool = PassageService::hasGroup('cool_people')

/**
* OR
*
*  Check group membership by group Name
*   Note: Group names are not guaranteed to be unique.
*   DO NOT CHECK BY GROUP NAME if security is an issue.
**/

// use hasGroupName($group_name) to check membership
$isInGroupNamedCool = PassageService::hasGroupName('Cool')

Available Passage Service Methods

  • passagePermissions() - Get an array of all approved passage permissions for the user
  • can($permission_name) - (alias of hasPermissionName())
  • hasPermissionName($permission_name) - Check a passage permission name
  • hasPermission(integer $permission_id) - Check a passage permission id
  • hasPermissions(array $check_permission_ids) - Check an array of passage permission ids
  • hasPermissionNames(array $check_permissions) - Check an array of passage permission names
  • passageGroups() - Get an array of all approved passage groups for the user
  • inGroupName($group_name) - Check a passage group name
  • hasGroupName($group_name) - (alias of inGroupName())
  • inGroup($group_code) - Check a passage group code
  • hasGroup($group_code) - (alias of inGroup())
  • inGroups(array $check_group_codes) - Check an array of passage group ids
  • inGroupNames(array $check_groups) - Check an array of passage group names

These methods are also available directly on the [Winter\User\Models\User] model

  • $user->hasPermission(integer $permission_id) - Check a passage permission id
  • $user->hasPermissionName($permission_name) - Check a passage permission name
  • $user->hasPermissions(array $check_permission_ids) - Check an array of passage permission ids
  • $user->hasPermissionNames(array $check_permissions) - Check an array of passage permission names
  • $user->inGroup($group_code) - Check a passage group code
  • $user->inGroupName($group_name) - Check a passage group name
  • $user->inGroups(array $check_group_codes) - Check an array of passage group ids
  • $user->inGroupNames(array $check_groups) - Check an array of passage group names

josephcrowell/wn-passage-plugin 适用场景与选型建议

josephcrowell/wn-passage-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 374 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Authentication」 「cms」 「user」 「group」 「permission」 「override」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 josephcrowell/wn-passage-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 josephcrowell/wn-passage-plugin 我们能提供哪些服务?
定制开发 / 二次开发

基于 josephcrowell/wn-passage-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 374
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 25
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2021-04-20