Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability check for full-text search #9087

Merged
merged 1 commit into from
May 24, 2023
Merged
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
1 change: 1 addition & 0 deletions changelog/unreleased/enhancement-search-fulltext-filter
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Enhancement: Search full-text filter
The search result page now has a full-text filter which can be used to filter the displayed files by their content.

https://github.com/owncloud/web/pull/9059
https://github.com/owncloud/web/pull/9087
https://github.com/owncloud/web/issues/9058
5 changes: 4 additions & 1 deletion packages/web-app-files/src/components/Search/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</template>
</item-filter>
<item-filter-toggle
v-if="fullTextSearchEnabled"
:filter-label="$gettext('Search in file content')"
filter-name="fullText"
class="files-search-filter-full-text oc-mr-s"
Expand Down Expand Up @@ -131,7 +132,7 @@ import { configurationManager } from 'web-pkg/src/configuration'
import { basename } from 'path'
import { onBeforeRouteLeave } from 'vue-router'
import { useTask } from 'vue-concurrency'
import { eventBus } from 'web-pkg'
import { eventBus, useCapabilityFilesFullTextSearch } from 'web-pkg'
import ItemFilter from 'web-pkg/src/components/ItemFilter.vue'
import { isLocationCommonActive } from 'web-app-files/src/router'
import ItemFilterToggle from 'web-pkg/src/components/ItemFilterToggle.vue'
Expand Down Expand Up @@ -177,6 +178,7 @@ export default defineComponent({
const { y: fileListHeaderY } = useFileListHeaderPosition()
const clientService = useClientService()
const hasTags = useCapabilityFilesTags()
const fullTextSearchEnabled = useCapabilityFilesFullTextSearch()

const searchTermQuery = useRouteQuery('term')
const searchTerm = computed(() => {
Expand Down Expand Up @@ -261,6 +263,7 @@ export default defineComponent({
...useResourcesViewDefaults<Resource, any, any[]>(),
loadAvailableTagsTask,
fileListHeaderY,
fullTextSearchEnabled,
getSpace,
availableTags,
tagFilter
Expand Down
17 changes: 12 additions & 5 deletions packages/web-app-files/tests/unit/components/Search/List.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ describe('List component', () => {
})
})
describe('fullText', () => {
it('should render filter', () => {
const { wrapper } = getWrapper()
it('should render filter if enabled via capabilities', () => {
const { wrapper } = getWrapper({ fullTextSearchEnabled: true })
expect(wrapper.find(selectors.fullTextFilter).exists()).toBeTruthy()
})
it('should set initial filter when fullText is set active via query param', async () => {
const searchTerm = 'term'
const { wrapper } = getWrapper({ searchTerm, fullTextFilterQuery: 'true' })
const { wrapper } = getWrapper({
searchTerm,
fullTextFilterQuery: 'true',
fullTextSearchEnabled: true
})
await wrapper.vm.loadAvailableTagsTask.last
expect(wrapper.emitted('search')[0][0]).toEqual(`Content:"${searchTerm}"`)
})
Expand All @@ -82,7 +86,8 @@ function getWrapper({
resources = [],
searchTerm = '',
tagFilterQuery = null,
fullTextFilterQuery = null
fullTextFilterQuery = null,
fullTextSearchEnabled = false
} = {}) {
jest.mocked(queryItemAsString).mockImplementationOnce(() => searchTerm)
jest.mocked(queryItemAsString).mockImplementationOnce(() => fullTextFilterQuery)
Expand All @@ -98,7 +103,9 @@ function getWrapper({
mockAxiosResolve({ value: availableTags })
)
const storeOptions = defaultStoreMockOptions
storeOptions.getters.capabilities.mockReturnValue({ files: { tags: true } })
storeOptions.getters.capabilities.mockReturnValue({
files: { tags: true, full_text_search: fullTextSearchEnabled }
})
const store = createStore(storeOptions)
return {
mocks,
Expand Down
4 changes: 4 additions & 0 deletions packages/web-pkg/src/composables/capability/useCapability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export const useCapabilityFilesAppProviders = createCapabilityComposable<AppProv
'files.app_providers',
[]
)
export const useCapabilityFilesFullTextSearch = createCapabilityComposable(
'files.full_text_search',
false
)
export const useCapabilityFilesSharingCanDenyAccess = createCapabilityComposable(
'files_sharing.deny_access',
false
Expand Down