From 42d000145fc2e6ca5373e6316da5cbd6982275ab Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 2 Nov 2020 12:55:38 +0100 Subject: [PATCH] enable unshare action also when shared-with column is shown and fix some bugs arround unsharing and resharing --- addressbook/inc/class.addressbook_ui.inc.php | 13 ++++++++++--- api/src/Contacts/Sql.php | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 4fda5a8c89..f864b84d68 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -356,7 +356,7 @@ class addressbook_ui extends addressbook_bo /** * Get actions / context menu items * - * @param string $tid_filter =null + * @param ?string $tid_filter =null * @return array see Etemplate\Widget\Nextmatch::get_actions() */ public function get_actions($tid_filter=null) @@ -1495,7 +1495,8 @@ class addressbook_ui extends addressbook_bo foreach($contact['shared'] as $key => $shared) { // only unshare contacts shared by current user - if ($shared['shared_by'] == $this->user && + if (($shared['shared_by'] == $this->user || + $this->check_perms(ACL::EDIT, $contact)) && // only unshare from given addressbook, or all (empty($query['filter']) || $shared['shared_with'] == (int)$query['filter'])) { @@ -1967,6 +1968,11 @@ class addressbook_ui extends addressbook_bo } $order = $query['order']; + $unshare_grants = []; + foreach($this->grants as $grantee => $rights) + { + if ($rights & (ACL::EDIT|self::ACL_SHARED)) $unshare_grants[] = $grantee; + } $readonlys = array(); foreach($rows as $n => &$row) { @@ -2076,7 +2082,8 @@ class addressbook_ui extends addressbook_bo $row['cat_id'] = $this->categories->check_list(Acl::READ,$row['cat_id']); } - if ($query['col_filter']['shared_by'] == $this->user) + if ($query['col_filter']['shared_by'] == $this->user || !empty($row['shared_with']) && + array_intersect($unshare_grants, explode(',', $row['shared_with']))) { $row['class'] .= 'unshare_contact '; } diff --git a/api/src/Contacts/Sql.php b/api/src/Contacts/Sql.php index 04f7ae2d03..adb481e329 100644 --- a/api/src/Contacts/Sql.php +++ b/api/src/Contacts/Sql.php @@ -672,7 +672,7 @@ class Sql extends Api\Storage if (($key = array_search('shared_with', $extra_cols)) !== false) { $extra_cols[$key] = '(SELECT '.$this->db->group_concat('DISTINCT shared_with').' FROM '.self::SHARED_TABLE. - ' WHERE '.self::SHARED_TABLE.'.contact_id='.$this->table_name.'.contact_id) AS shared_with'; + ' WHERE '.self::SHARED_TABLE.'.contact_id='.$this->table_name.'.contact_id AND shared_deleted IS NULL) AS shared_with'; } if (!empty($filter['shared_with'])) { @@ -1114,8 +1114,9 @@ class Sql extends Api\Storage } } $this->db->insert(self::SHARED_TABLE, $data, - array_intersect_key($data, array_flip(['shared_by','shared_with','contact_id','share_id'])), __LINE__, __FILE__); - $data['shared_id'] = $this->db->get_last_insert_id(self::SHARED_TABLE, 'share_id'); + $where = array_intersect_key($data, array_flip(['shared_by','shared_with','contact_id','share_id'])), __LINE__, __FILE__); + // if we resurect a previous deleted share, we dont get the shared_id back, need to query it + $data['shared_id'] = $this->db->select(self::SHARED_TABLE, 'shared_id', $where, __LINE__, __FILE__)->fetchColumn(); } $ids[] = (int)$data['shared_id']; }