GithubHelp home page GithubHelp logo

dheia / wn-passage-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from josephcrowell/wn-passage-plugin

0.0 0.0 0.0 105 KB

Efficient user permission system for Winter CMS

License: Other

PHP 75.94% HTML 24.06%

wn-passage-plugin's Introduction

Passage plugin

( Installation code : josephcrowell.passage ) 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:
$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

wn-passage-plugin's People

Contributors

josephcrowell avatar firemankurt avatar ndcisiv avatar ribsousa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.