diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php index afbf1d5920..4f00ce1f9e 100644 --- a/apps/contacts/lib/addressbook.php +++ b/apps/contacts/lib/addressbook.php @@ -235,6 +235,7 @@ class OC_Contacts_Addressbook{ $uid = OCP\USER::getUser(); } $active = self::activeIds($uid); + $shared = OCP\Share::getItemsSharedWith('addressbook', OC_Contacts_Share::FORMAT_ADDRESSBOOKS); $addressbooks = array(); $ids_sql = join(',', array_fill(0, count($active), '?')); $prep = 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id IN ('.$ids_sql.') ORDER BY displayname'; @@ -249,7 +250,17 @@ class OC_Contacts_Addressbook{ } while( $row = $result->fetchRow()){ - $addressbooks[] = $row; + // Insert formatted shared addressbook instead + if ($row['userid'] != $uid) { + foreach ($shared as $addressbook) { + if ($addressbook['id'] == $row['id']) { + $addressbooks[] = $addressbook; + break; + } + } + } else { + $addressbooks[] = $row; + } } if(!count($addressbooks)) { self::addDefault($uid); diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php index ce66624c8f..3b16ffd5c1 100644 --- a/apps/contacts/lib/app.php +++ b/apps/contacts/lib/app.php @@ -24,16 +24,18 @@ class OC_Contacts_App { public static function getAddressbook($id) { $addressbook = OC_Contacts_Addressbook::find( $id ); - if( $addressbook === false || $addressbook['userid'] != OCP\USER::getUser() && !OCP\Share::getItemSharedWithBySource('addressbook', $id)) { - if ($addressbook === false) { - OCP\Util::writeLog('contacts', 'Addressbook not found: '. $id, OCP\Util::ERROR); - OCP\JSON::error(array('data' => array( 'message' => self::$l10n->t('Addressbook not found.')))); - } - else { + if ($addressbook === false) { + OCP\Util::writeLog('contacts', 'Addressbook not found: '. $id, OCP\Util::ERROR); + OCP\JSON::error(array('data' => array( 'message' => self::$l10n->t('Addressbook not found.')))); + exit(); + } else if ($addressbook['userid'] != OCP\USER::getUser()) { + if ($shared = OCP\Share::getItemSharedWithBySource('addressbook', $id)) { + $addressbook['displayname'] = $shared['item_target']; + } else { OCP\Util::writeLog('contacts', 'Addressbook('.$id.') is not from '.OCP\USER::getUser(), OCP\Util::ERROR); OCP\JSON::error(array('data' => array( 'message' => self::$l10n->t('This is not your addressbook.')))); + exit(); } - exit(); } return $addressbook; }