MyBB Community Forums

Full Version: Permission system based on additional groups
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm using this code inside a custom page:

<?php
if (is_member("4,6")){
} else {
error_no_permission();
} 
?>

So that admins and users inside a group 6 can access content of the page.

It works fine with my Admin profile, but I created a test profile which belongs to group 6 (additional) while his primary one is Registered and he gets the no permissions page. How can I fix this?

I will create mutliple custom pages in future and would be impossible to allow users to access only certain ones using primary groups. I don't understand why the "is_member" fucntion seems to check only primary group and not additional nes Sad
Try:

<?php
if (is_member("4","6")){
} else {
error_no_permission();
} 
?>
(2015-05-27, 06:38 PM)Ben C Wrote: [ -> ]Try:

<?php
if (is_member("4","6")){
} else {
error_no_permission();
} 
?>

Sorry it didn't change the result Sad
define("IN_MYBB", 1);
require_once "global.php";
$groups = $mybb->user['usergroup'];
if($mybb->user['additionalgroups'])
{
$groups.= "," . $mybb->user['additionalgroups'];
}
$explodedgroups = explode(",", $groups);
$canview  = 0;
$allowedgroups = array(4, 6);
foreach($explodedgroups as $group)
{
if(in_array($group, $allowedgroups))
{
$canview = 1;
break;
}
}
if(!$canview)
{
error_no_permission();
}
// Rest of page
(2015-05-27, 06:55 PM)dragonexpert Wrote: [ -> ]
define("IN_MYBB", 1);
require_once "global.php";
$groups = $mybb->user['usergroup'];
if($mybb->user['additionalgroups'])
{
$groups.= "," . $mybb->user['additionalgroups'];
}
$explodedgroups = explode(",", $groups);
$canview  = 0;
$allowedgroups = array(4, 6);
foreach($explodedgroups as $group)
{
if(in_array($group, $allowedgroups))
{
$canview = 1;
break;
}
}
if(!$canview)
{
error_no_permission();
}
// Rest of page

I had already declared that file was in mybb Sad

However your code didn't work... my test profile got the nopermission message... it's like mybb only checks primary usergroup and not additional ones - i edited profile so that it displays group 6 but nothing -.
Is the person in the correct group? It uses both the primary usergroup and additional groups to see if the person is in usergroup 4 or 6. I don't use display groups because that is not what should be used for permissions. The code I provided doesn't use permissions of groups at all.
(2015-05-27, 07:09 PM)dragonexpert Wrote: [ -> ]Is the person in the correct group?  It uses both the primary usergroup and additional groups to see if the person is in usergroup 4 or 6. I don't use display groups because that is not what should be used for permissions. The code I provided doesn't use permissions of groups at all.

Damn... my bad, your code did work in effect but i refreshed page (or didn't refresh?) and I couldn't see changes applied.... excuse me...

Issue is solved and your code is working Smile
(2015-05-27, 06:59 PM)ShadowOne Wrote: [ -> ]it's like mybb only checks primary usergroup and not additional ones - i edited profile so that it displays group 6 but nothing -.

It checks all groups and it works fine for me..
https://github.com/mybb/mybb/blob/featur...L6862-6865
https://github.com/mybb/mybb/blob/featur...L6872-6873
(2015-05-28, 12:55 AM)Destroy666 Wrote: [ -> ]
(2015-05-27, 06:59 PM)ShadowOne Wrote: [ -> ]it's like mybb only checks primary usergroup and not additional ones - i edited profile so that it displays group 6 but nothing -.

It checks all groups and it works fine for me..
https://github.com/mybb/mybb/blob/featur...L6862-6865
https://github.com/mybb/mybb/blob/featur...L6872-6873

Hi, it's what I'm looking for I think. Allow to users of additionalgroups to see a thing in postbit (usertitle only if in an additional group).
http://community.mybb.com/thread-143131-...pid1172588

This code I can add in showthread.php?