From c50bfa07ca3a456d69d73988f42e58e3282879e9 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 3 Aug 2016 21:16:57 +0200 Subject: multiple acl work --- Zotlabs/Module/Channel.php | 3 +- Zotlabs/Module/Filestorage.php | 7 +++- Zotlabs/Module/Network.php | 1 + include/conversation.php | 6 +++ include/text.php | 6 +++ view/js/acl.js | 86 ++++++++++++++++++++++++++++------------- view/tpl/acl_selector.tpl | 6 +-- view/tpl/attach_edit.tpl | 8 ++-- view/tpl/chatroom_new.tpl | 6 +-- view/tpl/cloud_actionspanel.tpl | 1 + view/tpl/jot.tpl | 9 +++-- 11 files changed, 96 insertions(+), 43 deletions(-) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index c74802ec5..59cb9f06c 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -133,6 +133,7 @@ class Channel extends \Zotlabs\Web\Controller { 'nickname' => \App::$profile['channel_address'], 'lockstate' => (((strlen(\App::$profile['channel_allow_cid'])) || (strlen(\App::$profile['channel_allow_gid'])) || (strlen(\App::$profile['channel_deny_cid'])) || (strlen(\App::$profile['channel_deny_gid']))) ? 'lock' : 'unlock'), 'acl' => (($is_owner) ? populate_acl($channel_acl,true, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post') : ''), + 'permissions' => (($is_owner) ? $channel_acl : ''), 'showacl' => (($is_owner) ? 'yes' : ''), 'bang' => '', 'visitor' => (($is_owner || $observer) ? true : false), @@ -363,4 +364,4 @@ class Channel extends \Zotlabs\Web\Controller { return $o; } -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Filestorage.php b/Zotlabs/Module/Filestorage.php index c3ef22e32..c8ad147bb 100644 --- a/Zotlabs/Module/Filestorage.php +++ b/Zotlabs/Module/Filestorage.php @@ -161,7 +161,12 @@ class Filestorage extends \Zotlabs\Web\Controller { '$submit' => t('Submit'), '$attach_btn_title' => t('Share this file'), '$link_btn_title' => t('Show URL to this file'), - '$notify' => array('notify', t('Notify your contacts about this file'), 0, '', array(t('No'), t('Yes'))) + '$notify' => array('notify', t('Notify your contacts about this file'), 0, '', array(t('No'), t('Yes'))), + + '$allow_cid' => json_encode(expand_acl($f['allow_cid'])), + '$allow_gid' => json_encode(expand_acl($f['allow_gid'])), + '$deny_cid' => json_encode(expand_acl($f['deny_cid'])), + '$deny_cid' => json_encode(expand_acl($f['deny_gid'])) )); echo $o; diff --git a/Zotlabs/Module/Network.php b/Zotlabs/Module/Network.php index 3b88cd8d6..0128adc2c 100644 --- a/Zotlabs/Module/Network.php +++ b/Zotlabs/Module/Network.php @@ -170,6 +170,7 @@ class Network extends \Zotlabs\Web\Controller { 'nickname' => $channel['channel_address'], 'lockstate' => (($private_editing || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), 'acl' => populate_acl((($private_editing) ? $def_acl : $channel_acl), true, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post'), + 'permissions' => (($private_editing) ? $def_acl : $channel_acl), 'bang' => (($private_editing) ? '!' : ''), 'visitor' => true, 'profile_uid' => local_channel(), diff --git a/include/conversation.php b/include/conversation.php index 1efca37f3..f68d538dc 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1213,6 +1213,8 @@ function status_editor($a, $x, $popup = false) { call_hooks('jot_tool', $jotplugins); + //print_r(acl2json($x['permissions']['allow_gid'])); killme(); + $o .= replace_macros($tpl, array( '$return_path' => ((x($x, 'return_path')) ? $x['return_path'] : App::$query_string), '$action' => z_root() . '/item', @@ -1253,6 +1255,10 @@ function status_editor($a, $x, $popup = false) { '$visitor' => $x['visitor'], '$lockstate' => $x['lockstate'], '$acl' => $x['acl'], + '$allow_cid' => acl2json($x['permissions']['allow_cid']), + '$allow_gid' => acl2json($x['permissions']['allow_gid']), + '$deny_cid' => acl2json($x['permissions']['deny_cid']), + '$deny_gid' => acl2json($x['permissions']['deny_gid']), '$mimeselect' => $mimeselect, '$layoutselect' => $layoutselect, '$showacl' => ((array_key_exists('showacl', $x)) ? $x['showacl'] : true), diff --git a/include/text.php b/include/text.php index 1eec2ba0a..6d7d0ed8d 100644 --- a/include/text.php +++ b/include/text.php @@ -2796,6 +2796,12 @@ function expand_acl($s) { return $ret; } +function acl2json($s) { + $s = expand_acl($s); + $s = json_encode($s); + return $s; +} + // When editing a webpage - a dropdown is needed to select a page layout // On submit, the pdl_select value (which is the mid of an item with item_type = ITEM_TYPE_PDL) is stored in diff --git a/view/js/acl.js b/view/js/acl.js index 79699c589..33895d260 100644 --- a/view/js/acl.js +++ b/view/js/acl.js @@ -1,15 +1,17 @@ -function ACL(backend_url, preset) { +function ACL(backend_url) { that = this; that.url = backend_url; that.kp_timer = null; - if (preset === undefined) preset = []; - that.allow_cid = (preset[0] || []); - that.allow_gid = (preset[1] || []); - that.deny_cid = (preset[2] || []); - that.deny_gid = (preset[3] || []); + that.self = []; + + that.allow_cid = []; + that.allow_gid = []; + that.deny_cid = []; + that.deny_gid = []; + that.group_uids = []; that.info = $("#acl-info"); @@ -21,11 +23,8 @@ function ACL(backend_url, preset) { that.showlimited = $("#acl-showlimited"); that.acl_select = $("#acl-select"); - that.preset = preset; - that.self = []; - // set the initial ACL lists in case the enclosing form gets submitted before the ajax loader completes. - that.on_submit(); + //that.on_submit(); /*events*/ @@ -47,32 +46,59 @@ function ACL(backend_url, preset) { } }); + + //$(document).on('click', '.acl-submit', that.get_form_id_and_submit); + //$(document).on('click', '.acl-select', that.get_form_id_and_submit); + + $(document).on('focus', '.acl-form', that.get_form_data); + $(document).on('click', '.acl-form', that.get_form_data); + $(document).on('click','.acl-button-show',that.on_button_show); $(document).on('click','.acl-button-hide',that.on_button_hide); + $(document).on('click','.acl-button-hide',that.on_button_hide); + $("#acl-search").keypress(that.on_search); /* startup! */ that.get(0,15000); - that.on_submit(); + //that.on_submit(); }); } // no longer called only on submit - call to update whenever a change occurs to the acl list. +ACL.prototype.get_form_data = function(event) { +//event.preventDefault() + + that.form_id = $(this).data('formid'); + + console.log(event); + + that.allow_cid = ($(this).data('allow_cid') || []); + that.allow_gid = ($(this).data('allow_gid') || []); + that.deny_cid = ($(this).data('deny_cid') || []); + that.deny_gid = ($(this).data('deny_gid') || []); + + that.update_view(); + that.on_submit(); +} ACL.prototype.on_submit = function() { - aclfields = $("#acl-fields").html(""); + + + //console.log(that.form_id); + $('.acl-field').remove(); $(that.allow_gid).each(function(i,v) { - aclfields.append(""); + $('#' + that.form_id).append(""); }); $(that.allow_cid).each(function(i,v) { - aclfields.append(""); + $('#' + that.form_id).append(""); }); $(that.deny_gid).each(function(i,v) { - aclfields.append(""); + $('#' + that.form_id).append(""); }); $(that.deny_cid).each(function(i,v) { - aclfields.append(""); + $('#' + that.form_id).append(""); }); //areYouSure jquery plugin: recheck the form here @@ -101,6 +127,7 @@ ACL.prototype.on_onlyme = function(event) { that.deny_cid = []; that.deny_gid = []; + that.update_view(event.target.value); that.on_submit(); @@ -126,14 +153,14 @@ ACL.prototype.on_showlimited = function(event) { // preventDefault() isn't called here as we want state changes from update_view() to be applied to the radiobutton event.stopPropagation(); - if(that.preset[0].length === 0 && that.preset[1].length === 0 && that.preset[2].length === 0 && that.preset[3].length === 0) { - that.preset[0] = [that.self[0]]; + if(that.allow_cid.length === 0 && that.allow_gid.length === 0 && that.deny_cid.length === 0 && that.deny_gid.length === 0) { + that.allow_cid = [that.self[0]]; } - that.allow_cid = (that.preset[0] || []); - that.allow_gid = (that.preset[1] || []); - that.deny_cid = (that.preset[2] || []); - that.deny_gid = (that.preset[3] || []); + that.allow_cid = (that.allow_cid || []); + that.allow_gid = (that.allow_gid || []); + that.deny_cid = (that.deny_cid || []); + that.deny_gid = (that.deny_gid || []); that.update_view(event.target.value); that.on_submit(); @@ -239,14 +266,21 @@ ACL.prototype.set_deny = function(itemid) { that.update_view(); }; -ACL.prototype.update_select = function(preset) { - that.showall.prop('selected', preset === 'public'); - that.onlyme.prop('selected', preset === 'onlyme'); - that.showlimited.prop('selected', preset === 'limited'); +ACL.prototype.update_select = function(set) { + that.showall.prop('selected', set === 'public'); + that.onlyme.prop('selected', set === 'onlyme'); + that.showlimited.prop('selected', set === 'limited'); }; ACL.prototype.update_view = function(value) { + console.log(that.form_id); + + console.log(that.allow_cid); + console.log(that.allow_gid); + console.log(that.deny_cid); + console.log(that.deny_gid); + if (that.allow_gid.length === 0 && that.allow_cid.length === 0 && that.deny_gid.length === 0 && that.deny_cid.length === 0) { that.list.hide(); //hide acl-list that.info.show(); //show acl-info diff --git a/view/tpl/acl_selector.tpl b/view/tpl/acl_selector.tpl index 60fae0a29..ddeb25a39 100755 --- a/view/tpl/acl_selector.tpl +++ b/view/tpl/acl_selector.tpl @@ -1,3 +1,4 @@ +
- +
diff --git a/view/tpl/attach_edit.tpl b/view/tpl/attach_edit.tpl index 965fb4819..1098049bf 100644 --- a/view/tpl/attach_edit.tpl +++ b/view/tpl/attach_edit.tpl @@ -1,4 +1,4 @@ -
+ @@ -16,15 +16,13 @@
- -
- {{$aclselect}} -
+{{$aclselect}} diff --git a/view/tpl/jot.tpl b/view/tpl/jot.tpl index 490349a04..a207989fb 100755 --- a/view/tpl/jot.tpl +++ b/view/tpl/jot.tpl @@ -1,4 +1,4 @@ -
+ {{$mimeselect}} {{$layoutselect}} {{if $id_select}} @@ -23,7 +23,6 @@ - {{if $showacl}}{{$acl}}{{/if}} {{if $webpage}}
@@ -166,11 +165,11 @@ {{/if}} {{if $showacl}} - {{/if}} - +
@@ -184,6 +183,8 @@ +{{if $showacl}}{{$acl}}{{/if}} + {{if $feature_expire}}