summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorcall-me-matt <nextcloud@matthiasheinisch.de>2020-09-06 00:48:04 +0200
committercall-me-matt <nextcloud@matthiasheinisch.de>2020-09-06 00:48:04 +0200
commitba67a50ecedc7dfa9eba36992726504c0e6d39bc (patch)
tree1c84dd93e0df8374a325ca348136d8c879043f8d /lib
parent33a53fc732e9f65bf37d162cc449ef80ab122303 (diff)
perform sanity checks
Signed-off-by: call-me-matt <nextcloud@matthiasheinisch.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Cron/SocialUpdate.php14
-rw-r--r--lib/Service/SocialApiService.php69
2 files changed, 62 insertions, 21 deletions
diff --git a/lib/Cron/SocialUpdate.php b/lib/Cron/SocialUpdate.php
index af9da459..46621e25 100644
--- a/lib/Cron/SocialUpdate.php
+++ b/lib/Cron/SocialUpdate.php
@@ -42,8 +42,8 @@ class SocialUpdate extends \OC\BackgroundJob\QueuedJob {
protected function run($arguments) {
$userId = $arguments['userId'];
- $offsetBook = $arguments['offsetBook'];
- $offsetContact = $arguments['offsetContact'];
+ $offsetBook = $arguments['offsetBook'] ?? null;
+ $offsetContact = $arguments['offsetContact'] ?? null;
// update contacts with first available social media profile
$result = $this->social->updateAddressbooks('any', $userId, $offsetBook, $offsetContact);
@@ -53,6 +53,16 @@ class SocialUpdate extends \OC\BackgroundJob\QueuedJob {
$report = $result->getData();
$stoppedAtBook = $report[0]['stoppedAt']['addressBook'];
$stoppedAtContact = $report[0]['stoppedAt']['contact'];
+
+ // make sure the offset contact/address book are still existing
+ if ($this->social->existsAddressBook($stoppedAtBook, $userId) == false) {
+ $stoppedAtBook = null;
+ }
+ if ($this->social->existsContact($stoppedAtContact, $stoppedAtBook, $userId) == false) {
+ $stoppedAtContact = null;
+ }
+ // TODO: can we check the userId still exists?
+
$this->jobList->add(self::class, [
'userId' => $userId,
'offsetBook' => $stoppedAtBook,
diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php
index 1791cdfe..290200c2 100644
--- a/lib/Service/SocialApiService.php
+++ b/lib/Service/SocialApiService.php
@@ -82,8 +82,6 @@ class SocialApiService {
/**
- * @NoAdminRequired
- *
* returns an array of supported social networks
*
* @returns {array} array of the supported social networks
@@ -98,8 +96,6 @@ class SocialApiService {
/**
- * @NoAdminRequired
- *
* Adds/updates photo for contact
*
* @param {pointer} contact reference to the contact to update
@@ -128,17 +124,19 @@ class SocialApiService {
/**
- * @NoAdminRequired
- *
* Gets the addressbook of an addressbookId
*
* @param {String} addressbookId the identifier of the addressbook
+ * @param {IManager} manager optional a ContactManager to use
*
* @returns {IAddressBook} the corresponding addressbook or null
*/
- protected function getAddressBook(string $addressbookId) : ?IAddressBook {
+ protected function getAddressBook(string $addressbookId, $manager=false) : ?IAddressBook {
$addressBook = null;
- $addressBooks = $this->manager->getUserAddressBooks();
+ if ($manager == false) {
+ $manager = $this->manager;
+ }
+ $addressBooks = $manager->getUserAddressBooks();
foreach ($addressBooks as $ab) {
if ($ab->getUri() === $addressbookId) {
$addressBook = $ab;
@@ -149,8 +147,6 @@ class SocialApiService {
/**
- * @NoAdminRequired
- *
* Retrieves and initiates all addressbooks from a user
*
* @param {string} userId the user to query
@@ -163,8 +159,6 @@ class SocialApiService {
}
/**
- * @NoAdminRequired
- *
* Retrieves social profile data for a contact and updates the entry
*
* @param {String} addressbookId the addressbook identifier
@@ -222,8 +216,51 @@ class SocialApiService {
}
/**
- * @NoAdminRequired
+ * checks an addressbook is existing
+ *
+ * @param {string} searchBookId the UID of the addressbook to verify
+ * @param {string} userId the user that should have access
*
+ * @returns {bool} true if the addressbook exists
+ */
+ public function existsAddressBook($searchBookId, $userId) {
+ $manager = $this->manager;
+ $coma = new ContactsManager($this->davBackend, $this->l10n);
+ $coma->setupContactsProvider($manager, $userId, $this->urlGen);
+ $addressBooks = $manager->getUserAddressBooks();
+ if ($this->getAddressBook($searchBookId, $manager) == null) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * checks a contact exists in an addressbook
+ *
+ * @param {string} searchContactId the UID of the contact to verify
+ * @param {string} searchBookId the UID of the addressbook to look in
+ * @param {string} userId the user that should have access
+ *
+ * @returns {bool} true if the contact exists
+ */
+ public function existsContact($searchContactId, $searchBookId, $userId) {
+ // load address books for the user
+ $manager = $this->manager;
+ $coma = new ContactsManager($this->davBackend, $this->l10n);
+ $coma->setupContactsProvider($manager, $userId, $this->urlGen);
+ $addressBook = $this->getAddressBook($searchBookId, $manager);
+ if ($addressBook == null) {
+ return false;
+ }
+
+ $check = $addressBook->search($searchContactId, ['UID'], ['types' => true]);
+ if (empty($check)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
* Stores the result of social avatar updates for each contact
* (used during batch updates in updateAddressbooks)
*
@@ -260,8 +297,6 @@ class SocialApiService {
}
/**
- * @NoAdminRequired
- *
* sorts an array of address books
*
* @param {IAddressBook} a
@@ -274,8 +309,6 @@ class SocialApiService {
}
/**
- * @NoAdminRequired
- *
* sorts an array of contacts
*
* @param {array} a
@@ -288,8 +321,6 @@ class SocialApiService {
}
/**
- * @NoAdminRequired
- *
* Updates social profile data for all contacts of an addressbook
*
* @param {String} network the social network to use (fallback: take first match)