Jump to content

How to use hooks to override content that shows when a user has no permission to access that page


DrQuincy
 Share

Recommended Posts

When a user goes to a page in the CMS that they don't have permission to access you get two messages:

  1. ProcessWire: You don't have access to edit
  2. The process returned no content.

How can I use hooks to override these messages? Ideally for point 2, I'd like to use HTML.

Thanks.

Link to comment
Share on other sites

I'd take a different approach and use hooks Page::viewable and Page::editable in templates/admin.php to either throw a 404 or to redirect to some default page they can view. In either case you can add a message or error that will be shown at the top of the page.

 

  • Like 1
Link to comment
Share on other sites

Thanks for the suggestion.

It's slightly different in this instance since there are additional items in the admin that appear in the menu, which I can't remove, and it would just make it look like they're broken if they 404. I was hoping instead to simply override the text of these to make the user experience make more sense:

  1. ProcessWire: You don't have access to edit
  2. The process returned no content.

Even something as simple as a translation would be better:

  1. You don't have permission to view or edit anything on this page
  2. This page is for administrators only. Please click here to go back to the main admin page.

Is that easy to do?

Link to comment
Share on other sites

18 minutes ago, DrQuincy said:

and it would just make it look like they're broken if they 404

I proposed to either 404 or redirect. So if you redirect to the main admin page and add a message before you redirect, the user doesn't even need to click anywhere and gets there automatically. Better UX IMO.

20 minutes ago, DrQuincy said:

there are additional items in the admin that appear in the menu, which I can't remove

Which items would that be? You can setup your roles/permissions in a way that users only see the menu items for pages/processes they have access to. If your users get access to the page tree, you can use hooks that utilize Page::viewable to remove those pages from the tree that they should not see.

 

23 minutes ago, DrQuincy said:

Even something as simple as a translation would be better:

 

23 minutes ago, DrQuincy said:

Is that easy to do?

You'd have to activate language support (if you haven't already) and then in the settings for each language search through the core translation files to find those strings and then overwrite them.

  • Like 1
Link to comment
Share on other sites

Thank you. I totally agree with you but…

The reason I'm doing it this way is I'm using the https://github.com/Toutouwai/CustomAdminMenus plugin — and this is unaware of page permissions.

EDIT: I've realised this will do the job. It's not quite what I was after but it's a bit of an edge case anyway and only takes a minute to implement.

wireLangReplacements([
	
	'The process returned no content.' 	=> 'This page is either for administrators only or it doesn’t exist. Please go back and choose another page.',
  
]); 

Thanks for your help.

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...