Ad

Register Permissions October Cms

I need help with registering permissions for a plugin. My plugin is 'event' and model is 'event'

1 How to define feature name in permission key.

acme.blog.access_categories //I don't know how to define this feature name

2 I need to create a permission to prevent some users from creating events in my events plugin in backend.

I have added new permission but it does nothing. Permission I created

 public function registerPermissions()
{
    return [
        'cng.tennis.access_events' => ['tab' => 'Events', 'label' => 'Create events']
    ];
}
Ad

Answer

1 Feature name

public function registerPermissions()
{
    return [
        'cng.tennis.access_events' => ['tab' => 'Events', 'label' => 'Create events'],
        'cng.tennis.create_events' => [ ... ],
        'cng.tennis.list_events' => [ ... ],
        'cng.tennis.delete_events' => [ ... ],
    ];
}

I guess you are already adding it 'label' => 'Create events' you can define multiple permissions there so you can assign each proper name.

And for the key you can use like

2 how to use permission

To restrict whole event controller you can add like this, now your whole controller is under that permission

<?php namespace Cng\Events\Controllers;

use Backend\Classes\BackendController;

class Events extends BackendController
{
    public $requiredPermissions = ['cng.tennis.access_events'];
}

To restrict some specific features suppose create event you need to add restrictions manually. for each you can add them as below

<?php namespace Cng\Events\Controllers;

use Backend\Classes\BackendController;

class Events extends BackendController
{

    // other code ...

    public function create($context = null) {

        // checking permission manually
        if (!$this->user->hasPermission(['cng.tennis.access_events'])) {
            // if user do not have permission show access restricted 
            return \Response::make(\View::make('backend::access_denied'), 403);
        }

        $this->asExtension('FormController')->create($context);
    }

    // ...

if any doubt please comment.

Ad
source: stackoverflow.com
Ad