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

How to add permissions to an addon?

Discussion in 'XenForo Development Discussions' started by Matthew Hawley, Jun 18, 2013.

  1. Matthew Hawley

    Matthew Hawley Well-Known Member

    So I have this:

    addonpermissions.png

    And this is the code in the template:

    Code:
    <xen:if is="{$perms.FindPostsInThread}">
    <xen:if is="{$hasPosted}">
            <li><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></li>
    </xen:if>
    </xen:if>
    Please don't just reply with some code, please tell me what to do with it.
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    I got your PM.

    Best bit of advice I can give is to check how I've done it in my Hide Poll Results add-on (it's one of my more recent add-ons). It contains various code relating to permission checks.
     
  3. James

    James Well-Known Member

    @Matthew Hawley what is this code for?
    Code:
    <xen:if is="{$perms.FindPostsInThread}">
    Permission checking in templates is done in this form:
    Code:
    <xen:if is="{$visitor.permissions.permissionGroupID.permissionID}">
    Permission Group ID -> Find Your Posts In A Thread (whatever the ID is)
    Permission ID -> canFindPostsInThread
     
  4. Matthew Hawley

    Matthew Hawley Well-Known Member

    Okay so i have this

    Code:
    <xen:if is="!{$xenOptions.findPostsInThreadEnable}">
    <xen:foreach loop="$posts" value="$post">
          <xen:if is="{$post.user_id} == {$visitor.user_id}">
                <xen:set var="$hasPosted">1</xen:set>
          </xen:if>
    </xen:foreach>
    <xen:if is="{$visitor.permissions.findPostsInThread.canFindPostsInThread}">
    <xen:if is="{$hasPosted}">
            <li><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></li>
    </xen:if>
    </xen:if>
    </xen:if>
    
    And the your posts link doesn't show up. I have the permission set as enabled for admins.
     
  5. James

    James Well-Known Member

    Code:
    <xen:if is="!{$xenOptions.findPostsInThreadEnable}">
    The exclamation mark is asking if the variable is false. Given that you're using "Enable" at the end, I imagine that is supposed to evaluate to true.
     
  6. Matthew Hawley

    Matthew Hawley Well-Known Member

    I looked at the code and it looks confusing
     
  7. Matthew Hawley

    Matthew Hawley Well-Known Member

    Thats not the problem. Though I did what you said and it still didn't work.
     
  8. Matthew Hawley

    Matthew Hawley Well-Known Member

  9. James

    James Well-Known Member

    Put debug code inside your code.

    Code:
    <xen:if is="!{$xenOptions.findPostsInThreadEnable}">
    <p style="background:red;">Enabled</p>
    
    <xen:foreach loop="$posts" value="$post">
          <xen:if is="{$post.user_id} == {$visitor.user_id}">
                <xen:set var="$hasPosted">1</xen:set>
    
    <p style="background:red;">Variable Set</p>
          
    </xen:if>
    </xen:foreach>
    <xen:if is="{$visitor.permissions.findPostsInThread.canFindPostsInThread}">
    
    <p style="background:red;">Has Permission</p>
    
    <xen:if is="{$hasPosted}">
    
    <p style="background:red;">Has Posted</p>
    
            <li><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></li>
    </xen:if>
    </xen:if>
    </xen:if>
    
     
  10. Matthew Hawley

    Matthew Hawley Well-Known Member

    whats the background red for?
     
  11. James

    James Well-Known Member

    So you can see it more easily... as it'll be red.
     
  12. Matthew Hawley

    Matthew Hawley Well-Known Member

    K. But that didn't fix the problem.

    threadtoolsproblem.png
     
  13. Matthew Hawley

    Matthew Hawley Well-Known Member

    LOL. I had the permission id wrong. Nvm it works! :ROFLMAO:
     
    James likes this.
  14. James

    James Well-Known Member

    No, but it's enabled us to see where the problem is, and it seems to be here:
    Code:
    <xen:if is="{$visitor.permissions.findPostsInThread.canFindPostsInThread}">
    
    Double-check the permission group ID and the permission ID (including the case).

    Ninja'd by the guy I was helping... cruel. :mad:
     
    Jon W likes this.
  15. James

    James Well-Known Member

    I'm currently at work and recently formatted my PC. I don't have a test setup of XF as I don't have a local webserver.
     
  16. Matthew Hawley

    Matthew Hawley Well-Known Member

    Ok.
     

Share This Page