Skip to content

Commit

Permalink
check if circles app is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Heinrich committed Oct 2, 2023
1 parent cf9036a commit 6abd2d6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use OCA\Calendar\Service\Appointments\AppointmentConfigService;
use OCA\Calendar\Service\CategoriesService;
use OC\App\CompareVersion;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\FileDisplayResponse;
Expand Down Expand Up @@ -55,6 +56,9 @@ class ViewController extends Controller {
/** @var IAppManager */
private $appManager;

/** @var CompareVersion */

Check failure on line 59 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

UndefinedDocblockClass

lib/Controller/ViewController.php:59:14: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 59 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedDocblockClass

lib/Controller/ViewController.php:59:14: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 59 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

UndefinedDocblockClass

lib/Controller/ViewController.php:59:14: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 59 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

UndefinedDocblockClass

lib/Controller/ViewController.php:59:14: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)
private $compareVersion;

/** @var string */
private $userId;

Expand All @@ -67,6 +71,7 @@ public function __construct(string $appName,
CategoriesService $categoriesService,
IInitialState $initialStateService,
IAppManager $appManager,
CompareVersion $compareVersion,

Check failure on line 74 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

UndefinedClass

lib/Controller/ViewController.php:74:3: UndefinedClass: Class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/019)

Check failure on line 74 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedClass

lib/Controller/ViewController.php:74:3: UndefinedClass: Class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/019)

Check failure on line 74 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

UndefinedClass

lib/Controller/ViewController.php:74:3: UndefinedClass: Class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/019)

Check failure on line 74 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

UndefinedClass

lib/Controller/ViewController.php:74:3: UndefinedClass: Class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/019)
?string $userId,
IAppData $appData) {
parent::__construct($appName, $request);
Expand All @@ -75,6 +80,7 @@ public function __construct(string $appName,
$this->categoriesService = $categoriesService;
$this->initialStateService = $initialStateService;
$this->appManager = $appManager;
$this->compareVersion = $compareVersion;
$this->userId = $userId;
$this->appData = $appData;
}
Expand Down Expand Up @@ -123,6 +129,11 @@ public function index():TemplateResponse {
$talkApiVersion = version_compare($this->appManager->getAppVersion('spreed'), '12.0.0', '>=') ? 'v4' : 'v1';
$tasksEnabled = $this->appManager->isEnabledForUser('tasks');

$circleVersion = $this->appManager->getAppVersion('circles');
$isCirclesEnabled = $this->appManager->isEnabledForUser('circles') === true;
// if circles is not installed, we use 0.0.0
$isCircleVersionCompatible = $this->compareVersion->isCompatible($circleVersion ? $circleVersion : '0.0.0', '22');

Check failure on line 135 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

UndefinedDocblockClass

lib/Controller/ViewController.php:135:32: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 135 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedDocblockClass

lib/Controller/ViewController.php:135:32: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 135 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

UndefinedDocblockClass

lib/Controller/ViewController.php:135:32: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

Check failure on line 135 in lib/Controller/ViewController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

UndefinedDocblockClass

lib/Controller/ViewController.php:135:32: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\App\CompareVersion does not exist (see https://psalm.dev/200)

$this->initialStateService->provideInitialState('app_version', $appVersion);
$this->initialStateService->provideInitialState('event_limit', $eventLimit);
$this->initialStateService->provideInitialState('first_run', $firstRun);
Expand All @@ -145,6 +156,7 @@ public function index():TemplateResponse {
$this->initialStateService->provideInitialState('can_subscribe_link', $canSubscribeLink);
$this->initialStateService->provideInitialState('categories', $this->categoriesService->getCategories($this->userId));
$this->initialStateService->provideInitialState('show_resources', $showResources);
$this->initialStateService->provideInitialState('isCirclesEnabled', $isCirclesEnabled && $isCircleVersionCompatible);

return new TemplateResponse($this->appName, 'main');
}
Expand Down
14 changes: 10 additions & 4 deletions src/components/Editor/Invitees/InviteesListSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
NcMultiselect as Multiselect,
} from '@nextcloud/vue'
import { principalPropertySearchByDisplaynameOrEmail } from '../../../services/caldavService.js'
import isCirclesEnabled from '../../../services/isCirclesEnabled.js'
import { circleSearchByName } from '../../../services/circleService.js'
import HttpClient from '@nextcloud/axios'
import debounce from 'debounce'
Expand All @@ -100,6 +101,7 @@ export default {
isLoading: false,
inputGiven: false,
matches: [],
isCirclesEnabled

Check warning on line 104 in src/components/Editor/Invitees/InviteesListSearch.vue

View workflow job for this annotation

GitHub Actions / eslint

Missing trailing comma
}
},
computed: {
Expand All @@ -118,14 +120,18 @@ export default {
if (query.length > 0) {
const promises = [
this.findAttendeesFromContactsAPI(query),
this.findAttendeesFromDAV(query),
this.findAttendeesFromCircles(query),
this.findAttendeesFromDAV(query)

Check warning on line 123 in src/components/Editor/Invitees/InviteesListSearch.vue

View workflow job for this annotation

GitHub Actions / eslint

Missing trailing comma
]
if (isCirclesEnabled) {
promises.push(this.findAttendeesFromCircles(query))
}
const [contactsResults, davResults, circleResults] = await Promise.all(promises)
matches.push(...contactsResults)
matches.push(...davResults)
matches.push(...circleResults)
if (isCirclesEnabled) {
matches.push(...circleResults)
}
// Source of the Regex: https://stackoverflow.com/a/46181
// eslint-disable-next-line
Expand Down Expand Up @@ -267,7 +273,7 @@ export default {
return {
commonName: circle.displayname,
calendarUserType: 'GROUP',

Check warning on line 275 in src/components/Editor/Invitees/InviteesListSearch.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesListSearch.vue#L273-L275

Added lines #L273 - L275 were not covered by tests
email: '',
email: '+' + circle.id + '@',

Check failure on line 276 in src/components/Editor/Invitees/InviteesListSearch.vue

View workflow job for this annotation

GitHub Actions / eslint

Multiple spaces found before 'circle'
isUser: false,
dropdownName: circle.displayname,
type: 'circle',
Expand Down
2 changes: 2 additions & 0 deletions src/services/circleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const circleSearchByName = async (query) => {
return []

Check warning on line 59 in src/services/circleService.js

View check run for this annotation

Codecov / codecov/patch

src/services/circleService.js#L58-L59

Added lines #L58 - L59 were not covered by tests
}

console.log(circles)

Check failure on line 62 in src/services/circleService.js

View workflow job for this annotation

GitHub Actions / eslint

Unexpected console statement

Check warning on line 62 in src/services/circleService.js

View check run for this annotation

Codecov / codecov/patch

src/services/circleService.js#L62

Added line #L62 was not covered by tests

Check failure on line 63 in src/services/circleService.js

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
return circles.filter((circle) => {
return true
}).map(circle => ({

Check warning on line 66 in src/services/circleService.js

View check run for this annotation

Codecov / codecov/patch

src/services/circleService.js#L64-L66

Added lines #L64 - L66 were not covered by tests
Expand Down
26 changes: 26 additions & 0 deletions src/services/isCirclesEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @copyright Copyright (c) 2021 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

import { loadState } from '@nextcloud/initial-state'

const isCirclesEnabled = loadState('calendar', 'isCirclesEnabled', false)

Check warning on line 25 in src/services/isCirclesEnabled.js

View check run for this annotation

Codecov / codecov/patch

src/services/isCirclesEnabled.js#L25

Added line #L25 was not covered by tests
export default isCirclesEnabled

0 comments on commit 6abd2d6

Please sign in to comment.