From 1fb37f93ccf4739a6f92f3f36c1ee4ec8ef66a07 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 9 Feb 2017 19:52:13 -0800 Subject: more permissions optimisations --- Zotlabs/Lib/Permcat.php | 52 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'Zotlabs/Lib/Permcat.php') diff --git a/Zotlabs/Lib/Permcat.php b/Zotlabs/Lib/Permcat.php index 7988aff97..505ee2cfc 100644 --- a/Zotlabs/Lib/Permcat.php +++ b/Zotlabs/Lib/Permcat.php @@ -10,24 +10,52 @@ class Permcat { public function __construct($channel_id) { - $name = 'default'; - $localname = t('default','permcat'); - - $perms = Zaccess\Permissions::FilledAutoPerms($channel_id); - if(! $perms) { - $role = get_pconfig($channel_id,'system','permissions_role'); - if($role) { - $x = Zaccess\PermissionRoles::role_perms($role); + $perms = []; + + // first check role perms for a perms_connect setting + + $role = get_pconfig($channel_id,'system','permissions_role'); + if($role) { + $x = Zaccess\PermissionRoles::role_perms($role); + if($x['perms_connect']) { $perms = Zaccess\Permissions::FilledPerms($x['perms_connect']); } - if(! $perms) { - $perms = Zaccess\Permissions::FilledPerms([]); + } + + // if no role perms it may be a custom role, see if there any autoperms + + if(! $perms) { + $perms = Zaccess\Permissions::FilledAutoPerms($channel_id); + } + + // if no autoperms it may be a custom role with manual perms + + if(! $perms) { + $r = q("select channel_hash from channel where channel_id = %d", + intval($channel_id) + ); + if($r) { + $x = q("select * from abconfig where chan = %d and xchan = '%s' and cat = 'my_perms'", + intval($channel_id), + dbesc($r[0]['channel_hash']) + ); + if($x) { + foreach($x as $xv) { + $perms[$xv['k']] = intval($xv['v']); + } + } } } + // nothing was found - create a filled permission array where all permissions are 0 + + if(! $perms) { + $perms = Zaccess\Permissions::FilledPerms([]); + } + $this->permcats[] = [ - 'name' => $name, - 'localname' => $localname, + 'name' => 'default', + 'localname' => t('default','permcat'), 'perms' => Zaccess\Permissions::Operms($perms), 'system' => 1 ]; -- cgit v1.2.3