2017 © Pedro Peláez
 

library permissioncontroller

Extended permissions for backend controllers in OctoberCMS.

image

niclasleonbock/permissioncontroller

Extended permissions for backend controllers in OctoberCMS.

  • Thursday, June 4, 2015
  • by niclasleonbock
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Permission Controller

This library adds extended permission support to controllers in OctoberCMS. It is built on top of the default $requiredPermissions property but extends it to be more powerful by adding the possibilty to define different permissions for different actions., (*1)

Hint: Due to the way Controller Behaviors work this is a class (and not a Behavior) you need to extend your controllers from., (*2)

Example

This will check for the required permissions depending on the action., (*3)

<?php namespace Vendor\Plugin\Controllers;

use Bock\PermissionController\Controller;

/**
 *  Back-end Controller
 */
class MyController extends Controller
{
    public $requiredPermissions = [
        'index'     => 'vendor.plugin.controller.list',
        'delete'    => 'vendor.plugin.controller.delete',
        'create'    => 'vendor.plugin.controller.create',
        'update'    => 'vendor.plugin.controller.update',
    ];

    // Rest of the code
}

Installation

First, you'll need to add the package to your composer.json and run composer update., (*4)

{
    "require": {
        "niclasleonbock/permissioncontroller": "dev-master"
    },
}

Helpers

getRequiredPermission
public getRequiredPermission($action)

Gets the required permission for an action (e.g. delete)., (*5)

isAllowed
public isAllowed($permission)

Alias for $this->user->hasAccess. Checks if the authenticated user has a given permission., (*6)

can
public can($action)

Checks wether the action is allowed in this request cycle, based on the user permissions. Can also be helpful in templates, e.g. to hide action buttons., (*7)

notAllowed
public notAllowed($flash = false)

Ends the current request with a not-allowed message. Either as flash message (if $flash is set to true) or an error page., (*8)

Bugs

Create a pull request or issue., (*9)

The Versions

04/06 2015

dev-master

9999999-dev

Extended permissions for backend controllers in OctoberCMS.

  Sources   Download

MIT

cms backend permission october