Jump to content

Custom Pages in Admin with custom permissions


chrizz
 Share

Recommended Posts

Hi everyone,

I have searched a lot but unfortunately I didn't find anything on this use case:

I have created a custom page within the admin section. The page's template is admin.

Now I want to give access to editors to access this page - but this access is controlled by the admin template. 

What is the best approach to give access to a custom admin page without making the user a superuser/admin?

Any help is appreciated! :)

Link to comment
Share on other sites

Is this custom page attached to a process module?

In that case you simply assign a new permission to the process in the module's config, eg:

    public static function getModuleInfo()
    {
        return array(
            'title' => "My Process Module,
            'permission' => 'special_permission',
        );
    }

That will limit access and viewing to those roles with that new "special_permission" permission.

Does that take care of your needs?

If it doesn't have its own process, please explain a little better what this page does, how it was created etc.

  • Like 3
Link to comment
Share on other sites

I just tried to get this on the road, but unfortunately it seems as if I am stil searching for the forrest.

I have a process assinged to my customer manager page. 

This process uses the permission 'manage-events' as adrian mentioned before in the getModuleInfo

I have a role (called editor) which has the manage-events right. 

If I login with a testuser (roles: guest, editor) I only see the "Pages" entry but not my custom page. Do I have to clear the caches anywhere?

// EDIT

Note to myself: You should not mix permission and permissions :D

Btw: is there a way to reset the permissions without reinstalling a module?

Link to comment
Share on other sites

  • 1 year later...

Hi, I'm current creating a module (i'm extending process) that handles several things:

  • Configurable so that admin can change site's specific options.
  • Create a custom page in the backend for editor-only to handle custom logic.
  • Loaded on site to provide data for templates.

I'm using a custom permission in the function getModuleInfo to prevent other roles from accessing the custom page. However, when the module is loaded on the frontend for guests, it displays an exception saying lack of permission executing the module. How do I fix this issue? Thanks for your patience.

Link to comment
Share on other sites

Hello again KienNguyen,

I'm guessing a little from your description, but you could try removing the permission from the permission requirements in the module settings and explicitly check for it in the portion of the module's code that handles display of the custom admin page instead. This should make the module usable from the front end.

In your code that handles admin pages, you'd do something like;

if (!wire('user')->hasPermission('my-module-permission-name')) return;

Hope that helps.

Link to comment
Share on other sites

Hello again KienNguyen,

I'm guessing a little from your description, but you could try removing the permission from the permission requirements in the module settings and explicitly check for it in the portion of the module's code that handles display of the custom admin page instead. This should make the module usable from the front end.

Hi,

Yes, it was what I had done in the first place: just use page-view permission and then do logic check in the module. However, the page is still visible in the menu for others. Since I want the page to be invisible to other roles as well, I thought the most simple way would be to give editor role a custom permission but I encountered the error when I visit the site as a guest.

Is it good to login as super user first, load the module and then sign out? Is it difficult to hide the menu in the admin toolbar? I'm just thinking about the best possible solution here.

Again, thanks for your time :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...