1
zite83
Creating my own permissions class for my module.
  • 2010/8/13 21:19

  • zite83

  • Just popping in

  • Posts: 41

  • Since: 2004/10/5


This is what I found at Adding Group Permissions and starting playing around with it in some of my test modules.


$gperm_handler =& xoops_gethandler('groupperm');
$cando $gperm_handler->checkRight($perm_name1$groups$mod_id)

if (
$cando){

   echo 
'true';

}else{

   echo 
'false';

}


What I wanted to come up with was a simple class that I could check all permissions for that user through out my module. What I came up with seems to work, but I'm not that great with security and just wanted to know if this is safe way to check my modules permissions or is there another direction I should go.

//Create new object while passing what I want to check
$replayPermissions = new replayPermissions('replay_permissions');


if (
$replayPermissions->canDelete()){
    echo 
'True';    
}else{
    echo 
'False';    
}



Class itself, just to note is only checking one type of permissions "replay_permissions" that is for module wide and not just one specific id or item.

if (!defined('XOOPS_ROOT_PATH')) {
    die(
"XOOPS root path not defined");
}



class 
replayPermissions {

    private 
$isAdmin false;
    private 
$view false;
    private 
$submit false;
    private 
$edit false;
    private 
$delete false;
    private 
$download false;
    private 
$vote false;
    private 
$edit_others false;
    private 
$delete_others false;


    function 
replayPermissions()
    {
        
$this->__construct();
    }

    function 
__construct($perm_name){
        

         global 
$xoopsUser;
        
        
$uid = (is_object($xoopsUser)) ? intval($xoopsUser->uid()): 0;
        
$groups = (is_object($xoopsUser)) ? $xoopsUser->getGroups(): XOOPS_GROUP_ANONYMOUS
         
        
         
        
$module_handler =& xoops_gethandler('module');
        
$module =& $module_handler->getByDirname('replay');
        
$mid $module->getVar('mid');
        
        
$gperm_handler =& xoops_gethandler('groupperm');
        
        
$this->isAdmin $gperm_handler->checkRight('system_admin'$uid$groups);
        
$this->view $gperm_handler->checkRight($perm_name$groups$mid);        
        
$this->submit $gperm_handler->checkRight($perm_name$groups$mid);    
        
$this->edit $gperm_handler->checkRight($perm_name$groups$mid);
        
$this->delete $gperm_handler->checkRight($perm_name$groups$mid);    
        
$this->download $gperm_handler->checkRight($perm_name$groups$mid);    
        
$this->vote $gperm_handler->checkRight($perm_name$groups $mid);    
        
$this->edit_others $gperm_handler->checkRight($perm_name$groups$mid);    
        
$this->delete_others $gperm_handler->checkRight($perm_name$groups$mid);        

    }
    
    
    function 
isAdmin() { 
    
        return 
$this->isAdmin;
    
    }
    
    function 
canView() { 
    
        return 
$this->view
    
    }
    
    function 
canSubmit() { 
    
        return 
$this->submit
    
    }
    
    function 
canEdit() { 
    
        return 
$this->edit
    
    }
    
    function 
canDelete() { 
    
        return 
$this->delete
    
    }
    
    function 
canDownload() { 
    
        return 
$this->download
    
    }
    
    function 
canVote() {
    
        return 
$this->vote;
    
    }
    
    function 
canEdit_others() { 
    
        return 
$this->edit_others
    
    }
    
    function 
canDelete_others() {
    
        return 
$this->delete_others
    
    }
}

Login

Who's Online

141 user(s) are online (102 user(s) are browsing Support Forums)


Members: 0


Guests: 141


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits