aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Access
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-02-09 17:29:24 -0800
committerzotlabs <mike@macgirvin.com>2017-02-09 17:29:24 -0800
commit16f27d000460725d26eb875e8522c768100c1715 (patch)
tree5c8201dc6207aba0114e1ec3e4382af1345dbce3 /Zotlabs/Access
parent8dc349caaca378192051ee08e282de3bc1679c14 (diff)
downloadvolse-hubzilla-16f27d000460725d26eb875e8522c768100c1715.tar.gz
volse-hubzilla-16f27d000460725d26eb875e8522c768100c1715.tar.bz2
volse-hubzilla-16f27d000460725d26eb875e8522c768100c1715.zip
more work on permcats and consolidating calls that try to discover connect permissions, also create lowlevel store functions for abook and profile - since these currently may have issues with sql strict mode.
Diffstat (limited to 'Zotlabs/Access')
-rw-r--r--Zotlabs/Access/Permissions.php75
1 files changed, 73 insertions, 2 deletions
diff --git a/Zotlabs/Access/Permissions.php b/Zotlabs/Access/Permissions.php
index b4b2e4d44..52526d020 100644
--- a/Zotlabs/Access/Permissions.php
+++ b/Zotlabs/Access/Permissions.php
@@ -117,7 +117,6 @@ class Permissions {
}
-
static public function FilledAutoperms($channel_id) {
if(! intval(get_pconfig($channel_id,'system','autoperms')))
return false;
@@ -128,7 +127,7 @@ class Permissions {
);
if($r) {
foreach($r as $rr) {
- $arr[$rr['k']] = $arr[$rr['v']];
+ $arr[$rr['k']] = intval($rr['v']);
}
}
return $arr;
@@ -143,4 +142,76 @@ class Permissions {
}
return true;
}
+
+ static public function connect_perms($channel_id) {
+
+ $my_perms = [];
+ $permcat = null;
+ $automatic = 0;
+
+ // If a default permcat exists, use that
+
+ $pc = ((feature_enabled($channel_id,'permcats')) ? get_pconfig($channel_id,'system','default_permcat') : 'default');
+ if(! in_array($pc, [ '','default' ])) {
+ $pcp = new Zlib\Permcat($channel_id);
+ $permcat = $pcp->fetch($pc);
+ if($permcat && $permcat['perms']) {
+ foreach($permcat['perms'] as $p) {
+ $my_perms[$p['name']] = $p['value'];
+ }
+ }
+ }
+
+ // look up the permission role to see if it specified auto-connect
+ // and if there was no permcat or a default permcat, set the perms
+ // from the role
+
+ $role = get_pconfig($channel_id,'system','permissions_role');
+ if($role) {
+ $xx = PermissionRoles::role_perms($role);
+ if($xx['perms_auto'])
+ $automatic = 1;
+
+ if((! $my_perms) && ($xx['perms_connect'])) {
+ $default_perms = $xx['perms_connect'];
+ $my_perms = Permissions::FilledPerms($default_perms);
+ }
+ }
+
+ // If we reached this point without having any permission information,
+ // it is likely a custom permissions role. First see if there are any
+ // automatic permissions.
+
+ if(! $my_perms) {
+ $m = Permissions::FilledAutoperms($channel_id);
+ if($m) {
+ $automatic = 1;
+ $my_perms = $m;
+ }
+ }
+
+ // If we reached this point with no permissions, the channel is using
+ // custom perms but they are not automatic. They will be stored in abconfig with
+ // the channel's channel_hash (the 'self' connection).
+
+ if(! $my_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) {
+ $my_perms[$xv['k']] = intval($xv['v']);
+ }
+ }
+ }
+ }
+
+ return ( [ 'perms' => $my_perms, 'automatic' => $automatic ] );
+ }
+
} \ No newline at end of file