Adding a Permission to an Existing Addon Help

dougiemac

Active member
Admin, please move if this isn't the correct forum. Thank you.

Preface:
I'm a product manager that hasnt coded since college really (20 years ago) and I'm very rusty at coding.

Objective: I want to add a view permission for an existing addon.

What I've done so far:
I've researched the forum and found some threads, but trying their suggestions / solutions hasnt netted a victory.

I've created the permission in the ACP Permission Definitions but I need to add some snipet of code to the template.

Questions:

So that leads me to two questions.
1. What template do I add the code in and where?
2. Is there a code snipet that I can use to copy and paste?

Thank you for any help.
 
Generally you'd add the code to the template and the PHP controller to prevent direct linking.

Generally, around the link to the page, you'd add a permission check like follows:

Code:
<xen:if is="{$visitor.permissions.<permission_group_id>.<permission_id>}">
//Link code.
</xen:if>

Then, in the controller (for the entire controller):

PHP:
<?php

XXX_XXX_ControllerPublic_XXX extends XenForo_ControllerPublic_Abstract
{
   protected function _preDispatch($action)
   {
      if (!XenForo_Visitor::getInstance()->hasPermission('<permission_group_id>', '<permsision_id>'))
      {
         throw $this->getNoPermissionResponseException();
      }
   }

   // Rest of controller
}

Or for a specific action:

PHP:
XXX_XXX_ControllerPublic_XXX extends XenForo_ControllerPublic_Abstract
{
   public function actionXXX()
   {
      if (!XenForo_Visitor::getInstance()->hasPermission('<permission_group_id>', '<permsision_id>'))
      {
           return $this->responseNoPermission();
      }

      // Rest of action
    }

    //rest of controller
}

Hope that makes sense :)

Liam
 
Top Bottom