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
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:
if($user->role("Moderator"))
{
// 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?
---
Question: Is it possible for me to check the user role or permission? What i would like to do is something like this:
if($user->role("Moderator"))
{
// 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?
0
Comments
Gdn::Session()->CheckPermission('Application.Permission.Name');
Vanilla Forums COO [GitHub, Twitter, About.me]
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.
// Define some global vanilla permissions. $PermissionModel->Define(array( 'YourApp.Some.Permission', 'YourApp.Some.OtherPermission' ));
Vanilla Forums COO [GitHub, Twitter, About.me]
Vanilla Forums COO [GitHub, Twitter, About.me]
$PermissionModel = Gdn::PermissionModel();
$PermissionModel->Database = $Database;
$PermissionModel->SQL = $SQL;
$PermissionModel->Define(array(
'Community.News.Manage'
));
Then ive disabled/reenabled my app but still i cannot give the role "Moderator" the permission community.news.manage. It does not show up when i'am editing the role "Moderator".
What am i doing wrong?
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' => 'rasmnus@styrk-it.dk', 'AuthorUrl' => 'http://styrk-it.dk', 'License' => 'Copyright 2010 (C) Styrk-IT' );