Skip to content

Commit

Permalink
of course we take codacy serious!
Browse files Browse the repository at this point in the history
Signed-off-by: call-me-matt <nextcloud@matthiasheinisch.de>
  • Loading branch information
call-me-matt committed Jul 31, 2020
1 parent 10e5f15 commit df55f34
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
16 changes: 8 additions & 8 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;

use OCA\Contacts\AppInfo\Application;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IUserSession;
Expand All @@ -53,16 +54,15 @@ class PageController extends Controller {
/** @var SocialApiService */
private $socialApiService;

public function __construct(string $appName,
IRequest $request,
public function __construct(IRequest $request,
IConfig $config,
IInitialStateService $initialStateService,
IFactory $languageFactory,
IUserSession $userSession,
SocialApiService $socialApiService) {
parent::__construct($appName, $request);
parent::__construct(Application::APP_ID, $request);

$this->appName = $appName;
$this->appName = Application::APP_ID;
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->languageFactory = $languageFactory;
Expand All @@ -86,14 +86,14 @@ public function index(): TemplateResponse {
$locales = $this->languageFactory->findAvailableLocales();
$defaultProfile = $this->config->getAppValue($this->appName, 'defaultProfile', 'HOME');
$supportedNetworks = $this->socialApiService->getSupportedNetworks();
$isSocialEnabledByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes'); // allow users to retrieve avatars from social networks (default: yes)
$isSocialEnabledByUser = $this->config->getUserValue($userId, $this->appName, 'enableSocialSync', 'no'); // automated background syncs for social avatars (default: no)
$syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes'); // allow users to retrieve avatars from social networks (default: yes)
$bgSyncEnabledByUser = $this->config->getUserValue($userId, $this->appName, 'enableSocialSync', 'no'); // automated background syncs for social avatars (default: no)

$this->initialStateService->provideInitialState($this->appName, 'locales', $locales);
$this->initialStateService->provideInitialState($this->appName, 'defaultProfile', $defaultProfile);
$this->initialStateService->provideInitialState($this->appName, 'supportedNetworks', $supportedNetworks);
$this->initialStateService->provideInitialState($this->appName, 'allowSocialSync', $isSocialEnabledByAdmin);
$this->initialStateService->provideInitialState($this->appName, 'enableSocialSync', $isSocialEnabledByUser);
$this->initialStateService->provideInitialState($this->appName, 'allowSocialSync', $syncAllowedByAdmin);
$this->initialStateService->provideInitialState($this->appName, 'enableSocialSync', $bgSyncEnabledByUser);

Util::addScript($this->appName, 'contacts');
Util::addStyle($this->appName, 'contacts');
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/SocialApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\IUserSession;

class SocialApiController extends ApiController {
protected $appName;

/** @var IConfig */
private $config;
Expand All @@ -50,6 +51,7 @@ public function __construct(IRequest $request,
parent::__construct(Application::APP_ID, $request);

$this->config = $config;
$this->appName = Application::APP_ID;
$this->userSession = $userSession;
$this->socialApiService = $socialApiService;
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Cron/SocialUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
use OCA\Contacts\Service\SocialApiService;

class SocialUpdate extends \OC\BackgroundJob\QueuedJob {
private $appName;

/** @var SocialUpdateService */
private $social;

public function __construct(string $AppName, SocialApiService $social) {
$this->appName = $AppName;
public function __construct(SocialApiService $social) {
$this->social = $social;
}

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

namespace OCA\Contacts\Cron;

use OCA\Contacts\AppInfo\Application;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\IUser;
Expand All @@ -50,14 +52,14 @@ class SocialUpdateRegistration extends \OC\BackgroundJob\TimedJob {
* @param IUserManager $userManager
* @param IJobList $jobList
*/
public function __construct(string $AppName,
public function __construct(
// ITimeFactory $time,
IUserManager $userManager,
IConfig $config,
IJobList $jobList) {
//parent::__construct($time);

$this->appName = $AppName;
$this->appName = Application::APP_ID;
$this->userManager = $userManager;
$this->config = $config;
$this->jobList = $jobList;
Expand All @@ -72,16 +74,16 @@ public function __construct(string $AppName,
protected function run($arguments) {

// check if admin allows for social updates:
$isSocialEnabledByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes');
if (!($isSocialEnabledByAdmin === 'yes')) {
$syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes');
if (!($syncAllowedByAdmin === 'yes')) {
return;
}

$this->userManager->callForSeenUsers(function (IUser $user) {

// check that user opted-in:
$isSocialEnabledByUser = $this->config->getUserValue($user->getUID(), $this->appName, 'enableSocialSync', 'no');
if ($isSocialEnabledByUser === 'yes') {
$bgSyncEnabledByUser = $this->config->getUserValue($user->getUID(), $this->appName, 'enableSocialSync', 'no');
if ($bgSyncEnabledByUser === 'yes') {
$this->jobList->add(SocialUpdate::class, [
'userId' => $user->getUID()
]);
Expand Down
14 changes: 7 additions & 7 deletions lib/Service/SocialApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public function __construct(
* @returns {array} array of the supported social networks
*/
public function getSupportedNetworks() : array {
$isSocialEnabledByAdmin = $this->config->getAppValue(Application::APP_ID, 'allowSocialSync', 'yes');
if ($isSocialEnabledByAdmin !== 'yes') {
$syncAllowedByAdmin = $this->config->getAppValue(Application::APP_ID, 'allowSocialSync', 'yes');
if ($syncAllowedByAdmin !== 'yes') {
return [];
}
return $this->socialProvider->getSupportedNetworks();
Expand Down Expand Up @@ -150,8 +150,8 @@ protected function getAddressBook(string $addressbookId) : ?IAddressBook {
* @param {IManager} the contact manager to load
*/
protected function registerAddressbooks($userId, IManager $manager) {
$cm = new ContactsManager($this->davBackend, $this->l10n);
$cm->setupContactsProvider($manager, $userId, $this->urlGen);
$coma = new ContactsManager($this->davBackend, $this->l10n);
$coma->setupContactsProvider($manager, $userId, $this->urlGen);
//FIXME: better would be: davBackend->getUsersOwnAddressBooks($principal); (no shared or system address books)
// ... or the promising IAddressBookProvider, which I cant get running
$this->manager = $manager;
Expand Down Expand Up @@ -269,9 +269,9 @@ protected function registerUpdateResult(array $report, string $entry, string $st
public function updateAddressbooks(string $network, string $userId) : JSONResponse {

// double check!
$isSocialEnabledByAdmin = $this->config->getAppValue(Application::APP_ID, 'allowSocialSync', 'yes');
$isSocialEnabledByUser = $this->config->getUserValue($userId, Application::APP_ID, 'enableSocialSync', 'no');
if (($isSocialEnabledByAdmin !== 'yes') || ($isSocialEnabledByUser !== 'yes')) {
$syncAllowedByAdmin = $this->config->getAppValue(Application::APP_ID, 'allowSocialSync', 'yes');
$bgSyncEnabledByUser = $this->config->getUserValue($userId, Application::APP_ID, 'enableSocialSync', 'no');
if (($syncAllowedByAdmin !== 'yes') || ($bgSyncEnabledByUser !== 'yes')) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}

Expand Down
1 change: 1 addition & 0 deletions lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\Settings\ISettings;

class AdminSettings implements ISettings {
protected $appName;

/** @var IConfig */
private $config;
Expand Down
1 change: 0 additions & 1 deletion tests/unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function setUp() {
$this->socialApi = $this->createMock(SocialApiService::class);

$this->controller = new PageController(
'contacts',
$this->request,
$this->config,
$this->initialStateService,
Expand Down

0 comments on commit df55f34

Please sign in to comment.