Skip to content

Commit

Permalink
Hide social sync option if social sync is not available
Browse files Browse the repository at this point in the history
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: nextcloud#1594
Signed-off-by: Pawel Boguslawski <pawel.boguslawski@ib.pl>
  • Loading branch information
pboguslawski committed Sep 5, 2022
1 parent 07b7fb0 commit 8a84821
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
* @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Matthias Heinisch <nextcloud@matthiasheinisch.de>
Expand Down Expand Up @@ -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');

Expand Down
7 changes: 4 additions & 3 deletions lib/Cron/SocialUpdateRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @copyright 2017 Georg Ehrke <oc.list@georgehrke.com>
* @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
*
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 8 additions & 6 deletions lib/Service/SocialApiService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2020 Matthias Heinisch <nextcloud@matthiasheinisch.de>
* @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
*
* @author Matthias Heinisch <nextcloud@matthiasheinisch.de>
*
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/AppNavigation/SettingsSection.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
- @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
- @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
-
- @author John Molakvoæ <skjnldsv@protonmail.com>
- @author Matthias Heinisch <nextcloud@matthiasheinisch.de>
Expand All @@ -24,7 +25,7 @@
<template>
<div>
<SettingsSortContacts class="settings-section" />
<CheckboxRadioSwitch :checked="enableSocialSync"
<CheckboxRadioSwitch v-if="allowSocialSync" :checked="enableSocialSync"
:loading="enableSocialSyncLoading"
:disabled="enableSocialSyncLoading"
class="social-sync__checkbox"
Expand Down

0 comments on commit 8a84821

Please sign in to comment.