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.

check for user role/permission

edited September 2010 in Vanilla 2.0 - 2.8
I was unable to find anything when searching.


Question: Is it possible for me to check the user role or permission? What i would like to do is something like this:

// do something with moderator

I have tried different things and even looked through alot of the files that came with the installation but i cant seem to find any solution.

Do i need to write my own function to check this?


  • Options
    TimTim Operations Vanilla Staff
    You cannot check for specific roles, but you can look for permissions for the logged-in user very easily:


    Vanilla Forums COO [GitHub, Twitter,]

  • Options
    Okay that is also fine. Thanks.
  • Options
    @styrk: I wrote an add-on (not in the addon repository here yet) that looks up the Roles of users. The same concept could conceivably be used to look up this information and use it in the way you want to.

    My addon exists to print the users's role in their post meta-data, though. I use roles as a sort of "reward" for loyalty to the forums, which doesn't actually confer any special abilities. So displaying that role is sort of important to that process.

    I think @Tim has a better way for you, though. Since roles are 100% definable by the user of the software, it's much safer to just check for permissions.
  • Options
    a followup question regarding this, how can i get my app have its own kind if persmission? (So that i can check/uncheck it under a role).
  • Options
    TimTim Operations Vanilla Staff
    In applications/your_app/settings/structure.php:

    // Define some global vanilla permissions. $PermissionModel->Define(array( 'YourApp.Some.Permission', 'YourApp.Some.OtherPermission' ));

    Vanilla Forums COO [GitHub, Twitter,]

  • Options
    Okay - i guess that only works when i'am installing the app, but what if my app is already setup ?
  • Options
    TimTim Operations Vanilla Staff
    Disable and enable it

    Vanilla Forums COO [GitHub, Twitter,]

  • Options
    Okay, i put this in my app stucture.php (applications/community/settings/structure.php)

    $PermissionModel = Gdn::PermissionModel();
    $PermissionModel->Database = $Database;
    $PermissionModel->SQL = $SQL;


    Then ive disabled/reenabled my app but still i cannot give the role "Moderator" the permission It does not show up when i'am editing the role "Moderator".

    What am i doing wrong?
  • Options
    Okay I got it working. Here is how:

    In your about.php file you have to add an array to RegisterPermissions value and then re-enable the app. In my app my about.php looks like.

    $ApplicationInfo['Community'] = array( 'Description' => "A tournament community system", 'Version' => '1.0', 'RegisterPermissions' => array("Community.News.Manage", "Community.Tournaments.Manage", "Community.Tournaments.Master"), 'SetupController' => 'setup', 'AllowEnable' => TRUE, // You can remove this when you create your own application (leaving it will make it so the application can't be enabled by Garden) 'Author' => "Rasmus Styrk", 'AuthorEmail' => '', 'AuthorUrl' => '', 'License' => 'Copyright 2010 (C) Styrk-IT' );
Sign In or Register to comment.