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 Permissions
gabessdsp
New
So I searched through the documentation, and I can't seem to find anything on how to check if a user has "x" permission. I want to add my own link to the menu but only when the user has "x" permission and that's why I need this.
0
Comments
Are you adding the link through a plugin?
A theme file?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Coding it through my theme I guess. Just looking for a way to check for the permission with the Garden Framework
Assuming you are using smarty, you can use the code below to check any permission:
Anything between enclosed in the if statement will be shown only if the currently signed in user has the permission.
For more information on Smarty tags, check out the wiki.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Is smarty another plugin to install or is it built in?
A quote from the link I shared:
It then goes on to talk about all the Smarty tags used in a standard master template.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
So I need to make a smarty tpl to check for the permission? I was hoping for a basic way in PHP
Vanilla 2.1+ uses Smarty, so you would have to use the
default.master.tpl
file for overriding the master template via the theme. Vanilla 2.0.18.8 usesdefault.master.php
, so you can use PHP code in the master template for 2.0.18.8.You can also create a theme hooks file. Let's say your theme is called "example" and you want to create a theme hooks file. You have to create one manually and it requires that you enter the correct theme name in the file name and in the class name. Replace the word "example" below in the file name and in the class name below to match your theme's name, and when you're finished creating the file, clear the cache folder of Vanilla to make sure it gets loaded.
/themes/example/class.examplethemehooks.php
Add Pages to Vanilla with the Basic Pages app
@Shadowdare said:
I'm kind of using it in a slightly different way, so I was hoping there was a direct
if('Garden.Moderation.Manage')
//do this
}else{
do this
}
but from my understanding that would mean I need to download and upgrade to Vanilla 2.1 beta.
You can check permissions on a controller with
$this->Permission('Permission.Name')
. You can check permissions through the session object withGdn::Session()->CheckPermission('Permission.Name')
.Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I think that second one is exactly what I am looking for. Thank you.