From 8a848215e5b871f40a7a12c29c75056ab86ad6e6 Mon Sep 17 00:00:00 2001 From: Pawel Boguslawski Date: Mon, 5 Sep 2022 14:06:39 +0200 Subject: [PATCH 1/4] Hide social sync option if social sync is not available This mod hides `Update avatars from social media (refreshed once per week)` checkbox from contacts settings if syncing avatars is disabled by admin or no internet connection is avalable. Author-Change-Id: IB#1125033 Related: https://github.com/nextcloud/contacts/issues/1594 Signed-off-by: Pawel Boguslawski --- lib/Controller/PageController.php | 6 ++++-- lib/Cron/SocialUpdateRegistration.php | 7 ++++--- lib/Service/SocialApiService.php | 14 ++++++++------ src/components/AppNavigation/SettingsSection.vue | 3 ++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index fcfee915e..00db59dff 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -1,6 +1,7 @@ + * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @author John Molakvoæ * @author Matthias Heinisch @@ -96,8 +97,9 @@ public function index(): TemplateResponse { $defaultProfile = $this->config->getAppValue(Application::APP_ID, 'defaultProfile', 'HOME'); $supportedNetworks = $this->socialApiService->getSupportedNetworks(); - // allow users to retrieve avatars from social networks (default: yes) - $syncAllowedByAdmin = $this->config->getAppValue(Application::APP_ID, 'allowSocialSync', 'yes'); + // Allow users to retrieve avatars from social networks (default: yes). Disabled if internet connection is not available. + $syncAllowedByAdmin = (($this->config->getAppValue(Application::APP_ID, 'allowSocialSync', 'yes') === 'yes') + && $this->config->getSystemValueBool('has_internet_connection', true)) ? 'yes' : 'no'; // automated background syncs for social avatars (default: no) $bgSyncEnabledByUser = $this->config->getUserValue($userId, Application::APP_ID, 'enableSocialSync', 'no'); diff --git a/lib/Cron/SocialUpdateRegistration.php b/lib/Cron/SocialUpdateRegistration.php index da8f24c0d..70024e933 100644 --- a/lib/Cron/SocialUpdateRegistration.php +++ b/lib/Cron/SocialUpdateRegistration.php @@ -4,6 +4,7 @@ /** * @copyright 2017 Georg Ehrke + * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @author Georg Ehrke * @author Roeland Jago Douma @@ -84,9 +85,9 @@ public function __construct( */ protected function run($arguments) { - // check if admin allows for social updates: - $syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes'); - if (!($syncAllowedByAdmin === 'yes')) { + // Social updates must be enabled by admin and internet connection must be available. + if (($this->config->getAppValue($this->appName, 'allowSocialSync', 'yes') !== 'yes') + || !$this->config->getSystemValueBool('has_internet_connection', true)) { return; } diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php index 9a27a93d0..f5bf10f48 100644 --- a/lib/Service/SocialApiService.php +++ b/lib/Service/SocialApiService.php @@ -1,6 +1,7 @@ + * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @author Matthias Heinisch * @@ -89,8 +90,9 @@ public function __construct( * @return {array} array of the supported social networks */ public function getSupportedNetworks() : array { - $syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes'); - if ($syncAllowedByAdmin !== 'yes') { + // Check if admin allows for social updates and internet connection is available. + if (($this->config->getAppValue($this->appName, 'allowSocialSync', 'yes') !== 'yes') + || !$this->config->getSystemValueBool('has_internet_connection', true)) { return []; } return $this->socialProvider->getSupportedNetworks(); @@ -364,10 +366,10 @@ protected function sortContacts(array $a, array $b) { */ public function updateAddressbooks(string $userId, string $offsetBook = null, string $offsetContact = null, string $network = null) : JSONResponse { - // double check! - $syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes'); - $bgSyncEnabledByUser = $this->config->getUserValue($userId, $this->appName, 'enableSocialSync', 'no'); - if (($syncAllowedByAdmin !== 'yes') || ($bgSyncEnabledByUser !== 'yes')) { + // Forbid if social sync is disabled by admin or by user or no internet connection is available. + if (($this->config->getAppValue($this->appName, 'allowSocialSync', 'yes') !== 'yes') + || ($this->config->getUserValue($userId, $this->appName, 'enableSocialSync', 'no') !== 'yes') + || !$this->config->getSystemValueBool('has_internet_connection', true)) { return new JSONResponse([], Http::STATUS_FORBIDDEN); } diff --git a/src/components/AppNavigation/SettingsSection.vue b/src/components/AppNavigation/SettingsSection.vue index 58f80ed47..8890e4863 100644 --- a/src/components/AppNavigation/SettingsSection.vue +++ b/src/components/AppNavigation/SettingsSection.vue @@ -1,5 +1,6 @@