Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2012, 02:53:13 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155506 Posts in 21711 Topics by 7737 Members
Latest Member: simpleguy
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Module Permissions  (Read 395 times)
mahalleday

Offline Offline

Posts: 188



WWW
« on: August 10, 2009, 11:58:51 PM »

How can I set/check a user/usergroup's permission level for my module?  Right now I can to see if the user is a admin the give them full access but it;s not the most elgant or scure why of going about it.  I know there are some admin classes built into WB to handle this I am just not sure how to implement them. 

If anyone can explain how or poitn me to an example or somethig in another mod I could follwo that would be great.
Logged

AdBaker2 Project Site: http://code.google.com/p/adbaker/
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #1 on: August 11, 2009, 12:16:02 AM »

Did you tried to go to access >show advanced options  and there to check/uncheck permisions for the group you want ?

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
mahalleday

Offline Offline

Posts: 188



WWW
« Reply #2 on: August 11, 2009, 12:22:33 AM »

What i mean is i ned to know what code i need to place in my module to check for permission the admins will set in the backend.
Logged

AdBaker2 Project Site: http://code.google.com/p/adbaker/
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #3 on: August 11, 2009, 12:45:08 AM »

you dont need to put any code... just set acces in access menu. for example if you uncheck the wysiwyg, every section in page menu with wysiwyg will be visible...

just play a little with those permissions and you will figure out..

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
SourDough

Offline Offline

Posts: 47


WWW
« Reply #4 on: August 11, 2009, 07:18:19 PM »

How about this:

Code:
function checkPerm(){
   
    require_once(WB_PATH.'/framework/class.wb.php');
    global $page_id, $database;
    $wb = new wb;
   
        //Borrowed code from Frontend Edit snippet.
        if (is_numeric($wb->get_session('USER_ID'))) {
            /**
            *    Get permissons
            */
            if ($page_id)
                $this_page = $page_id;
            else
                $this_page = $wb->default_page_id;
           
            $results = $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$this_page'");
            $results_array = $results->fetchRow();
            $old_admin_groups = explode(',', $results_array['admin_groups']);
            $old_admin_users = explode(',', $results_array['admin_users']);
            $this_user = $wb->get_session('GROUP_ID');
   
            $query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '".$page_id."'";
            $get_pages = $database->query($query);
           
            $page = $get_pages->fetchRow();
            $admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
            $admin_users = explode(',', str_replace('_', '', $page['admin_users']));
            $in_group = FALSE;
           
            foreach($wb->get_groups_id() as $cur_gid)
                if (in_array($cur_gid, $admin_groups)) $in_group = TRUE;
           
            if (($in_group) OR is_numeric(array_search($this_user, $old_admin_groups)) ) {
                return TRUE;
            }     
        }
}

You can then call it with:
Code:
if(checkPerm() == TRUE) {
        //code to execute if user is in admin group for this module
} else {
        //code to run otherwise
}

As the comment in the code states, most of this is from the frontend edit snippet.  I've used it in a few projects on an intranet and haven't had any issues.  However, I do think it would be nice to have a built in function for this type of thing.  I'm working on a couple modules that allow frontend editing and have been making due with this.

Nick
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!