Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions lib/Service/CalendarInitialStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Share\IManager as IShareManager;
use function in_array;

class CalendarInitialStateService {
Expand All @@ -39,6 +40,7 @@ public function __construct(
private ?IQueue $queue,
private IGroupManager $groupManager,
private IUserManager $userManager,
private IShareManager $shareManager,
) {
}

Expand Down Expand Up @@ -80,6 +82,7 @@ public function run(): void {
'outgoing_server2server_share_enabled',
true,
);
$allowGroupSharing = $this->shareManager->allowGroupSharing();

$this->initialStateService->provideInitialState('event_limit', $eventLimit);
$this->initialStateService->provideInitialState('first_run', $firstRun);
Expand All @@ -102,6 +105,7 @@ public function run(): void {
'calendar_federation_enabled',
$calendarFederationEnabled && $remoteSharesEnabled,
);
$this->initialStateService->provideInitialState('shareapi_allow_group_sharing', $allowGroupSharing);
$this->initialStateService->provideInitialState('has_notify_push', $this->queue !== null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:searchable="true"
:internalSearch="false"
:max-height="600"
:placeholder="$t('calendar', 'Share with users or groups')"
:placeholder="placeholder"
class="sharing-search__select"
:class="{ showContent: inputGiven, 'icon-loading': isLoading }"
:userSelect="true"
Expand All @@ -22,11 +22,11 @@
openDirection="above"
trackBy="user"
label="displayName"
:ariaLabelCombobox="$t('calendar', 'Share with users or groups')"
:ariaLabelCombobox="placeholder"
@search="findSharee"
@option:selected="shareCalendar">
<template #no-options>
<span>{{ $t('calendar', 'No users or groups') }}</span>
<span>{{ noResult }}</span>
</template>
<template #option="sharee">
<div class="share-item">
Expand Down Expand Up @@ -58,6 +58,7 @@ import AccountMultiple from 'vue-material-design-icons/AccountMultiple.vue'
import { principalPropertySearchByDisplaynameOrEmail } from '@/services/caldavService.js'
import useCalendarsStore from '@/store/calendars.js'
import usePrincipalsStore from '@/store/principals.js'
import useSettingsStore from '@/store/settings.js'
import { urldecode } from '@/utils/url.ts'

export default {
Expand Down Expand Up @@ -85,7 +86,7 @@ export default {
},

computed: {
...mapStores(usePrincipalsStore, useCalendarsStore),
...mapStores(usePrincipalsStore, useCalendarsStore, useSettingsStore),

/**
* True, if federated calendar shares are enabled on this server.
Expand All @@ -95,6 +96,30 @@ export default {
supportsFederatedCalendars() {
return loadState('calendar', 'calendar_federation_enabled')
},

/**
* Placeholder / aria label for the sharee search input.
*
* @return {string}
*/
placeholder() {
if (this.settingsStore.allowGroupSharing) {
return this.$t('calendar', 'Share with users or groups')
}
return this.$t('calendar', 'Share with users')
},

/**
* Empty-state message when no sharees match.
*
* @return {string}
*/
noResult() {
if (this.settingsStore.allowGroupSharing) {
return this.$t('calendar', 'No users or groups')
}
return this.$t('calendar', 'No users')
},
},

methods: {
Expand Down Expand Up @@ -203,6 +228,9 @@ export default {
}

const isGroup = result.calendarUserType === 'GROUP'
if (isGroup && !this.settingsStore.allowGroupSharing) {
return list
}

// TODO: Why do we have to decode those two values?
const user = urldecode(result[isGroup ? 'groupId' : 'userId'])
Expand Down
6 changes: 5 additions & 1 deletion src/store/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default defineStore('settings', {
forceEventAlarmType: false,
canSubscribeLink: true,
showResources: true,
allowGroupSharing: true,
// user-defined Nextcloud settings
momentLocale: 'en',
attachmentsFolder: '/Calendar',
Expand Down Expand Up @@ -348,8 +349,9 @@ export default defineStore('settings', {
* @param {string} data.attachmentsFolder Default user's attachments folder
* @param {boolean} data.showResources Show or hide the resources tab
* @param {string} data.publicCalendars The list of public calendars configured by the administrator
* @param {boolean} data.allowGroupSharing Whether sharing calendars with groups is allowed
*/
loadSettingsFromServer({ appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showDeclined, showWeekends, skipPopover, slotDuration, defaultReminderPartDay, defaultReminderFullDay, talkEnabled, tasksEnabled, timezone, hideEventExport, forceEventAlarmType, disableAppointments, tasksSidebar, canSubscribeLink, attachmentsFolder, showResources, publicCalendars }) {
loadSettingsFromServer({ appVersion, eventLimit, firstRun, showWeekNumbers, showTasks, showDeclined, showWeekends, skipPopover, slotDuration, defaultReminderPartDay, defaultReminderFullDay, talkEnabled, tasksEnabled, timezone, hideEventExport, forceEventAlarmType, disableAppointments, tasksSidebar, canSubscribeLink, attachmentsFolder, showResources, publicCalendars, allowGroupSharing }) {
logInfo(`
Initial settings:
- AppVersion: ${appVersion}
Expand All @@ -374,6 +376,7 @@ Initial settings:
- attachmentsFolder: ${attachmentsFolder}
- ShowResources: ${showResources}
- PublicCalendars: ${publicCalendars}
- AllowGroupSharing: ${allowGroupSharing}
`)

this.appVersion = appVersion
Expand All @@ -398,6 +401,7 @@ Initial settings:
this.attachmentsFolder = attachmentsFolder
this.showResources = showResources
this.publicCalendars = publicCalendars
this.allowGroupSharing = allowGroupSharing
},

/**
Expand Down
1 change: 1 addition & 0 deletions src/utils/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function getSettingsFromInitialState() {
showResources: loadState('calendar', 'show_resources', true),
publicCalendars: loadState('calendar', 'publicCalendars', []),
tasksSidebar: loadState('calendar', 'tasks_sidebar', true),
allowGroupSharing: loadState('calendar', 'shareapi_allow_group_sharing', true),
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/javascript/unit/store/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('store/settings test suite', () => {
attachmentsFolder: '/Calendar',
attachmentsFolderCreated: false,
showResources: true,
allowGroupSharing: true,
publicCalendars: null,
searchQuery: '',
})
Expand Down Expand Up @@ -90,6 +91,7 @@ describe('store/settings test suite', () => {
canSubscribeLink: true,
attachmentsFolder: '/Calendar',
showResources: true,
allowGroupSharing: true,
publicCalendars: null,
}

Expand Down Expand Up @@ -118,6 +120,7 @@ describe('store/settings test suite', () => {
canSubscribeLink: true,
attachmentsFolder: '/Attachments',
showResources: true,
allowGroupSharing: false,
publicCalendars: null,
}

Expand Down Expand Up @@ -148,6 +151,7 @@ Initial settings:
- attachmentsFolder: /Attachments
- ShowResources: true
- PublicCalendars: null
- AllowGroupSharing: false
`)
expect(settingsStore.$state).toEqual({
appVersion: '2.1.0',
Expand All @@ -174,6 +178,7 @@ Initial settings:
attachmentsFolder: '/Attachments',
attachmentsFolderCreated: false,
showResources: true,
allowGroupSharing: false,
publicCalendars: null,
searchQuery: '',
})
Expand Down
17 changes: 14 additions & 3 deletions tests/php/unit/Service/CalendarInitialStateServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Share\IManager as IShareManager;
use PHPUnit\Framework\MockObject\MockObject;

class CalendarInitialStateServiceTest extends TestCase {
Expand Down Expand Up @@ -61,6 +62,7 @@ class CalendarInitialStateServiceTest extends TestCase {

private IGroupManager&MockObject $groupManager;
private IUserManager&MockObject $userManager;
private IShareManager&MockObject $shareManager;

protected function setUp(): void {
$this->appName = 'calendar';
Expand All @@ -79,6 +81,9 @@ protected function setUp(): void {
}
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->shareManager = $this->createMock(IShareManager::class);
$this->shareManager->method('allowGroupSharing')
->willReturn(true);

$user = $this->createMock(IUser::class);
$this->userManager->method('get')
Expand All @@ -103,6 +108,7 @@ public function testRun(): void {
$this->queue,
$this->groupManager,
$this->userManager,
$this->shareManager,
);
$this->config->expects(self::exactly(18))
->method('getAppValue')
Expand Down Expand Up @@ -172,7 +178,7 @@ public function testRun(): void {
->willReturn([$this->createMock(IResourceBackend::class)]);
$this->roomManager->expects(self::never())
->method('getBackends');
$this->initialStateService->expects(self::exactly(29))
$this->initialStateService->expects(self::exactly(30))
->method('provideInitialState')
->willReturnMap([
['app_version', '1.0.0'],
Expand Down Expand Up @@ -203,6 +209,7 @@ public function testRun(): void {
['publicCalendars', null],
['calendar_federation_enabled', true],
['resource_booking_enabled', true],
['shareapi_allow_group_sharing', true],
['has_notify_push', $this->queue !== null],
]);

Expand All @@ -224,6 +231,7 @@ public function testRunAnonymously(): void {
$this->queue,
$this->groupManager,
$this->userManager,
$this->shareManager,
);
$this->config->expects(self::exactly(16))
->method('getAppValue')
Expand Down Expand Up @@ -286,7 +294,7 @@ public function testRunAnonymously(): void {
$this->roomManager->expects(self::once())
->method('getBackends')
->willReturn([]);
$this->initialStateService->expects(self::exactly(28))
$this->initialStateService->expects(self::exactly(29))
->method('provideInitialState')
->willReturnMap([
['app_version', '1.0.0'],
Expand Down Expand Up @@ -316,6 +324,7 @@ public function testRunAnonymously(): void {
['publicCalendars', null],
['calendar_federation_enabled', false],
['resource_booking_enabled', false],
['shareapi_allow_group_sharing', true],
['has_notify_push', $this->queue !== null],
]);

Expand Down Expand Up @@ -343,6 +352,7 @@ public function testIndexViewFix(string $savedView, string $expectedView): void
$this->queue,
$this->groupManager,
$this->userManager,
$this->shareManager,
);
$this->config->expects(self::exactly(18))
->method('getAppValue')
Expand Down Expand Up @@ -413,7 +423,7 @@ public function testIndexViewFix(string $savedView, string $expectedView): void
$this->roomManager->expects(self::once())
->method('getBackends')
->willReturn([$this->createMock(IRoomBackend::class)]);
$this->initialStateService->expects(self::exactly(29))
$this->initialStateService->expects(self::exactly(30))
->method('provideInitialState')
->willReturnMap([
['app_version', '1.0.0'],
Expand Down Expand Up @@ -444,6 +454,7 @@ public function testIndexViewFix(string $savedView, string $expectedView): void
['publicCalendars', null],
['calendar_federation_enabled', true],
['resource_booking_enabled', true],
['shareapi_allow_group_sharing', true],
['has_notify_push', $this->queue !== null],
]);

Expand Down
Loading