From a7948d7bfee1c0c8c9f1a731aabdc636c280bff0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 26 Sep 2018 22:02:50 +0200 Subject: permcats app --- Zotlabs/Module/Connedit.php | 3 +- Zotlabs/Module/Defperms.php | 3 +- Zotlabs/Module/Permcats.php | 135 +++++++++++++++++++++++++++++++++++ Zotlabs/Module/Settings/Permcats.php | 120 ------------------------------- Zotlabs/Widget/Settings_menu.php | 8 --- 5 files changed, 139 insertions(+), 130 deletions(-) create mode 100644 Zotlabs/Module/Permcats.php delete mode 100644 Zotlabs/Module/Settings/Permcats.php (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php index 712215bc3..3d7ee449a 100644 --- a/Zotlabs/Module/Connedit.php +++ b/Zotlabs/Module/Connedit.php @@ -7,6 +7,7 @@ namespace Zotlabs\Module; * */ +use Zotlabs\Lib\Apps; require_once('include/socgraph.php'); require_once('include/selectors.php'); @@ -851,7 +852,7 @@ class Connedit extends \Zotlabs\Web\Controller { '$autoperms' => array('autoperms',t('Apply these permissions automatically'), ((get_pconfig(local_channel(),'system','autoperms')) ? 1 : 0), t('Connection requests will be approved without your interaction'), $yes_no), '$permcat' => [ 'permcat', t('Permission role'), '', '',$permcats ], '$permcat_new' => t('Add permission role'), - '$permcat_enable' => feature_enabled(local_channel(),'permcats'), + '$permcat_enable' => Apps::system_app_installed(local_channel(), 'Permission Categories'), '$addr' => unpunify($contact['xchan_addr']), '$primeurl' => unpunify($contact['xchan_url']), '$section' => $section, diff --git a/Zotlabs/Module/Defperms.php b/Zotlabs/Module/Defperms.php index 63acc9795..2e886aa64 100644 --- a/Zotlabs/Module/Defperms.php +++ b/Zotlabs/Module/Defperms.php @@ -1,6 +1,7 @@ array('autoperms',t('Apply these permissions automatically'), ((get_pconfig(local_channel(),'system','autoperms')) ? 1 : 0), t('If enabled, connection requests will be approved without your interaction'), $yes_no), '$permcat' => [ 'permcat', t('Permission role'), '', '',$permcats ], '$permcat_new' => t('Add permission role'), - '$permcat_enable' => feature_enabled(local_channel(),'permcats'), + '$permcat_enable' => Apps::system_app_installed(local_channel(), 'Permission Categories'), '$section' => $section, '$sections' => $sections, '$autolbl' => t('The permissions indicated on this page will be applied to all new connections.'), diff --git a/Zotlabs/Module/Permcats.php b/Zotlabs/Module/Permcats.php new file mode 100644 index 000000000..97090067b --- /dev/null +++ b/Zotlabs/Module/Permcats.php @@ -0,0 +1,135 @@ + $desc) { + if(array_key_exists('perms_' . $perm, $_POST)) { + $pcarr[] = $perm; + } + } + } + + \Zotlabs\Lib\Permcat::update(local_channel(),$name,$pcarr); + + build_sync_packet(); + + info( t('Permission category saved.') . EOL); + + return; + } + + + function get() { + + if(! local_channel()) + return; + + if(! Apps::system_app_installed(local_channel(), 'Permission Categories')) { + //Do not display any associated widgets at this point + App::$pdl = ''; + + $o = 'Permission Categories App (Not Installed):
'; + $o .= t('Create custom connection permission limits'); + return $o; + } + + $channel = App::get_channel(); + + + if(argc() > 1) + $name = hex2bin(argv(1)); + + if(argc() > 2 && argv(2) === 'drop') { + \Zotlabs\Lib\Permcat::delete(local_channel(),$name); + build_sync_packet(); + json_return_and_die([ 'success' => true ]); + } + + + $desc = t('Use this form to create permission rules for various classes of people or connections.'); + + $existing = []; + + $pcat = new \Zotlabs\Lib\Permcat(local_channel()); + $pcatlist = $pcat->listing(); + $permcats = []; + if($pcatlist) { + foreach($pcatlist as $pc) { + if(($pc['name']) && ($name) && ($pc['name'] == $name)) + $existing = $pc['perms']; + if(! $pc['system']) + $permcats[bin2hex($pc['name'])] = $pc['localname']; + } + } + + $global_perms = \Zotlabs\Access\Permissions::Perms(); + + foreach($global_perms as $k => $v) { + $thisperm = \Zotlabs\Lib\Permcat::find_permcat($existing,$k); + $checkinherited = \Zotlabs\Access\PermissionLimits::Get(local_channel(),$k); + + if($existing[$k]) + $thisperm = "1"; + + $perms[] = array('perms_' . $k, $v, '',$thisperm, 1, (($checkinherited & PERMS_SPECIFIC) ? '' : '1'), '', $checkinherited); + } + + + + $tpl = get_markup_template("permcats.tpl"); + $o .= replace_macros($tpl, array( + '$form_security_token' => get_form_security_token("permcats"), + '$title' => t('Permission Categories'), + '$desc' => $desc, + '$desc2' => $desc2, + '$tokens' => $t, + '$permcats' => $permcats, + '$atoken' => $atoken, + '$url1' => z_root() . '/channel/' . $channel['channel_address'], + '$url2' => z_root() . '/photos/' . $channel['channel_address'], + '$name' => array('name', t('Permission Name') . ' *', (($name) ? $name : ''), ''), + '$me' => t('My Settings'), + '$perms' => $perms, + '$inherited' => t('inherited'), + '$notself' => 0, + '$self' => 1, + '$permlbl' => t('Individual Permissions'), + '$permnote' => t('Some permissions may be inherited from your channel\'s privacy settings, which have higher priority than individual settings. You can not change those settings here.'), + '$submit' => t('Submit') + )); + return $o; + } + +} diff --git a/Zotlabs/Module/Settings/Permcats.php b/Zotlabs/Module/Settings/Permcats.php deleted file mode 100644 index 40641c3f2..000000000 --- a/Zotlabs/Module/Settings/Permcats.php +++ /dev/null @@ -1,120 +0,0 @@ - $desc) { - if(array_key_exists('perms_' . $perm, $_POST)) { - $pcarr[] = $perm; - } - } - } - - \Zotlabs\Lib\Permcat::update(local_channel(),$name,$pcarr); - - build_sync_packet(); - - info( t('Permission category saved.') . EOL); - - return; - } - - - function get() { - - if(! local_channel()) - return; - - $channel = \App::get_channel(); - - - if(argc() > 2) - $name = hex2bin(argv(2)); - - if(argc() > 3 && argv(3) === 'drop') { - \Zotlabs\Lib\Permcat::delete(local_channel(),$name); - build_sync_packet(); - json_return_and_die([ 'success' => true ]); - } - - - $desc = t('Use this form to create permission rules for various classes of people or connections.'); - - $existing = []; - - $pcat = new \Zotlabs\Lib\Permcat(local_channel()); - $pcatlist = $pcat->listing(); - $permcats = []; - if($pcatlist) { - foreach($pcatlist as $pc) { - if(($pc['name']) && ($name) && ($pc['name'] == $name)) - $existing = $pc['perms']; - if(! $pc['system']) - $permcats[bin2hex($pc['name'])] = $pc['localname']; - } - } - - $global_perms = \Zotlabs\Access\Permissions::Perms(); - - foreach($global_perms as $k => $v) { - $thisperm = \Zotlabs\Lib\Permcat::find_permcat($existing,$k); - $checkinherited = \Zotlabs\Access\PermissionLimits::Get(local_channel(),$k); - - if($existing[$k]) - $thisperm = "1"; - - $perms[] = array('perms_' . $k, $v, '',$thisperm, 1, (($checkinherited & PERMS_SPECIFIC) ? '' : '1'), '', $checkinherited); - } - - - - $tpl = get_markup_template("settings_permcats.tpl"); - $o .= replace_macros($tpl, array( - '$form_security_token' => get_form_security_token("settings_permcats"), - '$title' => t('Permission Categories'), - '$desc' => $desc, - '$desc2' => $desc2, - '$tokens' => $t, - '$permcats' => $permcats, - '$atoken' => $atoken, - '$url1' => z_root() . '/channel/' . $channel['channel_address'], - '$url2' => z_root() . '/photos/' . $channel['channel_address'], - '$name' => array('name', t('Permission Name') . ' *', (($name) ? $name : ''), ''), - '$me' => t('My Settings'), - '$perms' => $perms, - '$inherited' => t('inherited'), - '$notself' => 0, - '$self' => 1, - '$permlbl' => t('Individual Permissions'), - '$permnote' => t('Some permissions may be inherited from your channel\'s privacy settings, which have higher priority than individual settings. You can not change those settings here.'), - '$submit' => t('Submit') - )); - return $o; - } - -} diff --git a/Zotlabs/Widget/Settings_menu.php b/Zotlabs/Widget/Settings_menu.php index 041ca312f..781f3b145 100644 --- a/Zotlabs/Widget/Settings_menu.php +++ b/Zotlabs/Widget/Settings_menu.php @@ -87,14 +87,6 @@ class Settings_menu { ); } - if(feature_enabled(local_channel(),'permcats')) { - $tabs[] = array( - 'label' => t('Permission Categories'), - 'url' => z_root() . '/settings/permcats', - 'selected' => ((argv(1) === 'permcats') ? 'active' : ''), - ); - } - if($role === false || $role === 'custom') { $tabs[] = array( 'label' => t('Connection Default Permissions'), -- cgit v1.2.3