Custom Module Admin Permission

Discussion in 'aMember Pro v.4' started by bfritton, Mar 28, 2013.

  1. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    Hello!
    I'm working on a module that has some custom permissions for a grid (Am_table and Am_Record type stuff) and I'm having trouble giving restricted permissions to admins for the grid.

    In my controller, I have
    PHP:
    public function checkAdminPermissions(Admin $admin)
        {
            if (
    $admin->hasPermission('zapi-edit-system-credit-cost')) {
                
    $this->adminHasEdit true;
                
    $perms $admin->getPermissions();
                
    $perms['grid_zapiSystemCreditCost']['edit'] = 1;
                
    $admin->setPermissions($perms);
            }
     
            if (
    $admin->hasPermission('zapi-browse-system-credit-cost')) {
                
    $perms $admin->getPermissions();
                
    $perms['grid_zapiSystemCreditCost']['browse'] = 1;
                
    $admin->setPermissions($perms);
                return 
    true;
            }
        }
    and in my bootstap.php I have
    PHP:
    function onGetPermissionsList(Am_Event $event)
        {
            
    $event->addReturn(___("Can view Zenya API customer credentials"), "zapi-browse");
            
    $event->addReturn(___("Can add/edit Zenya API customer credentials"), "zapi-edit");
            
    $event->addReturn(___("Can view system-level Zenya API credit cost table"), "zapi-browse-system-credit-cost");
            
    $event->addReturn(___("Can edit system-level Zenya API credit cost table"), "zapi_zapi-edit-system-credit-cost");
        }
    I got it so that the user with only the zapi custom browse and edit permissions can VIEW the grid (with the hacked setPermissions code in checkAdminPermissions() present) but they still can't edit the records or create a new one.

    I think my issue is that I need to nest the permissions in in a grid array, like the core permissions sets (http://screencast.com/t/0Mj5oikZlb), as I was, before the setPermissions() hack, getting access denied:
    "
    You have no enough permissions for this operation (grid_zapiSystemCreditCost-browse)"

    I haven't been able to figure out how to do this and can't locate the the core core segments that generate the product, content, users, etc permissions to follow.

    Any help with this? Thanks!
  2. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    For those who are wondering, I was able to get insert and delete capability by putting

    $perms['grid_zapiSystemCreditCost']['insert'] = 1;
    $perms['grid_zapiSystemCreditCost']['delete'] = 1;

    in under

    $perms['grid_zapiSystemCreditCost']['edit'] = 1;

Share This Page