From 6698d7b03a88533eda8d79581b7e13565d36fa7e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 20 Mar 2015 17:37:01 +0100 Subject: possible improvement regarding deletion --- include/attach.php | 71 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 29 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 43b56e4f6..8ffb4bb96 100644 --- a/include/attach.php +++ b/include/attach.php @@ -827,7 +827,7 @@ function attach_delete($channel_id, $resource) { intval($channel_id) ); - file_activity($channel_id, $object, $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'update', $no_activity=false); + file_activity($channel_id, $object, $object['allow_cid'], $object['allow_gid'], $object['deny_cid'], $object['deny_gid'], 'update', $no_activity=false); } @@ -974,10 +974,14 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, if(!$object) return; - //filter out receivers which do not have permission to view filestorage + //turn strings into arrays $arr_allow_cid = expand_acl($allow_cid); + $arr_allow_gid = expand_acl($allow_gid); + $arr_deny_cid = expand_acl($deny_cid); + $arr_deny_gid = expand_acl($deny_gid); + + //filter out receivers which do not have permission to view filestorage $arr_allow_cid = check_list_permissions($channel_id, $arr_allow_cid, 'view_storage'); - $allow_cid = perms2str($arr_allow_cid); $is_dir = (($object['flags'] & ATTACH_FLAG_DIR) ? true : false); @@ -990,15 +994,16 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $folder_hash = $object['folder']; - $r_perms = recursive_activity_recipients($allow_cid, $allow_gid, $deny_cid, $deny_gid, $folder_hash); + $r_perms = recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash); - //filter out receivers which do not have permission to view filestorage - $r_perms['allow_cid'] = check_list_permissions($channel_id, $r_perms['allow_cid'], 'view_storage'); + //split up returned perms + $arr_allow_cid = $r_perms['allow_cid']; + $arr_allow_gid = $r_perms['allow_gid']; + $arr_deny_cid = $r_perms['deny_cid']; + $arr_deny_gid = $r_perms['deny_gid']; - $allow_cid = perms2str($r_perms['allow_cid']); - $allow_gid = perms2str($r_perms['allow_gid']); - $deny_cid = perms2str($r_perms['deny_cid']); - $deny_gid = perms2str($r_perms['deny_gid']); + //filter out receivers which do not have permission to view filestorage + $arr_allow_cid = check_list_permissions($channel_id, $arr_allow_cid, 'view_storage'); } @@ -1008,7 +1013,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $item_flags = ITEM_WALL|ITEM_ORIGIN; - $private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0); + $private = (($arr_allow_cid[0] || $arr_allow_gid[0] || $arr_deny_cid[0] || $arr_deny_gid[0]) ? 1 : 0); $jsonobject = json_encode($object); @@ -1037,6 +1042,17 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, if($update && $verb == 'post' ) { //send update activity and create a new one + //updates should be sent to everybody with recursive perms and all eventual former allowed members ($object['allow_cid'] etc.). + $o_arr_allow_cid = expand_acl($object['allow_cid']); + $o_arr_allow_gid = expand_acl($object['allow_gid']); + $o_arr_deny_cid = expand_acl($object['deny_cid']); + $o_arr_deny_gid = expand_acl($object['deny_gid']); + //merge arrays and remove duplicates + $arr_allow_cid = array_unique(array_merge($arr_allow_cid, $o_arr_allow_cid)); + $arr_allow_gid = array_unique(array_merge($arr_allow_gid, $o_arr_allow_gid)); + $arr_deny_cid = array_unique(array_merge($arr_deny_cid, $o_arr_deny_cid)); + $arr_deny_gid = array_unique(array_merge($arr_deny_gid, $o_arr_deny_gid)); + $u_mid = item_message_id(); $arr = array(); @@ -1050,11 +1066,10 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['author_xchan'] = $poster['xchan_hash']; $arr['owner_xchan'] = $poster['xchan_hash']; $arr['title'] = ''; - //updates should be visible to everybody -> perms may have changed - $arr['allow_cid'] = ''; - $arr['allow_gid'] = ''; - $arr['deny_cid'] = ''; - $arr['deny_gid'] = ''; + $arr['allow_cid'] = perms2str($arr_allow_cid); + $arr['allow_gid'] = perms2str($arr_allow_gid); + $arr['deny_cid'] = perms2str($arr_deny_cid); + $arr['deny_gid'] = perms2str($arr_deny_gid); $arr['item_restrict'] = ITEM_HIDDEN; $arr['item_private'] = 0; $arr['verb'] = ACTIVITY_UPDATE; @@ -1093,10 +1108,10 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['author_xchan'] = $poster['xchan_hash']; $arr['owner_xchan'] = $poster['xchan_hash']; $arr['title'] = ''; - $arr['allow_cid'] = $allow_cid; - $arr['allow_gid'] = $allow_gid; - $arr['deny_cid'] = $deny_cid; - $arr['deny_gid'] = $deny_gid; + $arr['allow_cid'] = perms2str($arr_allow_cid); + $arr['allow_gid'] = perms2str($arr_allow_gid); + $arr['deny_cid'] = perms2str($arr_deny_cid); + $arr['deny_gid'] = perms2str($arr_deny_gid); $arr['item_restrict'] = ITEM_HIDDEN; $arr['item_private'] = $private; $arr['verb'] = (($update) ? ACTIVITY_UPDATE : ACTIVITY_POST); @@ -1123,7 +1138,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, function get_file_activity_object($channel_id, $hash, $cloudpath) { - $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1", + $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited, allow_cid, allow_gid, deny_cid, deny_gid FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1", intval($channel_id), dbesc($hash) ); @@ -1152,28 +1167,26 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) { 'folder' => $x[0]['folder'], 'flags' => $x[0]['flags'], 'created' => $x[0]['created'], - 'edited' => $x[0]['edited'] + 'edited' => $x[0]['edited'], + 'allow_cid' => $x[0]['allow_cid'], + 'allow_gid' => $x[0]['allow_gid'], + 'deny_cid' => $x[0]['deny_cid'], + 'deny_gid' => $x[0]['deny_gid'] ); return $object; } -function recursive_activity_recipients($allow_cid, $allow_gid, $deny_cid, $deny_gid, $folder_hash) { +function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) { $poster = get_app()->get_observer(); - $arr_allow_cid = expand_acl($allow_cid); - $arr_allow_gid = expand_acl($allow_gid); - //turn allow_gid into allow_cid's foreach($arr_allow_gid as $gid) { $in_group = in_group($gid); $arr_allow_cid = array_unique(array_merge($arr_allow_cid, $in_group)); } - $arr_deny_cid = expand_acl($deny_cid); - $arr_deny_gid = expand_acl($deny_gid); - $count = 0; while($folder_hash) { $x = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid, folder FROM attach WHERE hash = '%s' LIMIT 1", -- cgit v1.2.3 From 264b43db05fe0a9a4ec4402eb43c7ecf501d4fee Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 20 Mar 2015 17:46:13 +0100 Subject: some cleanup --- include/attach.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 8ffb4bb96..7d0b99c05 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1043,15 +1043,10 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, //send update activity and create a new one //updates should be sent to everybody with recursive perms and all eventual former allowed members ($object['allow_cid'] etc.). - $o_arr_allow_cid = expand_acl($object['allow_cid']); - $o_arr_allow_gid = expand_acl($object['allow_gid']); - $o_arr_deny_cid = expand_acl($object['deny_cid']); - $o_arr_deny_gid = expand_acl($object['deny_gid']); - //merge arrays and remove duplicates - $arr_allow_cid = array_unique(array_merge($arr_allow_cid, $o_arr_allow_cid)); - $arr_allow_gid = array_unique(array_merge($arr_allow_gid, $o_arr_allow_gid)); - $arr_deny_cid = array_unique(array_merge($arr_deny_cid, $o_arr_deny_cid)); - $arr_deny_gid = array_unique(array_merge($arr_deny_gid, $o_arr_deny_gid)); + $u_arr_allow_cid = array_unique(array_merge($arr_allow_cid, expand_acl($object['allow_cid']))); + $u_arr_allow_gid = array_unique(array_merge($arr_allow_gid, expand_acl($object['allow_gid']))); + $u_arr_deny_cid = array_unique(array_merge($arr_deny_cid, expand_acl($object['deny_cid']))); + $u_arr_deny_gid = array_unique(array_merge($arr_deny_gid, expand_acl($object['deny_gid']))); $u_mid = item_message_id(); @@ -1066,10 +1061,10 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['author_xchan'] = $poster['xchan_hash']; $arr['owner_xchan'] = $poster['xchan_hash']; $arr['title'] = ''; - $arr['allow_cid'] = perms2str($arr_allow_cid); - $arr['allow_gid'] = perms2str($arr_allow_gid); - $arr['deny_cid'] = perms2str($arr_deny_cid); - $arr['deny_gid'] = perms2str($arr_deny_gid); + $arr['allow_cid'] = perms2str($u_arr_allow_cid); + $arr['allow_gid'] = perms2str($u_arr_allow_gid); + $arr['deny_cid'] = perms2str($u_arr_deny_cid); + $arr['deny_gid'] = perms2str($u_arr_deny_gid); $arr['item_restrict'] = ITEM_HIDDEN; $arr['item_private'] = 0; $arr['verb'] = ACTIVITY_UPDATE; -- cgit v1.2.3 From daed7fbeada3c781a6b5d7c8dd69d35733d93ef1 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 21 Mar 2015 19:12:43 +0100 Subject: Bugfix und variable initialization. Fixed a wrong perm_is_allowed() parameter, commented some other places where we use variables that are not set and should not work. --- include/attach.php | 61 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 23 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 7d0b99c05..04fd25ace 100644 --- a/include/attach.php +++ b/include/attach.php @@ -275,7 +275,11 @@ function attach_by_hash($hash, $rev = 0) { * * @see attach_by_hash() * @param $hash - * @param $ref + * @param $rev revision default 0 + * @return array Everything except data. + * * \e boolean \b success boolean true or false + * * \e string \b message (optional) only when success is false + * * \e array \b data array of attach DB entry without data component */ function attach_by_hash_nodata($hash, $rev = 0) { @@ -318,6 +322,7 @@ function attach_by_hash_nodata($hash, $rev = 0) { $ret['success'] = true; $ret['data'] = $r[0]; + return $ret; } @@ -361,6 +366,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $existing_size = 0; if($options === 'replace') { + /** @BUG $replace is undefined here */ $x = q("select id, hash, filesize from attach where id = %d and uid = %d limit 1", intval($replace), intval($channel_id) @@ -373,7 +379,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $existing_size = intval($x[0]['filesize']); $hash = $x[0]['hash']; } - + if($options === 'revise' || $options === 'update') { $sql_options = " order by revision desc "; if($options === 'update' && $arr && array_key_exists('revision',$arr)) @@ -513,22 +519,24 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { } /** - * Read a virtual directory and return contents, checking permissions of all parent components. - * @function z_readdir + * @brief Read a virtual directory and return contents. + * + * Also checking permissions of all parent components. + * * @param integer $channel_id * @param string $observer_hash hash of current observer * @param string $pathname * @param string $parent_hash (optional) * - * @returns array $ret - * $ret['success'] = boolean true or false - * $ret['message'] = error message if success is false - * $ret['data'] = array of attach DB entries without data component + * @return array $ret + * * \e boolean \b success boolean true or false + * * \e string \b message error message if success is false + * * \e array \b data array of attach DB entries without data component */ function z_readdir($channel_id, $observer_hash, $pathname, $parent_hash = '') { $ret = array('success' => false); - if(! perm_is_allowed($r[0]['uid'], get_observer_hash(), 'view_storage')) { + if(! perm_is_allowed($channel_id, get_observer_hash(), 'view_storage')) { $ret['message'] = t('Permission denied.'); return $ret; } @@ -833,12 +841,14 @@ function attach_delete($channel_id, $resource) { /** * @brief Returns path to file in cloud/. - * This function cannot be used with mod/dav as it always returns a path valid under mod/cloud + * + * @warning This function cannot be used with mod/dav as it always returns a + * path valid under mod/cloud. * - * @param array - * $arr[uid] int the channels uid - * $arr[folder] string - * $arr[filename]] string + * @param array assoziative array with: + * * \e int \b uid the channel's uid + * * \e string \b folder + * * \e string \b filename * @return string * path to the file in cloud/ */ @@ -895,6 +905,7 @@ function get_cloudpath($arr) { * @return string with the full folder path */ function get_parent_cloudpath($channel_id, $channel_name, $attachHash) { + $parentFullPath = ''; // build directory tree $parentHash = $attachHash; do { @@ -933,9 +944,9 @@ function find_folder_hash_by_attach_hash($channel_id, $attachHash) { /** * @brief Returns the filename of an attachment in a given channel. * - * @param mixed $channel_id + * @param int $channel_id * The id of the channel - * @param mixed $attachHash + * @param string $attachHash * The hash of the attachment * @return string * The filename of the attachment @@ -949,6 +960,7 @@ function find_filename_by_hash($channel_id, $attachHash) { if ($r) { $filename = $r[0]['filename']; } + return $filename; } @@ -1172,8 +1184,10 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) { } -function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) { +function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) { + $ret = array(); + $parent_arr = array(); $poster = get_app()->get_observer(); //turn allow_gid into allow_cid's @@ -1194,8 +1208,10 @@ function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_ $parent_arr['allow_cid'][] = expand_acl($x[0]['allow_cid']); $parent_arr['allow_gid'][] = expand_acl($x[0]['allow_gid']); - //TODO: should find a much better solution for the allow_cid <-> allow_gid problem. - //Do not use allow_gid for now. Instead lookup the members of the group directly and add them to allow_cid. + /** + * @TODO should find a much better solution for the allow_cid <-> allow_gid problem. + * Do not use allow_gid for now. Instead lookup the members of the group directly and add them to allow_cid. + * */ if($parent_arr['allow_gid']) { foreach($parent_arr['allow_gid'][$count] as $gid) { $in_group = in_group($gid); @@ -1207,11 +1223,9 @@ function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_ $parent_arr['deny_gid'][] = expand_acl($x[0]['deny_gid']); $count++; - } $folder_hash = $x[0]['folder']; - } //if none of the parent folders is private just return file perms @@ -1279,11 +1293,12 @@ function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_ } return $ret; - } function in_group($group_id) { - //TODO: make these two queries one with a join. + $group_members = array(); + + /** @TODO make these two queries one with a join. */ $x = q("SELECT id FROM groups WHERE hash = '%s'", dbesc($group_id) ); -- cgit v1.2.3 From 47c055e7f39ed4524dae6f0da2f0c64412f794d9 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 22 Mar 2015 14:24:07 +0100 Subject: do not override item_private here anymore --- include/attach.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 04fd25ace..1daa42aef 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1078,7 +1078,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['deny_cid'] = perms2str($u_arr_deny_cid); $arr['deny_gid'] = perms2str($u_arr_deny_gid); $arr['item_restrict'] = ITEM_HIDDEN; - $arr['item_private'] = 0; + $arr['item_private'] = $private; $arr['verb'] = ACTIVITY_UPDATE; $arr['obj_type'] = $objtype; $arr['object'] = $u_jsonobject; -- cgit v1.2.3