From 3f1a4b655900d64ad2c13f1906eb77eaf15d11b5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 6 Nov 2017 20:13:14 -0800 Subject: second half of issue #893 - move channel default permissions to its own module so we can apply different page/widget layouts than for connedit; the relevant functionality is abandoned on mod_connedit but still intact. Trying a slightly different look/behaviour for inherited settings and the associated checkboxes. This may need a bit more tweaking but overall looks a lot cleaner. --- Zotlabs/Module/Defperms.php | 267 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 Zotlabs/Module/Defperms.php (limited to 'Zotlabs/Module/Defperms.php') diff --git a/Zotlabs/Module/Defperms.php b/Zotlabs/Module/Defperms.php new file mode 100644 index 000000000..4e7ddb55a --- /dev/null +++ b/Zotlabs/Module/Defperms.php @@ -0,0 +1,267 @@ + $desc) { + + $checkinherited = \Zotlabs\Access\PermissionLimits::Get(local_channel(),$perm); + $inherited = (($checkinherited & PERMS_SPECIFIC) ? false : true); + + if(array_key_exists('perms_' . $perm, $_POST)) { + set_abconfig($channel['channel_id'],$orig_record[0]['abook_xchan'],'my_perms',$perm, + intval($_POST['perms_' . $perm])); + 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); + + + notice( t('Settings updated.') . EOL); + + + // Refresh the structure in memory with the new data + + $r = q("SELECT abook.*, xchan.* + FROM abook left join xchan on abook_xchan = xchan_hash + WHERE abook_channel = %d and abook_id = %d LIMIT 1", + intval(local_channel()), + intval($contact_id) + ); + if($r) { + \App::$poi = $r[0]; + } + + + $this->defperms_clone($a); + + goaway(z_root() . '/defperms'); + + return; + + } + + /* @brief Clone connection + * + * + */ + + function defperms_clone(&$a) { + + if(! \App::$poi) + return; + + $channel = \App::get_channel(); + + $r = q("SELECT abook.*, xchan.* + FROM abook left join xchan on abook_xchan = xchan_hash + WHERE abook_channel = %d and abook_id = %d LIMIT 1", + intval(local_channel()), + intval(\App::$poi['abook_id']) + ); + if($r) { + \App::$poi = array_shift($r); + } + + $clone = \App::$poi; + + unset($clone['abook_id']); + unset($clone['abook_account']); + unset($clone['abook_channel']); + + $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']); + if($abconfig) + $clone['abconfig'] = $abconfig; + + build_sync_packet(0 /* use the current local_channel */, array('abook' => array($clone))); + } + + /* @brief Generate content of connection edit page + * + * + */ + + function get() { + + $sort_type = 0; + $o = ''; + + if(! local_channel()) { + notice( t('Permission denied.') . EOL); + return login(); + } + + $section = ((array_key_exists('section',$_REQUEST)) ? $_REQUEST['section'] : ''); + $channel = \App::get_channel(); + + $yes_no = array(t('No'),t('Yes')); + + $connect_perms = \Zotlabs\Access\Permissions::connect_perms(local_channel()); + + $o .= "\n"; + + if(\App::$poi) { + + $sections = []; + + $self = false; + + $tpl = get_markup_template('defperms.tpl'); + + + $perms = array(); + $channel = \App::get_channel(); + + $contact = \App::$poi; + + $global_perms = \Zotlabs\Access\Permissions::Perms(); + + $existing = get_all_perms(local_channel(),$contact['abook_xchan']); + $hidden_perms = []; + + foreach($global_perms as $k => $v) { + $thisperm = get_abconfig(local_channel(),$contact['abook_xchan'],'my_perms',$k); + + $checkinherited = \Zotlabs\Access\PermissionLimits::Get(local_channel(),$k); + + $inherited = (($checkinherited & PERMS_SPECIFIC) ? false : true); + + $perms[] = [ 'perms_' . $k, $v, intval($thisperm), '', $yes_no, (($inherited) ? ' disabled="disabled" ' : '') ]; + if($inherited) { + $hidden_perms[] = [ 'perms_' . $k, intval($thisperm) ]; + } + } + + $pcat = new \Zotlabs\Lib\Permcat(local_channel()); + $pcatlist = $pcat->listing(); + $permcats = []; + if($pcatlist) { + foreach($pcatlist as $pc) { + $permcats[$pc['name']] = $pc['localname']; + } + } + + $o .= replace_macros($tpl, [ + '$header' => t('Connection Default Permissions'), + '$autoperms' => 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'), + '$section' => $section, + '$sections' => $sections, + '$autolbl' => t('The permissions indicated on this page will be applied to all new connections.'), + '$autoapprove' => t('Automatic approval settings'), + '$unapproved' => $unapproved, + '$inherited' => t('inherited'), + '$submit' => t('Submit'), + '$me' => t('My Settings'), + '$perms' => $perms, + '$hidden_perms' => $hidden_perms, + '$permlbl' => t('Individual Permissions'), + '$permnote_self' => t('Some individual permissions may have been preset or locked based on your channel type and privacy settings.'), + '$contact_id' => $contact['abook_id'], + '$name' => $contact['xchan_name'], + ]); + + $arr = array('contact' => $contact,'output' => $o); + + call_hooks('contact_edit', $arr); + + return $arr['output']; + + } + } +} -- cgit v1.2.3