JosephCrowell/wn-passage-plugin

快速、高效的权限系统,用于控制对您网站资源的访问

资助包维护!
Patreon

安装: 107

依赖关系: 1

建议者: 0

安全: 0

星标: 4

关注者: 0

分支: 2

类型:winter-plugin

2.0.2 2024-03-01 00:43 UTC

This package is auto-updated.

Last update: 2024-09-10 06:26:43 UTC


README

(安装代码:josephcrowell.wn-passage-plugin ) 需要 ( Winter.User )

此插件为 WinterCMS 添加前端用户组权限系统。

将插件下载到插件目录,并在 Winter 后端注销并重新登录。通过用户侧菜单访问“通道权限”页面并添加您的权限。

用户权限/通道权限条目

在后台用户(Winter.Users)下,您将找到一个名为 "通道权限"的侧菜单项。 这是您输入权限名称和可选描述的地方。

在后台用户下,您将找到一个顶部按钮 "用户组"。 点击按钮查看组。在编辑组时,您将在底部找到每个 "通道权限" 的复选框。这是您为每个用户组分配权限的地方。

用户覆盖

在后台用户(Winter.Users)下,您将找到一个名为 "用户覆盖"的侧菜单项。

用户覆盖允许您为单个用户添加权限。您还可以通过添加覆盖并取消选中 授权 复选框从用户中删除权限。

页面或部分中的用户权限

在一个页面上,您可以使用以下 twig 函数限制对视图部分访问

{% 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>

可用的 Twig 函数

  • can('PermissionName') - 检查通道权限名称

  • hasPermissionName('PermissionName') - 检查通道权限名称

  • hasPermissionNames(['PermissionName1','PermissionName2','PermissionName3']) - 检查通道权限名称数组

  • hasPermission(PermissionId) (其中 PermissionId 是一个整数) - 检查通道权限 ID

  • hasPermissions([PermissionId1,PermissionId2,PermissionId3]) - 检查通道权限 ID 数组

  • inGroupName('GroupName') - 检查通道组名称

  • inGroupNames(['Group Name','Group Name 2','Group Name 3']) - 检查通道组名称数组

  • inGroup('GroupCode') - 检查通道组代码

  • inGroups(['GroupCode1','GroupCode2','GroupCode3']) - 检查通道组代码数组

您自己的插件中的用户权限

// 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')

可用的通道服务方法

  • passagePermissions() - 获取用户所有已批准通道权限的数组
  • can($permission_name) - (hasPermissionName() 的别名)
  • hasPermissionName($permission_name) - 检查通道权限名称
  • hasPermission(integer $permission_id) - 检查通道权限 ID
  • hasPermissions(array $check_permission_ids) - 检查通道权限 ID 数组
  • hasPermissionNames(array $check_permissions) - 检查通道权限名称数组
  • passageGroups() - 获取用户所有已批准通道组的数组
  • inGroupName($group_name) - 检查通道组名称
  • hasGroupName($group_name) - (inGroupName() 的别名)
  • inGroup($group_code) - 检查通道组代码
  • hasGroup($group_code) - (inGroup() 的别名)
  • inGroups(array $check_group_codes) - 检查通道组 ID 数组
  • inGroupNames(array $check_groups) - 检查通道组名称数组