From da9a5415a1b3a55fd8335604ccf3bbd4b2fcb2e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 4 Jun 2021 08:11:49 +0200 Subject: [PATCH] Properly check for circles version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- .eslintrc.js | 1 + lib/Controller/PageController.php | 16 +- package-lock.json | 221 ++++++++++++++++++- package.json | 1 + src/main.js | 5 +- src/services/logger.js | 28 +++ src/views/Contacts.vue | 6 + tests/unit/Controller/PageControllerTest.php | 10 +- 8 files changed, 280 insertions(+), 8 deletions(-) create mode 100644 src/services/logger.js diff --git a/.eslintrc.js b/.eslintrc.js index a532df9e..29134f1d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,6 @@ module.exports = { globals: { + appName: true, appVersion: true, }, diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index d885d6b7..c789ecc7 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -24,6 +24,7 @@ namespace OCA\Contacts\Controller; +use OC\App\CompareVersion; use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; @@ -56,13 +57,17 @@ class PageController extends Controller { /** @var IAppManager */ private $appManager; + /** @var CompareVersion */ + private $compareVersion; + public function __construct(IRequest $request, IConfig $config, IInitialStateService $initialStateService, IFactory $languageFactory, IUserSession $userSession, SocialApiService $socialApiService, - IAppManager $appManager) { + IAppManager $appManager, + CompareVersion $compareVersion) { parent::__construct(Application::APP_ID, $request); $this->config = $config; @@ -71,6 +76,7 @@ class PageController extends Controller { $this->userSession = $userSession; $this->socialApiService = $socialApiService; $this->appManager = $appManager; + $this->compareVersion = $compareVersion; } /** @@ -95,13 +101,17 @@ class PageController extends Controller { // automated background syncs for social avatars (default: no) $bgSyncEnabledByUser = $this->config->getUserValue($userId, Application::APP_ID, 'enableSocialSync', 'no'); + $isContactsInteractionEnabled = $this->appManager->isEnabledForUser('contactsinteraction') === true; + $isCirclesEnabled = $this->appManager->isEnabledForUser('circles') === true; + $isCircleVersionCompatible = $this->compareVersion->isCompatible($this->appManager->getAppVersion('circles'), 22); + $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(Application::APP_ID, 'allowSocialSync', $syncAllowedByAdmin); $this->initialStateService->provideInitialState(Application::APP_ID, 'enableSocialSync', $bgSyncEnabledByUser); - $this->initialStateService->provideInitialState(Application::APP_ID, 'isContactsInteractionEnabled', $this->appManager->isEnabledForUser('contactsinteraction') === true); - $this->initialStateService->provideInitialState(Application::APP_ID, 'isCirclesEnabled', $this->appManager->isEnabledForUser('circles') === true); + $this->initialStateService->provideInitialState(Application::APP_ID, 'isContactsInteractionEnabled', $isContactsInteractionEnabled); + $this->initialStateService->provideInitialState(Application::APP_ID, 'isCirclesEnabled', $isCirclesEnabled && $isCircleVersionCompatible); Util::addScript(Application::APP_ID, 'contacts-main'); Util::addStyle(Application::APP_ID, 'contacts'); diff --git a/package-lock.json b/package-lock.json index 4e1289ad..d15fca16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1946,6 +1946,16 @@ "node-gettext": "^3.0.0" } }, + "@nextcloud/logger": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@nextcloud/logger/-/logger-2.0.0.tgz", + "integrity": "sha512-C3vb8I1z67c5FhSWUNB21U6gzzD7RVgjyVUeK+QVz5nYQt1UWTp9yGyqE8G+R5QAyFFWfuOw1RHHkHJ/CWQ4YA==", + "requires": { + "@nextcloud/auth": "^1.2.2", + "babel-plugin-transform-class-properties": "^6.24.1", + "core-js": "^3.6.4" + } + }, "@nextcloud/moment": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@nextcloud/moment/-/moment-1.1.1.tgz", @@ -2814,6 +2824,58 @@ "resolved": "https://registry.npmjs.org/b64-to-blob/-/b64-to-blob-1.2.19.tgz", "integrity": "sha512-L3nSu8GgF4iEyNYakCQSfL2F5GI5aCXcot9mNTf+4N0/BMhpxqqHyOb6jIR24iq2xLjQZLG8FOt3gnUcV+9NVg==" }, + "babel-code-frame": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", + "requires": { + "chalk": "^1.1.3", + "esutils": "^2.0.2", + "js-tokens": "^3.0.2" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + } + } + }, "babel-eslint": { "version": "10.1.0", "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.1.0.tgz", @@ -2828,6 +2890,27 @@ "resolve": "^1.12.0" } }, + "babel-helper-function-name": { + "version": "6.24.1", + "resolved": "https://registry.npmjs.org/babel-helper-function-name/-/babel-helper-function-name-6.24.1.tgz", + "integrity": "sha1-00dbjAPtmCQqJbSDUasYOZ01gKk=", + "requires": { + "babel-helper-get-function-arity": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1", + "babel-traverse": "^6.24.1", + "babel-types": "^6.24.1" + } + }, + "babel-helper-get-function-arity": { + "version": "6.24.1", + "resolved": "https://registry.npmjs.org/babel-helper-get-function-arity/-/babel-helper-get-function-arity-6.24.1.tgz", + "integrity": "sha1-j3eCqpNAfEHTqlCQj4mwMbG2hT0=", + "requires": { + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, "babel-loader": { "version": "8.2.2", "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-8.2.2.tgz", @@ -2914,6 +2997,14 @@ } } }, + "babel-messages": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-6.23.0.tgz", + "integrity": "sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=", + "requires": { + "babel-runtime": "^6.22.0" + } + }, "babel-plugin-dynamic-import-node": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz", @@ -2949,6 +3040,101 @@ "@babel/helper-define-polyfill-provider": "^0.2.2" } }, + "babel-plugin-syntax-class-properties": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-class-properties/-/babel-plugin-syntax-class-properties-6.13.0.tgz", + "integrity": "sha1-1+sjt5oxf4VDlixQW4J8fWysJ94=" + }, + "babel-plugin-transform-class-properties": { + "version": "6.24.1", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-class-properties/-/babel-plugin-transform-class-properties-6.24.1.tgz", + "integrity": "sha1-anl2PqYdM9NvN7YRqp3vgagbRqw=", + "requires": { + "babel-helper-function-name": "^6.24.1", + "babel-plugin-syntax-class-properties": "^6.8.0", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1" + } + }, + "babel-runtime": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "requires": { + "core-js": "^2.4.0", + "regenerator-runtime": "^0.11.0" + }, + "dependencies": { + "core-js": { + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz", + "integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==" + }, + "regenerator-runtime": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" + } + } + }, + "babel-template": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-template/-/babel-template-6.26.0.tgz", + "integrity": "sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=", + "requires": { + "babel-runtime": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "lodash": "^4.17.4" + } + }, + "babel-traverse": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.26.0.tgz", + "integrity": "sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=", + "requires": { + "babel-code-frame": "^6.26.0", + "babel-messages": "^6.23.0", + "babel-runtime": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "debug": "^2.6.8", + "globals": "^9.18.0", + "invariant": "^2.2.2", + "lodash": "^4.17.4" + }, + "dependencies": { + "globals": { + "version": "9.18.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", + "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==" + } + } + }, + "babel-types": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-types/-/babel-types-6.26.0.tgz", + "integrity": "sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=", + "requires": { + "babel-runtime": "^6.26.0", + "esutils": "^2.0.2", + "lodash": "^4.17.4", + "to-fast-properties": "^1.0.3" + }, + "dependencies": { + "to-fast-properties": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", + "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=" + } + } + }, + "babylon": { + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", + "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==" + }, "bail": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/bail/-/bail-1.0.5.tgz", @@ -3292,8 +3478,8 @@ "dev": true }, "cdav-library": { - "version": "git+https://github.com/nextcloud/cdav-library.git#7fdc09ccc4917635c5189a878be9a899ee81f799", - "from": "git+https://github.com/nextcloud/cdav-library.git#7fdc09ccc4917635c5189a878be9a899ee81f799", + "version": "git+https://github.com/nextcloud/cdav-library.git#00e0479f545cd9d9fc445e70596ec154c106d3c7", + "from": "git+https://github.com/nextcloud/cdav-library.git", "requires": { "core-js": "^3.13.0", "regenerator-runtime": "^0.13.7" @@ -5646,6 +5832,21 @@ "function-bind": "^1.1.1" } }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "requires": { + "ansi-regex": "^2.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + } + } + }, "has-bigints": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.1.tgz", @@ -5923,6 +6124,14 @@ "integrity": "sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==", "dev": true }, + "invariant": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", + "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", + "requires": { + "loose-envify": "^1.0.0" + } + }, "is-accessor-descriptor": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz", @@ -6546,6 +6755,14 @@ "integrity": "sha512-vM6rUVCVUJJt33bnmHiZEvr7wPT78ztX7rojL+LW51bHtLh6HTjx84LA5W4+oa6aKEJA7jJu5LR6vQRBpA5DVg==", "dev": true }, + "loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "requires": { + "js-tokens": "^3.0.0 || ^4.0.0" + } + }, "lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", diff --git a/package.json b/package.json index c0ab4a3d..789055a2 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@nextcloud/event-bus": "^2.0.0", "@nextcloud/initial-state": "^1.2.0", "@nextcloud/l10n": "^1.4.1", + "@nextcloud/logger": "^2.0.0", "@nextcloud/moment": "^1.1.1", "@nextcloud/paths": "^2.0.0", "@nextcloud/router": "^2.0.0", diff --git a/src/main.js b/src/main.js index 397a35bb..51a2b45c 100644 --- a/src/main.js +++ b/src/main.js @@ -28,6 +28,7 @@ import Vue from 'vue' import App from './ContactsRoot' import router from './router' import store from './store' +import logger from './services/logger' /** GLOBAL COMPONENTS AND DIRECTIVE */ import ClickOutside from 'vue-click-outside' @@ -55,8 +56,10 @@ sync(store, router) Vue.prototype.t = t Vue.prototype.n = n -// eslint-disable-next-line + +Vue.prototype.appName = appName Vue.prototype.appVersion = appVersion +Vue.prototype.logger = logger Vue.prototype.OC = OC Vue.prototype.OCA = OCA diff --git a/src/services/logger.js b/src/services/logger.js new file mode 100644 index 00000000..c30f921e --- /dev/null +++ b/src/services/logger.js @@ -0,0 +1,28 @@ +/** + * @copyright 2021 Christoph Wurst + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import { getLoggerBuilder } from '@nextcloud/logger' + +export default getLoggerBuilder() + .setApp(appName) + .detectUser() + .build() diff --git a/src/views/Contacts.vue b/src/views/Contacts.vue index 72f3fd5e..3306ade7 100644 --- a/src/views/Contacts.vue +++ b/src/views/Contacts.vue @@ -214,6 +214,12 @@ export default { mounted() { // Register search this.search = new OCA.Search(this.search, this.resetSearch) + + if (this.isCirclesEnabled) { + this.logger.info('Circles frontend enabled') + } else { + this.logger.info('No compatible version of circles found') + } }, async beforeMount() { diff --git a/tests/unit/Controller/PageControllerTest.php b/tests/unit/Controller/PageControllerTest.php index 1b3625e2..a60bfcc0 100644 --- a/tests/unit/Controller/PageControllerTest.php +++ b/tests/unit/Controller/PageControllerTest.php @@ -25,9 +25,10 @@ namespace OCA\Contacts\Controller; use ChristophWurst\Nextcloud\Testing\TestCase; +use OC\App\CompareVersion; use OCA\Contacts\Service\SocialApiService; -use OCP\AppFramework\Http\TemplateResponse; use OCP\App\IAppManager; +use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IInitialStateService; use OCP\IRequest; @@ -60,6 +61,9 @@ class PageControllerTest extends TestCase { /** @var IAppManager|MockObject*/ private $appManager; + /** @var CompareVersion|MockObject*/ + private $compareVersion; + protected function setUp(): void { parent::setUp(); @@ -70,6 +74,7 @@ class PageControllerTest extends TestCase { $this->userSession = $this->createMock(IUserSession::class); $this->socialApi = $this->createMock(SocialApiService::class); $this->appManager = $this->createMock(IAppManager::class); + $this->compareVersion = $this->createMock(CompareVersion::class); $this->controller = new PageController( $this->request, @@ -78,7 +83,8 @@ class PageControllerTest extends TestCase { $this->languageFactory, $this->userSession, $this->socialApi, - $this->appManager + $this->appManager, + $this->compareVersion ); }