Skip to content

Commit

Permalink
frontend: implement acces token search and filtering restrictions edi…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
Synar committed Jul 13, 2024
1 parent 2bf2200 commit a111bec
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 49 deletions.
23 changes: 13 additions & 10 deletions frontend/components/viewer/FilterConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
<Tab value="0">
Général
</Tab>
<Tab value="1"
v-if="hasFilteringTags">
<Tab
v-if="hasFilteringTags"
value="1"
>
Tags
</Tab>
<Tab
Expand Down Expand Up @@ -77,8 +79,8 @@
</Button>
</div>
<div
class="filter-settings mt-2"
v-if="hasFilteringPrimaryTags"
class="filter-settings mt-2"
>
<span class="font-medium block mb-2">Filtres</span>
<div
Expand Down Expand Up @@ -111,8 +113,10 @@
</div>
</TabPanel>

<TabPanel value="1"
v-if="hasFilteringTags">
<TabPanel
v-if="hasFilteringTags"
value="1"
>
<span class="font-medium block mb-2">Tags</span>
<InputGroup
class="mb-6 mt-2"
Expand Down Expand Up @@ -201,23 +205,22 @@
</template>

<script setup lang="ts">
import type { Category, Tag, EnumFilter, PublicPermissions } from '~/lib'
import type { Category, Tag, EnumFilter } from '~/lib'
export interface Props {
maximumHeight?: string
filteringTags: (Tag & { active: boolean | null })[]
filteringCategories: (Category & { active: boolean })[]
filteringEnums: EnumFilter[]
permissions?: PublicPermissions
}
const props = withDefaults(defineProps<Props>(), {
maximumHeight: '350px',
})
const hasFilteringTags = computed(() => (!props.permissions || props.permissions.can_list_with_filters) && props.filteringTags.filter(tag => !tag.is_primary_filter).length > 0)
const hasFilteringPrimaryTags = computed(() => (!props.permissions || props.permissions.can_list_with_filters) && props.filteringTags.filter(tag => tag.is_primary_filter).length > 0)
const hasFilteringEnums = computed(() => (!props.permissions || props.permissions.can_list_with_enum_constraints) && props.filteringEnums.length > 0)
const hasFilteringTags = computed(() => props.filteringTags.filter(tag => !tag.is_primary_filter).length > 0)
const hasFilteringPrimaryTags = computed(() => props.filteringTags.filter(tag => tag.is_primary_filter).length > 0)
const hasFilteringEnums = computed(() => props.filteringEnums.length > 0)
const emit = defineEmits<{
(event: 'filtersChanged'): void
Expand Down
2 changes: 0 additions & 2 deletions frontend/components/viewer/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@
<Popover ref="filterOp">
<ViewerFilterConfig
:permissions = "state.permissions!"
v-model:filteringTags="state.filteringTags"
v-model:filteringCategories="state.filteringCategories"
v-model:filteringEnums="state.filteringEnums"
Expand All @@ -228,7 +227,6 @@
modal
>
<ViewerFilterConfig
:permissions = "state.permissions!"
v-model:filteringTags="state.filteringTags"
v-model:filteringCategories="state.filteringCategories"
v-model:filteringEnums="state.filteringEnums"
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export type ErrorResponse = api.components['schemas']['ErrorResponse']

export type NewOrUpdateCategory = api.components['schemas']['NewOrUpdateCategory']
export type NewOrUpdateTag = api.components['schemas']['NewOrUpdateTag']
export type NewOrUpdateAccessToken = api.components['schemas']['NewOrUpdateAccessToken'] & { permissions: Permissions }
export type PermissionPolicy = api.components['schemas']['PermissionPolicy']
export type Permissions = api.components['schemas']['Permissions']
export type NewOrUpdateAccessToken = api.components['schemas']['NewOrUpdateAccessToken'] & { permissions: Permissions }
export type AccessToken = api.components['schemas']['AccessToken']
& {
permissions: Permissions & { geographic_restrictions: null | [number, number][][] }
Expand Down
62 changes: 32 additions & 30 deletions frontend/lib/viewer-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,26 @@ export class AppState {
}
})

this.filteringEnums = family.entity_form.fields
.filter(
f => f.indexed
&& !f.privately_indexed
&& (f.field_type === 'EnumMultiOption' || f.field_type === 'EnumSingleOption'))
.map((f) => {
return {
key: f.key,
title: f.display_name,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
values: (f.field_type_metadata as any).options.map((v: any) => {
return {
label: v.label,
value: v.value,
}
}),
active: [],
}
})
if (this.permissions?.can_list_with_enum_constraints)
this.filteringEnums = family.entity_form.fields
.filter(
f => f.indexed
&& !f.privately_indexed
&& (f.field_type === 'EnumMultiOption' || f.field_type === 'EnumSingleOption'))
.map((f) => {
return {
key: f.key,
title: f.display_name,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
values: (f.field_type_metadata as any).options.map((v: any) => {
return {
label: v.label,
value: v.value,
}
}),
active: [],
}
})
}

get online() {
Expand Down Expand Up @@ -266,15 +267,16 @@ export class AppState {
}
})

this.filteringTags = this.tagsData
.filter(tag => tag.allowed)
.filter(tag => tag.is_filter)
.map((tag) => {
return {
...tag,
active: tag.default_filter_status ? null : false,
}
})
if (this.permissions.can_list_with_filters)
this.filteringTags = this.tagsData
.filter(tag => tag.allowed)
.filter(tag => tag.is_filter)
.map((tag) => {
return {
...tag,
active: tag.default_filter_status ? null : false,
}
})

this.familiesData.forEach((family) => {
this.familiesLookupTable[family.id] = family
Expand Down Expand Up @@ -355,7 +357,7 @@ export class AppState {
)
}

async searchEntities(query: string, page: number, pageSize: number, require_locations?: boolean) : Promise<ViewerPaginatedCachedEntities>{
async searchEntities(query: string, page: number, pageSize: number, require_locations?: boolean): Promise<ViewerPaginatedCachedEntities> {
if (this.permissions?.can_list_without_query || query.length >= 4)
return await this.client.searchEntities(
query,
Expand All @@ -369,7 +371,7 @@ export class AppState {
require_locations ?? false,
)
else
return { entities: [], response_current_page: 0, total_pages: 0, total_results: 0, }
return { entities: [], response_current_page: 0, total_pages: 0, total_results: 0 }
}

getCategory(category_id: string) {
Expand Down
37 changes: 32 additions & 5 deletions frontend/pages/admin/access-tokens/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@

<Divider class="!my-2" />

<AdminInputSwitchField
id="list_entities"
v-model="editedAccessToken.permissions.can_list_without_query"
label="Permission de lister textuellement les entités avec une recherche vide"
helper-text="Si désactivée mais que le listage est activé, 4 caractères minimum seront nécessaires pour réaliser une recherche"
/>

<AdminInputSwitchField
id="list_entities"
v-model="editedAccessToken.permissions.can_list_with_filters"
label="Permission de filtrer les entités par tags"
/>

<AdminInputSwitchField
id="list_entities"
v-model="editedAccessToken.permissions.can_list_with_enum_constraints"
label="Permission de filtrer les entités par contraintes sur les réponses au formulaire d'entité"
/>

<Divider class="!my-2" />

<AdminInputPolicyPermissionField
v-model="editedAccessToken.permissions.families_policy"
:policy-name="'families_policy'"
Expand Down Expand Up @@ -147,11 +168,14 @@ const editedAccessToken: Ref<NewOrUpdateAccessToken> = ref(
? {
active: true,
permissions: {
can_list_entities: false,
can_access_entity: false,
can_add_entity: false,
can_access_comments: false,
can_add_comment: false,
can_list_entities: true,
can_access_entity: true,
can_add_entity: true,
can_access_comments: true,
can_add_comment: true,
can_list_without_query: true,
can_list_with_enum_constraints: true,
can_list_with_filters: true,
categories_policy: {
allow_all: true,
allow_list: [],
Expand Down Expand Up @@ -205,6 +229,9 @@ watch(
(newVal) => {
if (!newVal) {
editedAccessToken.value.permissions.can_access_entity = false
editedAccessToken.value.permissions.can_list_with_filters = false
editedAccessToken.value.permissions.can_list_without_query = false
editedAccessToken.value.permissions.can_list_with_enum_constraints = false
editedAccessToken.value.permissions.can_add_comment &&= editedAccessToken.value.permissions.can_add_entity
}
},
Expand Down
1 change: 0 additions & 1 deletion frontend/pages/search/[token].vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@
modal
>
<ViewerFilterConfig
:permissions = "state.permissions!"
v-model:filteringTags="state.filteringTags"
v-model:filteringCategories="state.filteringCategories"
v-model:filteringEnums="state.filteringEnums"
Expand Down

0 comments on commit a111bec

Please sign in to comment.