diff options
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Access/Permissions.php | 42 | ||||
-rw-r--r-- | Zotlabs/Module/Connedit.php | 36 | ||||
-rw-r--r-- | Zotlabs/Module/Settings.php | 32 |
3 files changed, 80 insertions, 30 deletions
diff --git a/Zotlabs/Access/Permissions.php b/Zotlabs/Access/Permissions.php index b389fc229..61ea51a48 100644 --- a/Zotlabs/Access/Permissions.php +++ b/Zotlabs/Access/Permissions.php @@ -70,5 +70,47 @@ class Permissions { } + // converts [ 0 => 'view_stream', ... ] + // to [ 'view_stream' => 1 ] + // for any permissions in $arr; + // Undeclared permissions are set to 0 + + static public function FilledPerms($arr) { + $everything = self::Perms(); + $ret = []; + foreach($everything as $k => $v) { + if(in_array($k,$arr)) + $ret[$k] = 1; + else + $ret[$k] = 0; + } + return $ret; + + } + static public function FilledAutoperms($channel_id) { + if(! intval(get_pconfig($channel_id,'system','autoperms'))) + return false; + + $arr = []; + $r = q("select * from pconfig where uid = %d and cat = 'autoperms'", + intval($channel_id) + ); + if($r) { + foreach($r as $rr) { + $arr[$rr['k']] = $arr[$rr['v']]; + } + } + return $arr; + } + + static public function PermsCompare($p1,$p2) { + foreach($p1 as $k => $v) { + if(! array_key_exists($k,$p2)) + return false; + if($p1[$k] != $p2[$k]) + return false; + } + return true; + } }
\ No newline at end of file diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php index 260952b4e..7f34cfc9b 100644 --- a/Zotlabs/Module/Connedit.php +++ b/Zotlabs/Module/Connedit.php @@ -126,9 +126,7 @@ class Connedit extends \Zotlabs\Web\Controller { $rating = 10; $rating_text = trim(escape_tags($_REQUEST['rating_text'])); - - $abook_my_perms = 0; - + $all_perms = \Zotlabs\Access\Permissions::Perms(); if($all_perms) { @@ -136,13 +134,21 @@ class Connedit extends \Zotlabs\Web\Controller { if(array_key_exists('perms_' . $perm, $_POST)) { set_abconfig($channel['channel_id'],$orig_record[0]['abook_xchan'],'my_perms',$perm, intval($_POST['perms_' . $perm])); - $abook_my_perms ++; + if($autoperms) { + set_pconfig($channel['channel_id'],'autoperms',$perm,intval($_POST['perms_' . $perm])); + } } else { set_abconfig($channel['channel_id'],$orig_record[0]['abook_xchan'],'my_perms',$perm,0); + if($autoperms) { + set_pconfig($channel['channel_id'],'autoperms',$perm,0); + } } } } + + if(! is_null($autoperms)) + set_pconfig($channel['channel_id'],'system','autoperms',$autoperms); $new_friend = false; @@ -209,14 +215,11 @@ class Connedit extends \Zotlabs\Web\Controller { } } - if($all_perms) { - foreach($all_perms as $perm => $desc) { - if(array_key_exists($perm, $abook_my_perms)) - set_abconfig($channel['channel_id'],$orig_record[0]['abook_xchan'],'my_perms',$perm,1); - else - set_abconfig($channel['channel_id'],$orig_record[0]['abook_xchan'],'my_perms',$perm,0); - } + $filled_perms = \Zotlabs\Access\Permissions::FilledPerms($abook_my_perms); + foreach($filled_perms as $k => $v) { + set_abconfig($channel['channel_id'],$orig_record[0]['abook_xchan'],'my_perms',$k,$v); } + } $abook_pending = (($new_friend) ? 0 : $orig_record[0]['abook_pending']); @@ -245,10 +248,13 @@ class Connedit extends \Zotlabs\Web\Controller { info( t('Connection updated.') . EOL); else notice( t('Failed to update connection record.') . EOL); -//@fixme perms - if(\App::$poi && \App::$poi['abook_my_perms'] != $abook_my_perms - && (! intval(\App::$poi['abook_self']))) { - \Zotlabs\Daemon\Master::Summon(array('Notifier', (($new_friend) ? 'permission_create' : 'permission_update'), $contact_id)); + + if(! intval(\App::$poi['abook_self'])) { + \Zotlabs\Daemon\Master::Summon( [ + 'Notifier', + (($new_friend) ? 'permission_create' : 'permission_update'), + $contact_id + ]); } if($new_friend) { diff --git a/Zotlabs/Module/Settings.php b/Zotlabs/Module/Settings.php index 81d76a2dd..514078b2f 100644 --- a/Zotlabs/Module/Settings.php +++ b/Zotlabs/Module/Settings.php @@ -21,10 +21,7 @@ class Settings extends \Zotlabs\Web\Controller { // We are setting these values - don't use the argc(), argv() functions here \App::$argc = 2; \App::$argv[] = 'channel'; - } - - - + } } @@ -422,20 +419,25 @@ class Settings extends \Zotlabs\Web\Controller { ); } - foreach($global_perms as $k => $v) { - set_abconfig(local_channel(),$channel['channel_hash'],'my_perms',$k,((array_key_exists($k,$role_permissions['perms_connect'])) ? 1 : 0)); - } - - set_pconfig(local_channel(),'system','autoperms',(($role_permissions['perms_auto']) ? intval($role_permissions['perms_accept']) : 0)); - - foreach($role_permissions as $p => $v) { - if(strpos($p,'channel_') !== false) { - $set_perms .= ', ' . $p . ' = ' . intval($v) . ' '; + $x = \Zotlabs\Access\Permissions::FilledPerms($role_permissions['perms_connect']); + foreach($x as $k => $v) { + set_abconfig(local_channel(),$channel['channel_hash'],'my_perms',$k, $v); + if($role_permissions['perms_auto']) { + set_pconfig(local_channel(),'autoperms',$k,$v); + } + else { + del_pconfig(local_channel(),'autoperms',$k); } - if($p === 'directory_publish') { - $publish = intval($v); + } + + if($role_permissions['limits']) { + foreach($role_permissions['limits'] as $k => $v) { + \Zotlabs\Access\PermissionLimits::Set(local_channel(),$k,$v); } } + if(array_key_exists('directory_publish',$role_permissions)) { + $publish = intval($role_permissions['directory_publish']); + } } set_pconfig(local_channel(),'system','hide_online_status',$hide_presence); |