Checking Permissions

Lukas W.

Well-known member
I've been struggling for quite a while now when trying to create my own addon and have come to the conclusion, that I will just bombard you with my questions. First one is about custom permissions in templates.

So I've activated debug mode and created a new permission for my addon, however I want to make a use out of it now of course. I've tried to do some research about the topic - needless to say I failed.

What I want to do exactly:
I have created a code snippet in a custom template modification inside the TMS and want to wrap it in (I guess) some sort of If-query to see, if the current user has sufficient permissions to see the code inside.
 
In a template:
Code:
<xen:if is="{$visitor.permissions.ctaFt.ctaFtViewFeaturedThreads}

In PHP:
Code:
if (XenForo_Visitor::getInstance()->hasPermission('ctaFt', 'ctaFtViewFeaturedThreads')
 
Haven't quite understood the syntax completely. Guess I need to replace the ctaFt and ctaFtViewFeaturedThreads with my stuff, and by the simple length of the second one I conclude, that it must be the permission ID but however, what is the first?
 
I've did it like this now:
Code:
<xen:if is="{$visitor.permissions.KLUBS.KLUBSPermission01}">
    //my Code
</xen:if>

Description inside the overview of all permissions is "KLUBS / general - KLUBSPermission01" and for testing purpose I've of course given all admins the permission, rest is set to default, but however it denies working.
 
Can you post screenshots of the add-on config screen and the permission definition page?
 
Sure. I've also just set my ACP back to english so things will be more fluent.

These are my permission settings:




And some stuff you might want to check:
th_600090441_Permission_122_12lo.jpg


 
And your add-on has KLUBS as the ID?

From the snippet you have posted, your template modification doesn't look correct.
 
Should be KLUBS



EDIT: Don't know what I changed, but now it works. :cautious: Thanks!
EDIT2: Nah, somehow does ignore every settings now and works either way...
 
Last edited:
I've tried around a lot, but it still doesn't work. My code is by now
Code:
<xen:if is="{$visitor.permissions.KLUBS.KLUBSPermission01}">
TMS doesn't complain about the syntax, but it doesn't work no matter how I set the permissions. The other way round when setting
Code:
<xen:if is="!{$visitor.permissions.KLUBS.KLUBSPermission01}">
it works, even when I set permission to never. IDs are definitly correct as they are copy-pasted.
 
Lots of struggle later, but I still haven't figured it out. Step by step I did the following:

  1. I went to the Development tab and created a new Addon, ID: test01
  2. Opened up the Permission Definitions and added a new Interface Group, ID: TestGroup
  3. Added a new permission, ID: PermissionID01
  4. I've set the new Permission to allow for everyone
  5. Created a new template modification, containing the following code for testing purpose:
    Code:
    <xen:if is="{$visitor.permissions.test01.TestGroup.PermissionID01}">
    <!--Finally Working-->
    <xen:else />
      <!--Somewhat...-->
    </xen:if>
    I've tried a variety of if-checks, including $PermissionID01, $test01.TestGroup.PermissionID01, $test01.PermissionID01, $visitor.permissions.test01.PermissionID01, $visitor.permissions.test01.TestGroup.PermissionID01, $visitor.permissions.PermissionID01 and $visitor.permissions.PermissionID01
  6. Still getting punched in the face by the code spitting out the "Somewhat..." comment, no matter how I set the permissions for any existing group/user.

Edit: Finally understood the system and got it working... it has to be $visitor.permissions.permissionGroupID.permissionID
 
Last edited:
Top Bottom