1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Checking Permissions

Discussion in 'XenForo Development Discussions' started by katsulynx, Jan 13, 2014.

  1. katsulynx

    katsulynx 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.
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    In a template:
    Code:
    <xen:if is="{$visitor.permissions.ctaFt.ctaFtViewFeaturedThreads}
    In PHP:
    Code:
    if (XenForo_Visitor::getInstance()->hasPermission('ctaFt', 'ctaFtViewFeaturedThreads')
     
    katsulynx likes this.
  3. katsulynx

    katsulynx Well-Known Member

    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?
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    That is the add-on ID.
     
    katsulynx likes this.
  5. katsulynx

    katsulynx Well-Known Member

    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.
     
  6. Brogan

    Brogan XenForo Moderator Staff Member

    Can you post screenshots of the add-on config screen and the permission definition page?
     
  7. katsulynx

    katsulynx Well-Known Member

    Sure. I've also just set my ACP back to english so things will be more fluent.

    These are my permission settings:
    [​IMG]

    [​IMG]

    And some stuff you might want to check:
    [​IMG]

    [​IMG]
     
  8. Brogan

    Brogan XenForo Moderator Staff Member

    And your add-on has KLUBS as the ID?

    From the snippet you have posted, your template modification doesn't look correct.
     
  9. katsulynx

    katsulynx Well-Known Member

    Should be KLUBS

    [​IMG]

    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: Jan 13, 2014
  10. katsulynx

    katsulynx Well-Known Member

    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.
     
  11. katsulynx

    katsulynx Well-Known Member

    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: Jan 14, 2014

Share This Page