Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to check whether a user has permissions to a category

I know how to check permission with the checkPermission() function for a permission set by a plugin through "RegisterPermissions" (e.g. Plugins.Preview.View and checkPermission('Plugins.Preview.View')).

What it is not obvious to me how I check whether the user has permission to add or View discussions in a specific category (or for that matter other category-related permissions like add/view comments).

Can it be done via checkPermission and what parameters do I pass to it?

If not, how else can I check for these permissions?

Tagged:

Best Answer

Answers

  • Yes, This is an example:

    $UserHasPermission = Gdn::Session()->CheckPermission('Plugins.Attachments.Upload.Allow', TRUE);
    if(!$UserHasPermission) {
    return;
    }else{
    whatever else.....
    }
    
  • I am sorry, as I stated, I already know how to check permissions for plugins. What I am asking is how to check for permission to add discussions, view discussions, add comments, and view comments in a specific category.

  • Here are most of the configs for vanilla... you can make your own permissions to be followed or you can use Vanilla configs ... look at plugins that use permissions to get a clue. If you know how to check for permissions in a plugin then you already know everything you need..

    What it is not obvious to me how I check whether the user has permission to add or View discussions in a specific category (or for that matter other category-related permissions like add/view comments).

    Look at plugins that do this there already are several...

  • Thank you both for asnwering. @R_J - This is very helpful. I will give this a try and see what I come up with;-). Much appreciated!

Sign In or Register to comment.