Giter Site home page Giter Site logo

userpermissions's Introduction

UserPermissions Plugin

Front-end user permissions management.

Requirements

This plugin requires the Winter.User Plugin.

Available Configurations

{plugin}/config/config.php
[
    /*
    * This lets you configure your own alias to use instead of the default
    * "hasUserPermission" method name. 
    */
    'hasUserPermissionAlias' => 'hasUserPermissionAlias'
]

Creating Permissions

In the backend, navigate to RainLab "Users" menu, on the left side there should
be a open lock icon with the name "Permissions". Click this and it will take you
to the list of permission.

  • Click "New Permission" to get to a form where you can enter information about a new
    permission you would like to create (dont forget to save).
  • Click on a permission in the list to manage existing permissions.

Managing User Permissions

In the backend, navigate to RainLab "Users" menu, either create a new user by
clicking "New User" and navigate to the "Permissions" tab of the newly opened form.
Here you can choose between "ALLOW", "INHERIT" or "DENY" for all existing permissions.

  • "ALLOW" will grant the user the permission, this takes precedence over group permissions.
  • "INHERIT" will grant the user the permission only if they also belong to a group which
    also has the permission set to allow (if they are checked).
  • "DENY" will NOT grant the user the permission, this takes precedence over group
    permissions meaning that even if the user belongs to a group with the permission
    allowed the user will not have the permission.

The same tab is available for all existing users, simply click the user you want
to manage in the user list and navigate to the "Permissions" tab.

Managing Group Permissions

In the backend, navigate to RainLab "Users" menu, either create a new group by
clicking "User Groups" and then on "New Group" or click the group you want to edit.
Navigate to the "Permissions" tab and click (check) all the permissions you want this group to have.

Using UserPermissions in your own development

Available UserPermissions functions:

/**
 * Check if user has supplied permissions
 *
 * @param mixed $permission Single string, single integer or Array structure with strings and/or integers
 * @param string $match How to match the permission(s), "all" or "one", defaults to "all"
 *
 * @return boolean Returns if user has supplied permission(s)
 */
function hasUserPermission($permission, $match = 'all') {
    <...>
}

Since every user model is extended with the same function it is available in both twig and backend php i.e.

For Twig

{% if user.hasUserPermission([1, 2, "can-eat-cake"]) %}
    <p>This user has all above permissions</p>
{% else %}
    <p>This user does not have permission</p>
{% endif %}

{% if user.hasUserPermission([1, 2, "can-eat-cake"], 'one') %}
    <p>This user has one of the above permissions</p>
{% else %}
    <p>This user does not have permission</p>
{% endif %}

{# Working fastest then checking 'hasUserPermission' for each permission#}
{# return all permission on array#}
{{user.UserAllPermission}}

{# return status of permission 'can-do-something'. If null - permission is disabled#}
{{user.UserAllPermission['can-do-something']}}

For Backend

if($user->hasUserPermission([1, 2, "can-eat-cake"])) {
    // This user has all above permissions
} else {
    // This user does not have permission
}

if($user->hasUserPermission([1, 2, "can-eat-cake"], 'one')) {
    // This user has one of the above permissions
} else {
    // This user does not have permission
}

// Working fastest then checking 'hasUserPermission' for each permission
// return all permissions
$all_permission = $user->UserAllPermission();

// return status of permission 'can-do-something'. If null - permission is disabled
$permission = $user->UserAllPermission()['can-do-something'];

userpermissions's People

Stargazers

Dheia avatar gviabcua avatar

Watchers

gviabcua avatar

Forkers

dheia

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.