How to add permissions to an addon?

Matthew Hawley

Well-known member
So I have this:

addonpermissions.webp

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.
 
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.
 
@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
 
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.
 
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.
 
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.

Thats not the problem. Though I did what you said and it still didn't work.
 
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>
 
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>

whats the background red for?
 
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.
 
Top Bottom