diff options
Diffstat (limited to 'lib/Controller')
-rw-r--r-- | lib/Controller/PageController.php | 38 | ||||
-rw-r--r-- | lib/Controller/SocialApiController.php | 48 |
2 files changed, 78 insertions, 8 deletions
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index e94510cd..60fd2e8b 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> + * @author Matthias Heinisch <nextcloud@matthiasheinisch.de> * * @license GNU AGPL version 3 or any later version * @@ -23,12 +24,14 @@ namespace OCA\Contacts\Controller; -use OCA\Contacts\AppInfo\Application; use OCA\Contacts\Service\SocialApiService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; + +use OCA\Contacts\AppInfo\Application; use OCP\IConfig; use OCP\IInitialStateService; +use OCP\IUserSession; use OCP\IRequest; use OCP\L10N\IFactory; use OCP\Util; @@ -43,6 +46,9 @@ class PageController extends Controller { /** @var IFactory */ private $languageFactory; + /** @var IUserSession */ + private $userSession; + /** @var SocialApiService */ private $socialApiService; @@ -50,12 +56,15 @@ class PageController extends Controller { IConfig $config, IInitialStateService $initialStateService, IFactory $languageFactory, + IUserSession $userSession, SocialApiService $socialApiService) { parent::__construct(Application::APP_ID, $request); + $this->appName = Application::APP_ID; $this->config = $config; $this->initialStateService = $initialStateService; $this->languageFactory = $languageFactory; + $this->userSession = $userSession; $this->socialApiService = $socialApiService; } @@ -66,17 +75,30 @@ class PageController extends Controller { * Default routing */ public function index(): TemplateResponse { + $user = $this->userSession->getUser(); + $userId = ''; + if (!is_null($user)) { + $userId = $user->getUid(); + } + $locales = $this->languageFactory->findAvailableLocales(); - $defaultProfile = $this->config->getAppValue(Application::APP_ID, 'defaultProfile', 'HOME'); + $defaultProfile = $this->config->getAppValue($this->appName, 'defaultProfile', 'HOME'); $supportedNetworks = $this->socialApiService->getSupportedNetworks(); + $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(Application::APP_ID, 'locales', $locales); - $this->initialStateService->provideInitialState(Application::APP_ID, 'defaultProfile', $defaultProfile); - $this->initialStateService->provideInitialState(Application::APP_ID, 'supportedNetworks', $supportedNetworks); + $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, 'locales', $locales); + $this->initialStateService->provideInitialState($this->appName, 'defaultProfile', $defaultProfile); + $this->initialStateService->provideInitialState($this->appName, 'supportedNetworks', $supportedNetworks); + $this->initialStateService->provideInitialState($this->appName, 'allowSocialSync', $syncAllowedByAdmin); + $this->initialStateService->provideInitialState($this->appName, 'enableSocialSync', $bgSyncEnabledByUser); - Util::addScript(Application::APP_ID, 'contacts'); - Util::addStyle(Application::APP_ID, 'contacts'); + Util::addScript($this->appName, 'contacts'); + Util::addStyle($this->appName, 'contacts'); - return new TemplateResponse(Application::APP_ID, 'main'); + return new TemplateResponse($this->appName, 'main'); } } diff --git a/lib/Controller/SocialApiController.php b/lib/Controller/SocialApiController.php index 4898d915..b09eafdb 100644 --- a/lib/Controller/SocialApiController.php +++ b/lib/Controller/SocialApiController.php @@ -30,21 +30,29 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; use OCP\IConfig; use OCP\IRequest; +use OCP\IUserSession; class SocialApiController extends ApiController { + protected $appName; /** @var IConfig */ private $config; + /** @var IUserSession */ + private $userSession; + /** @var SocialApiService */ private $socialApiService; public function __construct(IRequest $request, IConfig $config, + IUserSession $userSession, SocialApiService $socialApiService) { parent::__construct(Application::APP_ID, $request); $this->config = $config; + $this->appName = Application::APP_ID; + $this->userSession = $userSession; $this->socialApiService = $socialApiService; } @@ -69,6 +77,46 @@ class SocialApiController extends ApiController { /** * @NoAdminRequired * + * update appconfig (user setting) + * + * @param {String} key the identifier to change + * @param {String} allow the value to set + * + * @returns {JSONResponse} an empty JSONResponse with respective http status code + */ + public function setUserConfig($key, $allow) { + $user = $this->userSession->getUser(); + if (is_null($user)) { + return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); + } + $userId = $user->getUid(); + $this->config->setUserValue($userId, $this->appName, $key, $allow); + return new JSONResponse([], Http::STATUS_OK); + } + + + /** + * @NoAdminRequired + * + * retrieve appconfig (user setting) + * + * @param {String} key the identifier to retrieve + * + * @returns {string} the desired value or null if not existing + */ + public function getUserConfig($key) { + $user = $this->userSession->getUser(); + if (is_null($user)) { + return null; + } + $userId = $user->getUid(); + return $this->config->getUserValue($userId, $this->appName, $key, 'null'); + } + + + /** + * @NoAdminRequired + * * returns an array of supported social networks * * @returns {array} array of the supported social networks |