Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide social sync option if social sync is not available #2913

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triple copyright and no https? 😛

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*
* @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
Expand Up @@ -4,6 +4,7 @@

/**
* @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 @@ -92,8 +93,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 @@ -369,10 +371,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
4 changes: 3 additions & 1 deletion src/components/AppNavigation/ContactsSettings.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
- @copyright Copyright (c) 2022 Julia Kirschenheuter <julia.kirschenheuter@nextcloud.com>
pboguslawski marked this conversation as resolved.
Show resolved Hide resolved
- @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
-
- @author Julia Kirschenheuter <julia.kirschenheuter@nextcloud.com>
-
Expand All @@ -26,7 +27,8 @@
:show-navigation="true"
:open.sync="showSettings">
<AppSettingsSection id="general-settings" :title="t('contacts', 'General settings')">
<CheckboxRadioSwitch :checked="enableSocialSync"
<CheckboxRadioSwitch v-if="allowSocialSync"
:checked="enableSocialSync"
:loading="enableSocialSyncLoading"
:disabled="enableSocialSyncLoading"
class="social-sync__checkbox contacts-settings-modal__form__row"
Expand Down