diff options
author | Mario Vavti <mario@mariovavti.com> | 2017-03-08 09:39:46 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2017-03-08 09:39:46 +0100 |
commit | bc2b948f1f6e62b1c277a4042200bb6678956f3f (patch) | |
tree | 8586c30e495607eee23f16c0aad40974f0711275 /Zotlabs/Access | |
parent | 23e3e2c50499fab52769929a448e73012fd915af (diff) | |
parent | ff9442474d07cce24c8f66db39ec34471c3874a2 (diff) | |
download | volse-hubzilla-2.2.tar.gz volse-hubzilla-2.2.tar.bz2 volse-hubzilla-2.2.zip |
Merge branch 2.2RC2.2
Diffstat (limited to 'Zotlabs/Access')
-rw-r--r-- | Zotlabs/Access/PermissionRoles.php | 53 | ||||
-rw-r--r-- | Zotlabs/Access/Permissions.php | 95 |
2 files changed, 128 insertions, 20 deletions
diff --git a/Zotlabs/Access/PermissionRoles.php b/Zotlabs/Access/PermissionRoles.php index 94c49c44f..49d478c5c 100644 --- a/Zotlabs/Access/PermissionRoles.php +++ b/Zotlabs/Access/PermissionRoles.php @@ -8,7 +8,7 @@ use Zotlabs\Lib as Zlib; class PermissionRoles { static public function version() { - return 1; + return 2; } static function role_perms($role) { @@ -25,7 +25,7 @@ class PermissionRoles { $ret['online'] = true; $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', + 'view_pages', 'view_wiki', 'send_stream', 'post_wall', 'post_comments', 'post_mail', 'chat', 'post_like', 'republish' ]; $ret['limits'] = PermissionLimits::Std_Limits(); @@ -38,7 +38,7 @@ class PermissionRoles { $ret['online'] = true; $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', + 'view_pages', 'view_wiki', 'send_stream', 'post_wall', 'post_comments', 'post_mail', 'chat', 'post_like' ]; $ret['limits'] = PermissionLimits::Std_Limits(); @@ -52,7 +52,7 @@ class PermissionRoles { $ret['online'] = false; $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', + 'view_pages', 'view_wiki', 'send_stream', 'post_wall', 'post_comments', 'post_mail', 'post_like' ]; $ret['limits'] = PermissionLimits::Std_Limits(); $ret['limits']['view_contacts'] = PERMS_SPECIFIC; @@ -67,7 +67,7 @@ class PermissionRoles { $ret['online'] = false; $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'post_wall', 'post_comments', 'tag_deliver', + 'view_pages', 'view_wiki', 'post_wall', 'post_comments', 'tag_deliver', 'post_mail', 'post_like' , 'republish', 'chat' ]; $ret['limits'] = PermissionLimits::Std_Limits(); @@ -80,7 +80,7 @@ class PermissionRoles { $ret['online'] = false; $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'post_wall', 'post_comments', 'tag_deliver', + 'view_pages', 'view_wiki', 'post_wall', 'post_comments', 'tag_deliver', 'post_mail', 'post_like' , 'chat' ]; $ret['limits'] = PermissionLimits::Std_Limits(); @@ -95,7 +95,7 @@ class PermissionRoles { $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'post_wall', 'post_comments', + 'view_pages', 'view_wiki', 'post_wall', 'post_comments', 'post_mail', 'post_like' , 'chat' ]; $ret['limits'] = PermissionLimits::Std_Limits(); @@ -103,6 +103,7 @@ class PermissionRoles { $ret['limits']['view_contacts'] = PERMS_SPECIFIC; $ret['limits']['view_storage'] = PERMS_SPECIFIC; $ret['limits']['view_pages'] = PERMS_SPECIFIC; + $ret['limits']['view_wiki'] = PERMS_SPECIFIC; break; @@ -114,7 +115,7 @@ class PermissionRoles { $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', + 'view_pages', 'view_wiki', 'send_stream', 'post_wall', 'post_comments', 'post_mail', 'post_like' , 'republish' ]; $ret['limits'] = PermissionLimits::Std_Limits(); @@ -128,7 +129,7 @@ class PermissionRoles { $ret['online'] = false; $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'send_stream', 'post_wall', 'post_comments', + 'view_pages', 'view_wiki', 'send_stream', 'post_wall', 'post_comments', 'post_mail', 'post_like' , 'republish' ]; $ret['limits'] = PermissionLimits::Std_Limits(); @@ -143,7 +144,7 @@ class PermissionRoles { $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'post_like' , 'republish' ]; + 'view_pages', 'view_wiki', 'post_like' , 'republish' ]; $ret['limits'] = PermissionLimits::Std_Limits(); @@ -157,8 +158,8 @@ class PermissionRoles { $ret['perms_connect'] = [ 'view_stream', 'view_profile', 'view_contacts', 'view_storage', - 'view_pages', 'write_storage', 'write_pages', 'post_wall', 'post_comments', 'tag_deliver', - 'post_mail', 'post_like' , 'republish', 'chat' ]; + 'view_pages', 'view_wiki', 'write_storage', 'write_pages', 'post_wall', 'post_comments', 'tag_deliver', + 'post_mail', 'post_like' , 'republish', 'chat', 'write_wiki' ]; $ret['limits'] = PermissionLimits::Std_Limits(); break; @@ -185,6 +186,12 @@ class PermissionRoles { // if($perm === 'mynewperm') // \Zotlabs\Access\PermissionLimits::Set($uid,$perm,1); + if($perm === 'view_wiki') + \Zotlabs\Access\PermissionLimits::Set($uid,$perm,PERMS_PUBLIC); + + if($perm === 'write_wiki') + \Zotlabs\Access\PermissionLimits::Set($uid,$perm,PERMS_SPECIFIC); + // set autoperms here if applicable // choices are to set to 0, 1, or the value of an existing perm @@ -195,7 +202,13 @@ class PermissionRoles { $value = 0; // if($perm === 'mynewperm') - // $value = get_abconfig($uid,$c['channel_hash'],'autoperms','someexistingperm')); + // $value = get_abconfig($uid,$c['channel_hash'],'autoperms','someexistingperm'); + + if($perm === 'view_wiki') + $value = get_abconfig($uid,$c['channel_hash'],'autoperms','view_pages'); + + if($perm === 'write_wiki') + $value = get_abconfig($uid,$c['channel_hash'],'autoperms','write_pages'); if($c) { set_abconfig($uid,$c['channel_hash'],'autoperms',$perm,$value); @@ -212,8 +225,16 @@ class PermissionRoles { // case 'mynewperm': // choices are to set to 1, set to 0, or clone an existing perm // set_abconfig($uid,$ab['abook_xchan'],'my_perms',$perm, - // get_abconfig($uid,$ab['abook_xchan'],'my_perms','someexistingperm')); - + // intval(get_abconfig($uid,$ab['abook_xchan'],'my_perms','someexistingperm'))); + + case 'view_wiki': + set_abconfig($uid,$ab['abook_xchan'],'my_perms',$perm, + intval(get_abconfig($uid,$ab['abook_xchan'],'my_perms','view_pages'))); + + case 'write_wiki': + set_abconfig($uid,$ab['abook_xchan'],'my_perms',$perm, + intval(get_abconfig($uid,$ab['abook_xchan'],'my_perms','write_pages'))); + default: break; } @@ -255,6 +276,4 @@ class PermissionRoles { return $roles; } - - }
\ No newline at end of file diff --git a/Zotlabs/Access/Permissions.php b/Zotlabs/Access/Permissions.php index 43baa6cf7..d51e4d0ea 100644 --- a/Zotlabs/Access/Permissions.php +++ b/Zotlabs/Access/Permissions.php @@ -18,7 +18,7 @@ class Permissions { * permission roles. You will want to set a default PermissionLimit for each channel and also * provide a sane default for any existing connections. You may or may not wish to provide a * default auto permission. If in doubt, leave this alone as custom permissions by definition - * are the responsbility of the channel owner to manage. You just don't want to create any + * are the responsibility of the channel owner to manage. You just don't want to create any * suprises or break things so you have an opportunity to provide sane settings. * * Update the version here and in PermissionRoles @@ -36,7 +36,7 @@ class Permissions { static public function version() { // This must match the version in PermissionRoles.php before permission updates can run. - return 1; + return 2; } @@ -50,7 +50,9 @@ class Permissions { 'view_storage' => t('Can view my file storage and photos'), 'write_storage' => t('Can upload/modify my file storage and photos'), 'view_pages' => t('Can view my channel webpages'), + 'view_wiki' => t('Can view my wiki pages'), 'write_pages' => t('Can create/edit my channel webpages'), + 'write_wiki' => t('Can write to my wiki pages'), 'post_wall' => t('Can post on my channel (wall) page'), 'post_comments' => t('Can comment on or like my posts'), 'post_mail' => t('Can send me private mail messages'), @@ -92,6 +94,10 @@ class Permissions { // Undeclared permissions are set to 0 static public function FilledPerms($arr) { + if(is_null($arr)) { + btlogger('FilledPerms: null'); + } + $everything = self::Perms(); $ret = []; foreach($everything as $k => $v) { @@ -104,6 +110,17 @@ class Permissions { } + static public function OPerms($arr) { + $ret = []; + if($arr) { + foreach($arr as $k => $v) { + $ret[] = [ 'name' => $k, 'value' => $v ]; + } + } + return $ret; + } + + static public function FilledAutoperms($channel_id) { if(! intval(get_pconfig($channel_id,'system','autoperms'))) return false; @@ -114,7 +131,7 @@ class Permissions { ); if($r) { foreach($r as $rr) { - $arr[$rr['k']] = $arr[$rr['v']]; + $arr[$rr['k']] = intval($rr['v']); } } return $arr; @@ -129,4 +146,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 |