getGroupPluginManager(); $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy') ->setMethods(['respondToActions']) ->getMock(); $plugin->expects($this->any()) ->method('respondToActions') ->willReturn(GroupInterface::CREATE_GROUP); $plugin2 = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy') ->setMethods(['respondToActions']) ->getMock(); $plugin2->expects($this->any()) ->method('respondToActions') ->willReturn(GroupInterface::ADD_TO_GROUP); $pluginManager->register($plugin); $pluginManager->register($plugin2); $this->assertEquals($pluginManager->getImplementedActions(), GroupInterface::CREATE_GROUP | GroupInterface::ADD_TO_GROUP); $this->assertTrue($pluginManager->implementsActions(GroupInterface::CREATE_GROUP)); $this->assertTrue($pluginManager->implementsActions(GroupInterface::ADD_TO_GROUP)); } public function testCreateGroup(): void { $pluginManager = $this->getGroupPluginManager(); $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy') ->setMethods(['respondToActions', 'createGroup']) ->getMock(); $plugin->expects($this->any()) ->method('respondToActions') ->willReturn(GroupInterface::CREATE_GROUP); $plugin->expects($this->once()) ->method('createGroup') ->with( $this->equalTo('group') ); $pluginManager->register($plugin); $pluginManager->createGroup('group'); } public function testCreateGroupNotRegistered(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('No plugin implements createGroup in this LDAP Backend.'); $pluginManager = $this->getGroupPluginManager(); $pluginManager->createGroup('foo'); } public function testDeleteGroup(): void { $pluginManager = $this->getGroupPluginManager(); $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy') ->setMethods(['respondToActions', 'deleteGroup']) ->getMock(); $plugin->expects($this->any()) ->method('respondToActions') ->willReturn(GroupInterface::DELETE_GROUP); $plugin->expects($this->once()) ->method('deleteGroup') ->with( $this->equalTo('group') )->willReturn(true); $pluginManager->register($plugin); $this->assertTrue($pluginManager->deleteGroup('group')); } public function testDeleteGroupNotRegistered(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('No plugin implements deleteGroup in this LDAP Backend.'); $pluginManager = $this->getGroupPluginManager(); $pluginManager->deleteGroup('foo'); } public function testAddToGroup(): void { $pluginManager = $this->getGroupPluginManager(); $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy') ->setMethods(['respondToActions', 'addToGroup']) ->getMock(); $plugin->expects($this->any()) ->method('respondToActions') ->willReturn(GroupInterface::ADD_TO_GROUP); $plugin->expects($this->once()) ->method('addToGroup') ->with( $this->equalTo('uid'), $this->equalTo('gid') ); $pluginManager->register($plugin); $pluginManager->addToGroup('uid', 'gid'); } public function testAddToGroupNotRegistered(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('No plugin implements addToGroup in this LDAP Backend.'); $pluginManager = $this->getGroupPluginManager(); $pluginManager->addToGroup('foo', 'bar'); } public function testRemoveFromGroup(): void { $pluginManager = $this->getGroupPluginManager(); $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy') ->setMethods(['respondToActions', 'removeFromGroup']) ->getMock(); $plugin->expects($this->any()) ->method('respondToActions') ->willReturn(GroupInterface::REMOVE_FROM_GROUP); $plugin->expects($this->once()) ->method('removeFromGroup') ->with( $this->equalTo('uid'), $this->equalTo('gid') ); $pluginManager->register($plugin); $pluginManager->removeFromGroup('uid', 'gid'); } public function testRemoveFromGroupNotRegistered(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('No plugin implements removeFromGroup in this LDAP Backend.'); $pluginManager = $this->getGroupPluginManager(); $pluginManager->removeFromGroup('foo', 'bar'); } public function testCountUsersInGroup(): void { $pluginManager = $this->getGroupPluginManager(); $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy') ->setMethods(['respondToActions', 'countUsersInGroup']) ->getMock(); $plugin->expects($this->any()) ->method('respondToActions') ->willReturn(GroupInterface::COUNT_USERS); $plugin->expects($this->once()) ->method('countUsersInGroup') ->with( $this->equalTo('gid'), $this->equalTo('search') ); $pluginManager->register($plugin); $pluginManager->countUsersInGroup('gid', 'search'); } public function testCountUsersInGroupNotRegistered(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('No plugin implements countUsersInGroup in this LDAP Backend.'); $pluginManager = $this->getGroupPluginManager(); $pluginManager->countUsersInGroup('foo', 'bar'); } public function testgetGroupDetails(): void { $pluginManager = $this->getGroupPluginManager(); $plugin = $this->getMockBuilder('OCA\User_LDAP\Tests\LDAPGroupPluginDummy') ->setMethods(['respondToActions', 'getGroupDetails']) ->getMock(); $plugin->expects($this->any()) ->method('respondToActions') ->willReturn(GroupInterface::GROUP_DETAILS); $plugin->expects($this->once()) ->method('getGroupDetails') ->with( $this->equalTo('gid') ); $pluginManager->register($plugin); $pluginManager->getGroupDetails('gid'); } public function testgetGroupDetailsNotRegistered(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('No plugin implements getGroupDetails in this LDAP Backend.'); $pluginManager = $this->getGroupPluginManager(); $pluginManager->getGroupDetails('foo'); } } /option> Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/unified-search.ts
blob: a13b1036da19869b2d47967e6ee8a6e6370ed17e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import { getLoggerBuilder } from '@nextcloud/logger'
import { getCSPNonce } from '@nextcloud/auth'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
import { createPinia, PiniaVuePlugin } from 'pinia'
import Vue from 'vue'

import UnifiedSearch from './views/UnifiedSearch.vue'
import { useSearchStore } from '../src/store/unified-search-external-filters.js'

// eslint-disable-next-line camelcase
__webpack_nonce__ = getCSPNonce()

const logger = getLoggerBuilder()
	.setApp('unified-search')
	.detectUser()
	.build()

Vue.mixin({
	data() {
		return {
			logger,
		}
	},
	methods: {
		t,
		n,
	},
})

// Define type structure for unified searc action
interface UnifiedSearchAction {
    id: string;
    appId: string;
	searchFrom: string;
    label: string;
    icon: string;
    callback: () => void;
}

// Register the add/register filter action API globally
window.OCA = window.OCA || {}
window.OCA.UnifiedSearch = {
	registerFilterAction: ({ id, appId, searchFrom, label, callback, icon }: UnifiedSearchAction) => {
		const searchStore = useSearchStore()
		searchStore.registerExternalFilter({ id, appId, searchFrom, label, callback, icon })
	},
}

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

export default new Vue({
	el: '#unified-search',
	pinia,
	// eslint-disable-next-line vue/match-component-file-name
	name: 'UnifiedSearchRoot',
	render: h => h(UnifiedSearch),
})