From 8232e4e98e1fffbd9246a0ef4193fe86fbc43091 Mon Sep 17 00:00:00 2001 From: Martin Weise <martin.weise@tuwien.ac.at> Date: Sat, 25 Jan 2025 19:29:27 +0100 Subject: [PATCH] Refactored Signed-off-by: Martin Weise <martin.weise@tuwien.ac.at> --- dbrepo-ui/components/JumboBox.vue | 1 + dbrepo-ui/components/Loading.vue | 1 + dbrepo-ui/components/OntologiesList.vue | 64 ------------------- dbrepo-ui/components/ResourceStatus.vue | 1 + .../components/database/DatabaseToolbar.vue | 27 +++----- dbrepo-ui/components/identifier/Banner.vue | 1 + dbrepo-ui/components/identifier/Persist.vue | 37 ++++++----- dbrepo-ui/components/identifier/Select.vue | 13 +--- dbrepo-ui/components/subset/Builder.vue | 5 -- dbrepo-ui/components/subset/SubsetToolbar.vue | 13 ++-- dbrepo-ui/components/table/TableList.vue | 7 -- dbrepo-ui/components/table/TableToolbar.vue | 48 +++++++------- dbrepo-ui/components/user/UserToolbar.vue | 2 +- dbrepo-ui/components/view/ViewToolbar.vue | 31 +++++---- dbrepo-ui/composables/user-service.ts | 5 +- dbrepo-ui/layouts/default.vue | 57 +++++++++-------- dbrepo-ui/nuxt.config.ts | 30 ++++----- dbrepo-ui/package.json | 2 +- dbrepo-ui/pages/container/index.vue | 6 +- .../pages/database/[database_id]/info.vue | 7 +- .../persist/[identifier_id]/index.vue | 12 ++-- .../database/[database_id]/persist/index.vue | 14 ++-- .../pages/database/[database_id]/settings.vue | 16 +++-- .../[database_id]/subset/[subset_id]/data.vue | 4 -- .../[database_id]/subset/[subset_id]/info.vue | 8 ++- .../persist/[identifier_id]/index.vue | 9 +-- .../subset/[subset_id]/persist/index.vue | 6 -- .../database/[database_id]/subset/create.vue | 15 +---- .../database/[database_id]/subset/index.vue | 5 +- .../[database_id]/table/[table_id]/data.vue | 30 +++------ .../[database_id]/table/[table_id]/import.vue | 10 +-- .../[database_id]/table/[table_id]/info.vue | 35 +++++----- .../persist/[identifier_id]/index.vue | 9 +-- .../[database_id]/table/[table_id]/schema.vue | 19 ++++-- .../table/[table_id]/settings.vue | 32 +++------- .../[database_id]/table/create/dataset.vue | 9 +-- .../[database_id]/table/create/schema.vue | 9 +-- .../database/[database_id]/table/index.vue | 5 +- .../[database_id]/view/[view_id]/data.vue | 17 ++--- .../[database_id]/view/[view_id]/info.vue | 28 ++++---- .../persist/[identifier_id]/index.vue | 9 +-- .../view/[view_id]/persist/index.vue | 6 +- .../[database_id]/view/[view_id]/schema.vue | 24 ++++--- .../[database_id]/view/[view_id]/settings.vue | 29 ++++----- .../database/[database_id]/view/create.vue | 9 +-- .../database/[database_id]/view/index.vue | 5 +- dbrepo-ui/pages/index.vue | 14 +--- dbrepo-ui/pages/search.vue | 12 ---- dbrepo-ui/pages/user/authentication.vue | 6 +- dbrepo-ui/pages/user/index.vue | 3 - dbrepo-ui/pages/user/info.vue | 32 ++++------ dbrepo-ui/stores/cache.js | 14 ++-- 52 files changed, 319 insertions(+), 494 deletions(-) delete mode 100644 dbrepo-ui/components/OntologiesList.vue diff --git a/dbrepo-ui/components/JumboBox.vue b/dbrepo-ui/components/JumboBox.vue index d2b804f819..5a26ec6139 100644 --- a/dbrepo-ui/components/JumboBox.vue +++ b/dbrepo-ui/components/JumboBox.vue @@ -21,6 +21,7 @@ </v-row> </div> </template> + <script> export default { props: { diff --git a/dbrepo-ui/components/Loading.vue b/dbrepo-ui/components/Loading.vue index 743701ab67..84094bfef8 100644 --- a/dbrepo-ui/components/Loading.vue +++ b/dbrepo-ui/components/Loading.vue @@ -7,6 +7,7 @@ indeterminate /> </v-list-item-title> </template> + <script> export default { props: { diff --git a/dbrepo-ui/components/OntologiesList.vue b/dbrepo-ui/components/OntologiesList.vue deleted file mode 100644 index 432d26e428..0000000000 --- a/dbrepo-ui/components/OntologiesList.vue +++ /dev/null @@ -1,64 +0,0 @@ -<template> - <div> - <v-card - v-for="(ontology, idx) in ontologies" - :key="idx" - :to="`/semantic/ontology/${ontology.id}`" - variant="flat" - rounded="0"> - <v-divider - class="mx-4" /> - <v-card-title> - {{ ontology.prefix }} - </v-card-title> - <v-card-subtitle> - {{ ontology.uri }} - </v-card-subtitle> - <v-card-text> - <div - class="db-tags"> - <v-chip - v-if="ontology.sparql" - size="small" - color="success" - text="SPARQL" - variant="outlined" /> - <v-chip - v-if="ontology.rdf" - size="small" - text="RDF" - variant="outlined" /> - </div> - </v-card-text> - </v-card> - </div> -</template> - -<script setup> -</script> -<script> -import { useCacheStore } from '@/stores/cache.js' - -export default { - data () { - return { - cacheStore: useCacheStore() - } - }, - computed: { - ontologies () { - return [] - } - }, - mounted () { - }, - methods: { - } -} -</script> - -<style> -.db-tags .v-chip:not(:first-child) { - margin-left: 4px; -} -</style> diff --git a/dbrepo-ui/components/ResourceStatus.vue b/dbrepo-ui/components/ResourceStatus.vue index 5167d899ea..d766f37660 100644 --- a/dbrepo-ui/components/ResourceStatus.vue +++ b/dbrepo-ui/components/ResourceStatus.vue @@ -14,6 +14,7 @@ </span> </span> </template> + <script> export default { props: { diff --git a/dbrepo-ui/components/database/DatabaseToolbar.vue b/dbrepo-ui/components/database/DatabaseToolbar.vue index 9d43b262e3..a606bfd2dc 100644 --- a/dbrepo-ui/components/database/DatabaseToolbar.vue +++ b/dbrepo-ui/components/database/DatabaseToolbar.vue @@ -81,13 +81,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import { useCacheStore } from '@/stores/cache.js' import ResourceStatus from '@/components/ResourceStatus.vue' @@ -110,6 +103,12 @@ export default { access () { return this.cacheStore.getAccess }, + roles () { + return this.cacheStore.getRoles + }, + cacheUser () { + return this.cacheStore.getUser + }, isContrastTheme () { return this.$vuetify.theme.global.name.toLowerCase().endsWith('contrast') }, @@ -140,12 +139,6 @@ export default { } return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' }, - canImportCsv () { - if (!this.user || !this.hasWriteAccess) { - return false - } - return this.roles.includes('insert-table-data') - }, canCreateSubset () { if (!this.database) { return false @@ -156,22 +149,22 @@ export default { return this.hasReadAccess }, canCreateView () { - if (!this.user || !this.isOwner) { + if (!this.cacheUser || !this.isOwner) { return false } return this.roles.includes('create-database-view') }, canCreateTable () { - if (!this.user || !this.hasWriteAccess) { + if (!this.cacheUser || !this.hasWriteAccess) { return false } return this.roles.includes('create-table') }, isOwner () { - if (!this.database || !this.user) { + if (!this.database || !this.cacheUser) { return false } - return this.database.owner.id === this.userInfo.uid + return this.database.owner.id === this.cacheUser.uid }, buttonVariant () { const runtimeConfig = useRuntimeConfig() diff --git a/dbrepo-ui/components/identifier/Banner.vue b/dbrepo-ui/components/identifier/Banner.vue index 1450347c41..7c77a1b28b 100644 --- a/dbrepo-ui/components/identifier/Banner.vue +++ b/dbrepo-ui/components/identifier/Banner.vue @@ -3,6 +3,7 @@ {{ prefix }}: <a :href="href">{{ displayName }}</a> </div> </template> + <script> export default { props: { diff --git a/dbrepo-ui/components/identifier/Persist.vue b/dbrepo-ui/components/identifier/Persist.vue index 408d7e8265..b02ff09b76 100644 --- a/dbrepo-ui/components/identifier/Persist.vue +++ b/dbrepo-ui/components/identifier/Persist.vue @@ -827,13 +827,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import { formatYearUTC, formatMonthUTC, formatDayUTC, languages } from '@/utils' import { useCacheStore } from '@/stores/cache.js' @@ -972,6 +965,12 @@ export default { } }, computed: { + cacheUser () { + return this.cacheStore.getUser + }, + roles () { + return this.cacheStore.getRoles + }, isSubset () { return this.type === 'subset' }, @@ -1045,19 +1044,19 @@ export default { } }, canInsertSelf () { - if (!this.user) { + if (!this.cacheUser) { return false } - return this.user.given_name || this.user.family_name || this.user.attributes.affiliation || this.user.attributes.orcid + return this.cacheUser.given_name || this.cacheUser.family_name || this.cacheUser.attributes.affiliation || this.cacheUser.attributes.orcid }, isCreator () { - if (!this.user || !this.identifier) { + if (!this.cacheUser || !this.identifier) { return false } - if (!this.identifier.creator) { + if (!this.identifier.owner) { return true } - return this.identifier.creator.id === this.user.id + return this.identifier.owner.id === this.cacheUser.uid }, formValid () { /* somehow Vue3/Vuetify3 validation form is broken for arrays */ @@ -1119,10 +1118,10 @@ export default { return this.roles.includes('create-identifier') && !this.isPublished }, canRemove () { - if (!this.roles || !this.identifier || !this.identifier.creator || !this.user) { + if (!this.roles || !this.identifier || !this.identifier.owner || !this.cacheUser) { return false } - return this.roles.includes('delete-identifier') && this.identifier.creator.id === this.user.id && !this.isPublished + return this.roles.includes('delete-identifier') && this.identifier.owner.id === this.cacheUser.uid && !this.isPublished }, canPublish () { if (!this.roles || !this.identifier || !this.roles.includes('publish-identifier') || this.isPublished || !this.identifier.id) { @@ -1490,15 +1489,15 @@ export default { if (this.isPublished) { return false } - if (this.user.attributes.orcid) { - creator.name_identifier = this.user.attributes.orcid + if (this.cacheUser.attributes.orcid) { + creator.name_identifier = this.cacheUser.attributes.orcid this.retrieveCreator(creator) return } - creator.firstname = this.user.given_name - creator.lastname = this.user.family_name + creator.firstname = this.cacheUser.given_name + creator.lastname = this.cacheUser.family_name creator.creator_name = (creator.lastname ? creator.lastname + ', ' : '') + creator.firstname - creator.affiliation = this.user.attributes.affiliation + creator.affiliation = this.cacheUser.attributes.affiliation }, canShiftUp (creator, idx) { if (this.isPublished) { diff --git a/dbrepo-ui/components/identifier/Select.vue b/dbrepo-ui/components/identifier/Select.vue index 84f87e321f..ca5f3ce21e 100644 --- a/dbrepo-ui/components/identifier/Select.vue +++ b/dbrepo-ui/components/identifier/Select.vue @@ -41,16 +41,8 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Banner from '@/components/identifier/Banner.vue' -import { formatTimestampUTCLabel } from '@/utils' import { useCacheStore } from '@/stores/cache.js' export default { @@ -82,10 +74,10 @@ export default { if (!this.identifiers) { return [] } - if (!this.user) { + if (!this.userInfo) { return this.identifiers.filter(i => i.status === 'published') } - return this.identifiers.filter(i => i.status === 'published' || i.owner.id === this.user.id) + return this.identifiers.filter(i => i.status === 'published' || i.owner.id === this.userInfo.uid) }, listVariant () { const runtimeConfig = useRuntimeConfig() @@ -104,7 +96,6 @@ export default { this.init() }, methods: { - formatTimestampUTCLabel, href (identifier) { if (identifier.status === 'published') { return `/pid/${identifier.id}` diff --git a/dbrepo-ui/components/subset/Builder.vue b/dbrepo-ui/components/subset/Builder.vue index ae7df27683..4261b098b6 100644 --- a/dbrepo-ui/components/subset/Builder.vue +++ b/dbrepo-ui/components/subset/Builder.vue @@ -304,11 +304,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -</script> <script> import TimeDrift from '@/components/TimeDrift.vue' import Raw from '@/components/subset/Raw.vue' diff --git a/dbrepo-ui/components/subset/SubsetToolbar.vue b/dbrepo-ui/components/subset/SubsetToolbar.vue index 45ca762628..61e26e9967 100644 --- a/dbrepo-ui/components/subset/SubsetToolbar.vue +++ b/dbrepo-ui/components/subset/SubsetToolbar.vue @@ -55,12 +55,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -</script> <script> import DownloadButton from '@/components/identifier/DownloadButton.vue' import { formatTimestampUTCLabel } from '@/utils' @@ -95,6 +89,9 @@ export default { subset () { return this.cacheStore.getSubset }, + cacheUser () { + return this.cacheStore.getUser + }, identifiers () { if (!this.subset) { return [] @@ -152,10 +149,10 @@ export default { return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' }, canGetPid () { - if (!this.userInfo || !this.subset || !this.database) { + if (!this.cacheUser || !this.subset || !this.database) { return false } - return this.database.owner.id === this.userInfo.uid || (this.subset.owner.id === this.userInfo.uid && this.hasReadAccess) + return this.database.owner.id === this.cacheUser.uid || (this.subset.owner.id === this.cacheUser.uid && this.hasReadAccess) }, title () { if (!this.identifier) { diff --git a/dbrepo-ui/components/table/TableList.vue b/dbrepo-ui/components/table/TableList.vue index d34483422d..71106f7c65 100644 --- a/dbrepo-ui/components/table/TableList.vue +++ b/dbrepo-ui/components/table/TableList.vue @@ -38,13 +38,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import { formatTimestampUTCLabel } from '@/utils' import { useCacheStore } from '@/stores/cache.js' diff --git a/dbrepo-ui/components/table/TableToolbar.vue b/dbrepo-ui/components/table/TableToolbar.vue index 9aee22348f..e09cd67cba 100644 --- a/dbrepo-ui/components/table/TableToolbar.vue +++ b/dbrepo-ui/components/table/TableToolbar.vue @@ -77,13 +77,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import EditTuple from '@/components/dialogs/EditTuple.vue' import { useCacheStore } from '@/stores/cache.js' @@ -112,31 +105,40 @@ export default { access () { return this.cacheStore.getAccess }, + cacheUser () { + return this.cacheStore.getUser + }, + roles () { + return this.cacheStore.getRoles + }, hasReadAccess () { if (!this.access) { return false } - return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' + const userService = useUserService() + return userService.hasReadAccess(this.access) }, canUpdateTable () { - if (!this.roles || !this.user || !this.table) { + if (!this.roles || !this.cacheUser || !this.table) { return false } - return this.roles.includes('update-table') && this.table.owner.id === this.userInfo.uid + return this.roles.includes('update-table') && this.table.owner.id === this.cacheUser.uid }, canExecuteQuery () { - if (!this.roles || !this.table || !this.user) { + if (!this.roles || !this.table || !this.cacheUser) { return false } - const userService = useUserService() - return userService.hasReadAccess(this.access) && this.roles.includes('execute-query') + return this.hasReadAccess && this.roles.includes('execute-query') + }, + isOwner () { + const databaseService = useDatabaseService() + return databaseService.isOwner(this.database, this.cacheUser) }, canCreateView () { - if (!this.roles || !this.table || !this.user) { + if (!this.roles || !this.table || !this.cacheUser) { return false } - const databaseService = useDatabaseService() - return databaseService.isOwner(this.database, this.user) && this.roles.includes('create-database-view') + return this.isOwner && this.roles.includes('create-database-view') }, canViewData () { if (!this.table) { @@ -145,10 +147,10 @@ export default { if (this.table.is_public) { return true } - if (!this.user) { + if (!this.cacheUser) { return false } - return this.hasReadAccess || this.table.owner.id === this.userInfo.uid || this.database.owner.id === this.userInfo.uid + return this.hasReadAccess || this.table.owner.id === this.cacheUser.uid || this.database.owner.id === this.cacheUser.uid }, canViewSchema () { if (!this.table) { @@ -157,22 +159,22 @@ export default { if (this.table.is_schema_public) { return true } - if (!this.user) { + if (!this.cacheUser) { return false } - return this.hasReadAccess || this.table.owner.id === this.userInfo.uid || this.database.owner.id === this.userInfo.uid + return this.hasReadAccess || this.table.owner.id === this.cacheUser.uid || this.database.owner.id === this.cacheUser.uid }, canImportCsv () { - if (!this.roles || !this.table || !this.user) { + if (!this.roles || !this.table || !this.cacheUser) { return false } return this.roles.includes('insert-table-data') }, canGetPid () { - if (!this.user || !this.table || !this.database) { + if (!this.cacheUser || !this.table || !this.database) { return false } - return this.database.owner.id === this.userInfo.uid || this.table.owner.id === this.userInfo.uid + return this.hasReadAccess && this.database.owner.id === this.cacheUser.uid || this.table.owner.id === this.cacheUser.uid }, buttonVariant () { const runtimeConfig = useRuntimeConfig() diff --git a/dbrepo-ui/components/user/UserToolbar.vue b/dbrepo-ui/components/user/UserToolbar.vue index 868bab88a9..54210130d3 100644 --- a/dbrepo-ui/components/user/UserToolbar.vue +++ b/dbrepo-ui/components/user/UserToolbar.vue @@ -21,7 +21,7 @@ </template> <script setup> -const { loggedIn, user, login, logout } = useOidcAuth() +const { loggedIn } = useOidcAuth() </script> <script> export default { diff --git a/dbrepo-ui/components/view/ViewToolbar.vue b/dbrepo-ui/components/view/ViewToolbar.vue index 74eac9dedf..d9e0bfb6bf 100644 --- a/dbrepo-ui/components/view/ViewToolbar.vue +++ b/dbrepo-ui/components/view/ViewToolbar.vue @@ -56,13 +56,6 @@ </v-toolbar> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import { useCacheStore } from '@/stores/cache.js' import CreateOntology from '@/components/dialogs/CreateOntology.vue' @@ -96,6 +89,12 @@ export default { view () { return this.cacheStore.getView }, + cacheUser () { + return this.cacheStore.getUser + }, + roles () { + return this.cacheStore.getRoles + }, canViewData () { if (!this.view) { return false @@ -103,10 +102,10 @@ export default { if (this.view.is_public) { return true } - if (!this.user) { + if (!this.cacheUser) { return false } - return this.hasReadAccess || this.view.owner.id === this.userInfo.id || this.database.owner.id === this.userInfo.id + return this.hasReadAccess || this.view.owner.id === this.cacheUser.uid || this.database.owner.id === this.cacheUser.uid }, canViewSchema () { if (!this.view) { @@ -115,23 +114,23 @@ export default { if (this.view.is_schema_public) { return true } - if (!this.user) { + if (!this.cacheUser) { return false } - return this.hasReadAccess || this.view.owner.id === this.userInfo.id || this.database.owner.id === this.userInfo.id + return this.hasReadAccess || this.view.owner.id === this.cacheUser.uid || this.database.owner.id === this.cacheUser.uid }, canViewSettings () { - if (!this.user || !this.view) { + if (!this.cacheUser || !this.view) { return false } - return this.view.owner.id === this.userInfo.id + return this.view.owner.id === this.cacheUser.uid }, canCreatePid () { - if (!this.roles || !this.user || !this.view) { + if (!this.roles || !this.cacheUser || !this.view) { return false } - const userService = useUserService() - return this.roles.includes('create-identifier') && userService.hasReadAccess(this.access) + const cacheUserService = useUserService() + return cacheUserService.hasReadAccess(this.access) && this.roles.includes('create-identifier') }, access () { return this.cacheStore.getAccess diff --git a/dbrepo-ui/composables/user-service.ts b/dbrepo-ui/composables/user-service.ts index 5381fee565..3425dbaa5c 100644 --- a/dbrepo-ui/composables/user-service.ts +++ b/dbrepo-ui/composables/user-service.ts @@ -141,13 +141,13 @@ export const useUserService = (): any => { } function hasWriteAccess(table: TableDto, access: DatabaseAccessDto, user: UserDto): boolean { - if (!table || !access) { + if (!table || !access || !user) { return false } if (access.type === 'write_all') { return true } - return access.type === 'write_own' && table.owner.id === user.id + return access.type === 'write_own' && table.owner.id === user.uid } return { @@ -156,7 +156,6 @@ export const useUserService = (): any => { update, create, updatePassword, - refreshToken, nameIdentifierToNameIdentifierScheme, userToFullName, hasReadAccess, diff --git a/dbrepo-ui/layouts/default.vue b/dbrepo-ui/layouts/default.vue index a08f6f70f5..816d74c26a 100644 --- a/dbrepo-ui/layouts/default.vue +++ b/dbrepo-ui/layouts/default.vue @@ -105,10 +105,10 @@ {{ $t('navigation.login') }} </v-btn> <v-btn - v-if="loggedIn" + v-if="cacheUser" to="/user" variant="plain" - :text="userInfo.preferred_username" /> + :text="cacheUser.preferred_username" /> <v-menu v-if="loggedIn" location="bottom"> @@ -119,19 +119,18 @@ </template> <v-list> <v-list-item - v-if="user" + v-if="cacheUser" exact - :to="`/search?type=database&owner.username=${user.username}`"> + :to="`/search?type=database&owner.username=${cacheUser.username}`"> {{ $t('navigation.databases') + ' ' + $t('navigation.mine')}} </v-list-item> <v-list-item - v-if="user" + v-if="cacheUser" exact - :to="`/search?type=identifier&identifiers.creator.username=${user.username}`"> + :to="`/search?type=identifier&identifiers.creator.username=${cacheUser.username}`"> {{ $t('navigation.identifiers') + ' ' + $t('navigation.mine') }} </v-list-item> <v-list-item - v-if="user" @click="logout()"> {{ $t('navigation.logout') }} </v-list-item> @@ -154,10 +153,12 @@ <script setup> import { ref } from 'vue' +import { useCacheStore } from '@/stores/cache.js' const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) +const cacheStore = useCacheStore() +cacheStore.setUser(loggedIn ? user.value?.userInfo : null) +cacheStore.setRoles(loggedIn ? user.value?.claims?.realm_access?.roles : []) const runtimeConfig = useRuntimeConfig() const config = ref(runtimeConfig) useServerHead({ @@ -173,7 +174,6 @@ import JumboBox from '@/components/JumboBox.vue' import { useCacheStore } from '@/stores/cache.js' import { errorCodeKey, makeError } from '@/utils' - export default { components: { JumboBox @@ -211,6 +211,12 @@ export default { database () { return this.cacheStore.getDatabase }, + access () { + return this.cacheStore.getAccess + }, + cacheUser () { + return this.cacheStore.getUser + }, resource () { if (!this.$route.params.database_id) { return null @@ -248,13 +254,13 @@ export default { if (!this.user) { return null } - if (this.table && !this.table.is_public && !this.table.is_schema_public && this.table.owner.id !== this.user.id) { + if (this.table && !this.table.is_public && !this.table.is_schema_public && this.table.owner.id !== this.cacheUser.uid) { return makeError(403, null, null) } - if (this.view && !this.view.is_public && !this.view.is_schema_public && this.view.owner.id !== this.user.id) { + if (this.view && !this.view.is_public && !this.view.is_schema_public && this.view.owner.id !== this.cacheUser.uid) { return makeError(403, null, null) } - if (this.subset && !this.subset.is_public && !this.subset.is_schema_public && this.subset.owner.id !== this.user.id) { + if (this.subset && !this.subset.is_public && !this.subset.is_schema_public && this.subset.owner.id !== this.cacheUser.uid) { return makeError(403, null, null) } return null @@ -266,10 +272,7 @@ export default { return this.roles.includes('list-ontologies') }, canListContainers () { - if (!this.roles) { - return false - } - return this.roles.includes('list-containers') + return this.cacheUser }, logo () { return this.$config.public.logo @@ -291,19 +294,18 @@ export default { this.cacheStore.setTable(null) this.cacheStore.setView(null) this.cacheStore.setSubset(null) + this.cacheStore.setAccess(null) return } if (import.meta.server) { return } /* load database and optional access */ + this.cacheStore.setRouteAccess(newObj.database_id, this.cacheUser?.uid) this.cacheStore.setRouteDatabase(newObj.database_id) .catch((error) => { this.databaseError = error }) - if (this.userInfo) { - this.cacheStore.setRouteAccess(newObj.database_id, this.userInfo.uid) - } /* load table */ if (newObj.table_id) { this.cacheStore.setRouteTable(newObj.database_id, newObj.table_id) @@ -328,14 +330,14 @@ export default { } }, mounted () { - this.initEnvironment() if (this.$route.query && this.$route.query.q) { this.search = this.$route.query.q } - if (!this.user) { + if (!this.cacheUser) { return } this.setTheme() + this.setLocale() this.cacheStore.reloadMessages() }, methods: { @@ -343,7 +345,7 @@ export default { console.debug('performing fuzzy search') this.$router.push({ path: '/search', query: { q: this.search } }) }, - initEnvironment () { + setLocale () { if (!this.locale) { this.cacheStore.setLocale('en') return @@ -351,7 +353,10 @@ export default { this.$i18n.locale = this.locale }, setTheme () { - switch (this.user.attributes.theme) { + if (!this.cacheUser?.attributes?.theme) { + return + } + switch (this.cacheUser.attributes.theme) { case 'dark': this.$vuetify.theme.global.name = 'tuwThemeDark' break @@ -365,10 +370,6 @@ export default { this.$vuetify.theme.global.name = 'tuwThemeDarkContrast' break } - }, - setLocale (code) { - this.cacheStore.setLocale(code) - this.$i18n.locale = this.locale } } } diff --git a/dbrepo-ui/nuxt.config.ts b/dbrepo-ui/nuxt.config.ts index 305a753d9e..0f2099a387 100644 --- a/dbrepo-ui/nuxt.config.ts +++ b/dbrepo-ui/nuxt.config.ts @@ -3,19 +3,19 @@ import vuetify from 'vite-plugin-vuetify' const proxy: any = {} -/* proxies the backend calls, >>NOT<< the frontend calls (clicking) */ -if (process.env.NODE_ENV === 'development') { - const api = 'http://localhost' - proxy['/api'] = api - proxy['/pid'] = { - target: api + '/api', - changeOrigin: true, - pathRewrite: { - '^/pid': '/pid' - } - } - process.env.NUXT_PUBLIC_API_SERVER = api -} +// /* proxies the backend calls, >>NOT<< the frontend calls (clicking) */ +// if (process.env.NODE_ENV === 'development') { +// const api = 'http://localhost' +// proxy['/api'] = api +// proxy['/pid'] = { +// target: api + '/api', +// changeOrigin: true, +// pathRewrite: { +// '^/pid': '/pid' +// } +// } +// process.env.NUXT_PUBLIC_API_SERVER = api +// } /** * https://nuxt.com/docs/guide/concepts/rendering#hybrid-rendering @@ -116,10 +116,10 @@ export default defineNuxtConfig({ clientSecret: '', // inject on runtime scope: ['openid', 'roles'], optionalClaims: ['realm_access'], - redirectUri: 'http://localhost/auth/keycloak/callback', + redirectUri: 'http://localhost:3001/auth/keycloak/callback', userNameClaim: 'preferred_username', exposeAccessToken: true, - logoutRedirectUri: 'http://localhost', + logoutRedirectUri: 'http://localhost:3001', }, }, middleware: { diff --git a/dbrepo-ui/package.json b/dbrepo-ui/package.json index ec3ae1e6a4..7110d273f2 100644 --- a/dbrepo-ui/package.json +++ b/dbrepo-ui/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "build": "nuxt build", - "dev": "VERSION=bun-dev NODE_ENV=development nuxt dev", + "dev": "VERSION=bun-dev NUXT_OIDC_PROVIDERS_KEYCLOAK_CLIENT_SECRET=MUwRc7yfXSJwX8AdRMWaQC3Nep1VjwgG NODE_ENV=development nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", "postinstall": "nuxt prepare", diff --git a/dbrepo-ui/pages/container/index.vue b/dbrepo-ui/pages/container/index.vue index ec2149372e..20fed36801 100644 --- a/dbrepo-ui/pages/container/index.vue +++ b/dbrepo-ui/pages/container/index.vue @@ -1,5 +1,6 @@ <template> - <div> + <div + v-if="loggedIn"> <v-toolbar flat :title="$t('pages.container.title')"> @@ -11,6 +12,9 @@ </div> </template> +<script setup> +const { loggedIn } = useOidcAuth() +</script> <script> import ContainerList from '@/components/container/ContainerList.vue' diff --git a/dbrepo-ui/pages/database/[database_id]/info.vue b/dbrepo-ui/pages/database/[database_id]/info.vue index 33d63b29a9..9da8daab62 100644 --- a/dbrepo-ui/pages/database/[database_id]/info.vue +++ b/dbrepo-ui/pages/database/[database_id]/info.vue @@ -242,7 +242,7 @@ export default { if (!this.user) { return this.identifiers.filter(i => i.status === 'published') } - return this.identifiers.filter(i => i.status === 'published' || i.owner.id === this.user.id) + return this.identifiers.filter(i => i.status === 'published' || i.owner.id === this.userInfo.uid) }, identifier () { if (this.pid) { @@ -336,7 +336,10 @@ export default { if (this.error) { return false } - return this.database + if (!this.database) { + return false + } + return this.database.is_schema_public } } } diff --git a/dbrepo-ui/pages/database/[database_id]/persist/[identifier_id]/index.vue b/dbrepo-ui/pages/database/[database_id]/persist/[identifier_id]/index.vue index 2c2e5ef120..75f267944f 100644 --- a/dbrepo-ui/pages/database/[database_id]/persist/[identifier_id]/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/persist/[identifier_id]/index.vue @@ -8,12 +8,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Persist from '@/components/identifier/Persist.vue' import { useCacheStore } from '@/stores/cache.js' @@ -51,6 +45,12 @@ export default { database () { return this.cacheStore.getDatabase }, + roles () { + return this.cacheStore.getRoles + }, + cacheUser () { + return this.cacheStore.getUser + }, canCreateIdentifier () { if (!this.roles) { return false diff --git a/dbrepo-ui/pages/database/[database_id]/persist/index.vue b/dbrepo-ui/pages/database/[database_id]/persist/index.vue index a3581c0c82..570c5d9da5 100644 --- a/dbrepo-ui/pages/database/[database_id]/persist/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/persist/index.vue @@ -8,13 +8,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Persist from '@/components/identifier/Persist.vue' import { useCacheStore } from '@/stores/cache.js' @@ -48,6 +41,9 @@ export default { database () { return this.cacheStore.getDatabase }, + cacheUser () { + return this.cacheStore.getUser + }, hasIdentifier () { if (this.database && 'identifier' in this.database && this.database.identifier) { return 'id' in this.database.identifier @@ -55,10 +51,10 @@ export default { return false }, isOwner () { - if (!this.database || !this.userInfo) { + if (!this.database || !this.cacheUser) { return false } - return this.database.owner.id === this.userInfo.uid + return this.database.owner.id === this.cacheUser.uid }, canCreateIdentifier () { if (!this.roles || this.hasIdentifier) { diff --git a/dbrepo-ui/pages/database/[database_id]/settings.vue b/dbrepo-ui/pages/database/[database_id]/settings.vue index 5b0aa2a453..1d71474805 100644 --- a/dbrepo-ui/pages/database/[database_id]/settings.vue +++ b/dbrepo-ui/pages/database/[database_id]/settings.vue @@ -349,16 +349,16 @@ export default { if (!this.database || !this.user) { return false } - if (this.database.owner.id === null || this.user.id === null) { + if (this.database.owner.id === null || this.userInfo.uid === null) { return false } - return this.database.owner.id === this.user.id + return this.database.owner.id === this.userInfo.uid }, isSameOwner () { - if (!this.modifyOwner || !this.user) { + if (!this.modifyOwner || !this.userInfo) { return false } - return this.modifyOwner.id === this.user.id + return this.modifyOwner.id === this.userInfo.uid }, isSameVisibility () { if (!this.modifyVisibility || !this.database) { @@ -406,7 +406,13 @@ export default { if (this.error) { return false } - return this.database + if (!this.database) { + return false + } + if (!this.cacheUser) { + return false + } + return this.database.owner.id === this.cacheUser.uid }, previewImage () { if (this.file) { diff --git a/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/data.vue b/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/data.vue index e9719cd0ef..ee6d25eda7 100644 --- a/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/data.vue +++ b/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/data.vue @@ -139,10 +139,6 @@ export default { this.loadingSubset = false }) }, - loadResult () { - if (this.subset) { - } - }, download () { this.downloadLoading = true const queryService = useQueryService() diff --git a/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/info.vue b/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/info.vue index a9956278d1..eeb0a70c3e 100644 --- a/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/info.vue +++ b/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/info.vue @@ -50,7 +50,9 @@ v-if="subset.creator" :title="$t('pages.subset.creator.title')" density="compact"> - <UserBadge :user="subset.creator" :other-user="user" /> + <UserBadge + :user="subset.creator" + :other-user="cacheUser" /> </v-list-item> <v-list-item :title="$t('pages.subset.query.title')" @@ -143,8 +145,8 @@ export default { database () { return this.cacheStore.getDatabase }, - access () { - return this.cacheStore.getAccess + cacheUser () { + return this.cacheStore.getUser }, subset () { return this.cacheStore.getSubset diff --git a/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/persist/[identifier_id]/index.vue b/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/persist/[identifier_id]/index.vue index 0e1dac8c7e..65154f38a5 100644 --- a/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/persist/[identifier_id]/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/persist/[identifier_id]/index.vue @@ -8,12 +8,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Persist from '@/components/identifier/Persist.vue' import { useCacheStore } from '@/stores/cache.js' @@ -59,6 +53,9 @@ export default { database () { return this.cacheStore.getDatabase }, + roles () { + return this.cacheStore.getRoles + }, canCreateIdentifier () { if (!this.roles) { return false diff --git a/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/persist/index.vue b/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/persist/index.vue index cc0dbf4958..82a4ba5f70 100644 --- a/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/persist/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/subset/[subset_id]/persist/index.vue @@ -9,12 +9,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Persist from '@/components/identifier/Persist.vue' import { useCacheStore } from '@/stores/cache.js' diff --git a/dbrepo-ui/pages/database/[database_id]/subset/create.vue b/dbrepo-ui/pages/database/[database_id]/subset/create.vue index 2ea1c5022a..94fd8e8ec9 100644 --- a/dbrepo-ui/pages/database/[database_id]/subset/create.vue +++ b/dbrepo-ui/pages/database/[database_id]/subset/create.vue @@ -6,12 +6,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Builder from '@/components/subset/Builder.vue' import {useCacheStore} from '@/stores/cache.js' @@ -51,12 +45,6 @@ export default { access () { return this.cacheStore.getAccess }, - hasReadAccess () { - if (!this.access) { - return false - } - return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' - }, canCreateSubset () { if (!this.database) { return false @@ -64,7 +52,8 @@ export default { if (this.database.is_public) { return true } - return this.hasReadAccess + const userService = useUserService() + return userService.hasReadAccess(this.access) } } } diff --git a/dbrepo-ui/pages/database/[database_id]/subset/index.vue b/dbrepo-ui/pages/database/[database_id]/subset/index.vue index 2f68604881..93be3df024 100644 --- a/dbrepo-ui/pages/database/[database_id]/subset/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/subset/index.vue @@ -43,7 +43,10 @@ export default { if (this.error) { return false } - return this.database + if (!this.database) { + return false + } + return this.database.is_schema_public } } } diff --git a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/data.vue b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/data.vue index ca120e89f7..cf304cbf71 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/data.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/data.vue @@ -107,11 +107,7 @@ </template> <script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) +const { loggedIn } = useOidcAuth() </script> <script> import TableHistory from '@/components/table/TableHistory.vue' @@ -197,15 +193,12 @@ export default { table () { return this.cacheStore.getTable }, + roles () { + return this.cacheStore.getRoles + }, access () { return this.cacheStore.getAccess }, - hasReadAccess () { - if (!this.access) { - return false - } - return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' - }, title () { return (this.version ? this.$t('toolbars.database.history') : this.$t('toolbars.database.current')) + ' ' + this.versionFormatted }, @@ -230,15 +223,6 @@ export default { } return this.version.substring(0, 10) + 'T' + this.version.substring(11, 19) + 'Z' }, - canModify () { - if (!this.userInfo || !this.access || !this.table) { - return false - } - if (this.access.type === 'write_own' && this.table.owner.id === this.userInfo.uid) { - return true - } - return this.access.type === 'write_all' - }, primaryKeyColumns () { if (!this.table) { return [] @@ -258,7 +242,11 @@ export default { if (!this.roles || !this.roles.includes('view-table-data')) { return false } - return this.hasReadAccess + if (!this.access) { + return false + } + const userService = useUserService() + return userService.hasReadAccess(this.access) }, canAddTuple () { if (!this.roles) { diff --git a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/import.vue b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/import.vue index 46eb7106fd..1b54076c65 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/import.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/import.vue @@ -28,13 +28,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import TableImport from '@/components/table/TableImport.vue' import { useCacheStore } from '@/stores/cache.js' @@ -82,6 +75,9 @@ export default { table () { return this.cacheStore.getTable }, + roles () { + return this.cacheStore.getRoles + }, title () { if (!this.table) { return this.$t('pages.table.import.title') diff --git a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/info.vue b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/info.vue index ca295a5587..6ab884a826 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/info.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/info.vue @@ -64,7 +64,7 @@ :title="$t('pages.table.owner.title')"> <UserBadge :user="table.owner" - :other-user="user" /> + :other-user="cacheUser" /> </v-list-item> </v-list> </v-card-text> @@ -118,13 +118,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import TableToolbar from '@/components/table/TableToolbar.vue' import Select from '@/components/identifier/Select.vue' @@ -184,14 +177,21 @@ export default { table () { return this.cacheStore.getTable }, + cacheUser () { + return this.cacheStore.getUser + }, + roles () { + return this.cacheStore.getRoles + }, canRead () { if (this.database && this.database.is_public) { return true } - if (!this.user || !this.access) { + if (!this.access) { return false } - return this.access.type === 'read' || this.access.type === 'write_own' || this.access.type === 'write_all' + const userService = useUserService() + return userService.hasReadAccess(this.access) }, canViewSchema () { if (this.error) { @@ -203,16 +203,15 @@ export default { if (this.table.is_schema_public || this.table.is_public) { return true } - if (!this.userInfo) { + if (!this.cacheUser) { return false } - return this.hasReadAccess || this.table.owner.id === this.userInfo.uid || this.database.owner.id === this.userInfo.uid + const userService = useUserService() + return userService.hasReadAccess(this.access) || this.table.owner.id === this.cacheUser.uid || this.database.owner.id === this.cacheUser.uid }, canWrite () { - if (!this.table || !this.user || !this.access) { - return false - } - return (this.access.type === 'write_own' && this.table.owned_by === this.userInfo.uid) || this.access.type === 'write_all' + const userService = useUserService() + return userService.hasWriteAccess(this.table, this.access, this.cacheUser) }, access () { return this.cacheStore.getAccess @@ -236,10 +235,10 @@ export default { if (!this.identifiers) { return [] } - if (!this.userInfo) { + if (!this.cacheUser) { return this.identifiers.filter(i => i.status === 'published') } - return this.identifiers.filter(i => i.status === 'published' || i.owned_by === this.userInfo.uid) + return this.identifiers.filter(i => i.status === 'published' || i.owned_by === this.cacheUser.uid) }, identifier () { if (this.pid) { diff --git a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/persist/[identifier_id]/index.vue b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/persist/[identifier_id]/index.vue index 0e82a2210b..50c06f569a 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/persist/[identifier_id]/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/persist/[identifier_id]/index.vue @@ -6,12 +6,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Persist from '@/components/identifier/Persist.vue' import { useCacheStore } from '@/stores/cache.js' @@ -57,6 +51,9 @@ export default { database () { return this.cacheStore.getDatabase }, + roles () { + return this.cacheStore.getRoles + }, canCreateIdentifier () { if (!this.roles) { return false diff --git a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/schema.vue b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/schema.vue index 4cbb8d37d1..32a6dd9dad 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/schema.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/schema.vue @@ -123,9 +123,7 @@ <script setup> import { ref } from 'vue' -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) +const { loggedIn } = useOidcAuth() </script> <script> import TableToolbar from '@/components/table/TableToolbar.vue' @@ -187,6 +185,12 @@ export default { access () { return this.cacheStore.getAccess }, + cacheUser () { + return this.cacheStore.getUser + }, + roles () { + return this.cacheStore.getRoles + }, hasReadAccess () { if (!this.access) { return false @@ -203,16 +207,17 @@ export default { if (this.table.is_schema_public) { return true } - if (!this.userInfo) { + if (!this.cacheUser) { return false } - return this.hasReadAccess || this.table.owner.id === this.userInfo.uid || this.database.owner.id === this.userInfo.uid + const userService = useUserService() + return userService.hasReadAccess(this.access) || this.table.owner.id === this.cacheUser.uid || this.database.owner.id === this.cacheUser.uid }, primaryKeysColumns () { return this.table.constraints.primary_key.map(pk => pk.column.internal_name).join(', ') }, canAssignSemanticInformation () { - if (!this.userInfo) { + if (!this.cacheUser) { return false } if (this.roles.includes('modify-foreign-table-column-semantics')) { @@ -221,7 +226,7 @@ export default { if (!this.access) { return false } - return this.roles.includes('modify-table-column-semantics') && (this.access.type === 'write_all' || this.table.owner.id === this.userInfo.uid) + return this.roles.includes('modify-table-column-semantics') && (this.access.type === 'write_all' || this.table.owner.id === this.cacheUser.uid) }, inputVariant () { const runtimeConfig = useRuntimeConfig() diff --git a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/settings.vue b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/settings.vue index ddf319328c..a2ac279f2e 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/[table_id]/settings.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/[table_id]/settings.vue @@ -3,7 +3,6 @@ v-if="canUpdateTable"> <TableToolbar /> <v-window - v-if="loggedIn" v-model="tab"> <v-window-item> <v-form @@ -114,13 +113,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import TableToolbar from '@/components/table/TableToolbar.vue' import { useCacheStore } from '@/stores/cache.js' @@ -194,11 +186,11 @@ export default { access () { return this.cacheStore.getAccess }, - hasReadAccess () { - if (!this.access) { - return false - } - return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' + cacheUser () { + return this.cacheStore.getUser + }, + roles () { + return this.cacheStore.getRoles }, isChange () { if (!this.table) { @@ -210,26 +202,20 @@ export default { return this.table.is_schema_public !== this.modify.is_schema_public }, canUpdateTable () { - if (!this.roles || !this.userInfo || !this.table) { - return false - } - return this.roles.includes('update-table') && this.table.owner.id === this.userInfo.uid - }, - canModifyVisibility () { - if (!this.roles || !this.userInfo || !this.table) { + if (!this.roles || !this.cacheUser || !this.table) { return false } - return this.roles.includes('update-table') && this.table.owner.id === this.userInfo.uid + return this.roles.includes('update-table') && this.table.owner.id === this.cacheUser.uid }, canDropTable () { - if (!this.roles || !this.table || !this.userInfo) { + if (!this.roles || !this.table || !this.cacheUser) { return false } if (this.roles.includes('delete-foreign-table')) { return true } const tableService = useTableService() - return tableService.isOwner(this.table, this.userInfo) && this.roles.includes('delete-table') && this.table.identifiers.length === 0 + return tableService.isOwner(this.table, this.cacheUser) && this.roles.includes('delete-table') && this.table.identifiers.length === 0 }, inputVariant () { const runtimeConfig = useRuntimeConfig() diff --git a/dbrepo-ui/pages/database/[database_id]/table/create/dataset.vue b/dbrepo-ui/pages/database/[database_id]/table/create/dataset.vue index 78bd136751..50eb6305d7 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/create/dataset.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/create/dataset.vue @@ -219,12 +219,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import TableSchema from '@/components/table/TableSchema.vue' import { notEmpty } from '@/utils' @@ -323,6 +317,9 @@ export default { database() { return this.cacheStore.getDatabase }, + roles () { + return this.cacheStore.getRoles + }, generatedTableName() { if (!this.tableCreate.name) { return null diff --git a/dbrepo-ui/pages/database/[database_id]/table/create/schema.vue b/dbrepo-ui/pages/database/[database_id]/table/create/schema.vue index cf8de848de..d6bd4414df 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/create/schema.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/create/schema.vue @@ -185,12 +185,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import TableSchema from '@/components/table/TableSchema.vue' import { notEmpty } from '@/utils' @@ -266,6 +260,9 @@ export default { database () { return this.cacheStore.getDatabase }, + roles () { + return this.cacheStore.getRoles + }, canCreateTable () { if (!this.roles) { return false diff --git a/dbrepo-ui/pages/database/[database_id]/table/index.vue b/dbrepo-ui/pages/database/[database_id]/table/index.vue index ae3e3c13f1..95fdf1643e 100644 --- a/dbrepo-ui/pages/database/[database_id]/table/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/table/index.vue @@ -52,7 +52,10 @@ export default { if (this.error) { return false } - return this.database + if (!this.database) { + return false + } + return this.database.is_schema_public } } } diff --git a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/data.vue b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/data.vue index 0b0caa3c4f..bb3d953d76 100644 --- a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/data.vue +++ b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/data.vue @@ -38,7 +38,7 @@ import { ref } from 'vue' const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) +const cacheUser = ref(loggedIn ? user.value?.cacheUser : null) </script> <script> import TimeDrift from '@/components/TimeDrift.vue' @@ -88,11 +88,8 @@ export default { access () { return this.cacheStore.getAccess }, - hasReadAccess () { - if (!this.access) { - return false - } - return this.access.type === 'read' || this.access.type === 'write_own' || this.access.type === 'write_all' + cacheUser () { + return this.cacheStore.getUser }, canReadData () { if (!this.view) { @@ -101,10 +98,14 @@ export default { if (this.view.is_public) { return true } - if (!this.userInfo) { + if (!this.access) { + return false + } + if (!this.cacheUser) { return false } - return this.view.owner.id === this.userInfo.uid || this.hasReadAccess + const userService = useUserService() + return userService.hasReadAccess(this.access) || this.database.owner.id === this.cacheUser.uid }, }, mounted () { diff --git a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/info.vue b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/info.vue index 0ed006c4be..5864740846 100644 --- a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/info.vue +++ b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/info.vue @@ -59,12 +59,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -</script> <script> import ViewToolbar from '@/components/view/ViewToolbar.vue' import Summary from '@/components/identifier/Summary.vue' @@ -121,11 +115,11 @@ export default { view () { return this.cacheStore.getView }, - hasReadAccess () { - if (!this.access) { - return false - } - return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' + roles () { + return this.cacheStore.getRoles + }, + cacheUser () { + return this.cacheStore.getUser }, identifiers () { if (!this.view) { @@ -137,10 +131,10 @@ export default { if (!this.identifiers) { return [] } - if (!this.userInfo) { + if (!this.cacheUser) { return this.identifiers.filter(i => i.status === 'published') } - return this.identifiers.filter(i => i.status === 'published' || i.owner.id === this.userInfo.uid) + return this.identifiers.filter(i => i.status === 'published' || i.owner.id === this.cacheUser.uid) }, identifier () { if (this.pid) { @@ -177,10 +171,14 @@ export default { if (this.view.is_public) { return true } - if (!this.userInfo) { + if (!this.access) { return false } - return this.hasReadAccess || this.view.owner.id === this.userInfo.uid || this.database.owner.id === this.userInfo.uid + if (!this.cacheUser) { + return false + } + const userService = useUserService() + return userService.hasReadAcess(this.access) || this.database.owner.id === this.cacheUser.uid } }, methods: { diff --git a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/persist/[identifier_id]/index.vue b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/persist/[identifier_id]/index.vue index f528c86675..691336be2a 100644 --- a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/persist/[identifier_id]/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/persist/[identifier_id]/index.vue @@ -8,12 +8,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Persist from '@/components/identifier/Persist.vue' import { useCacheStore } from '@/stores/cache.js' @@ -59,6 +53,9 @@ export default { database () { return this.cacheStore.getDatabase }, + roles () { + return this.cacheStore.getRoles + }, canCreateIdentifier () { if (!this.roles) { return false diff --git a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/persist/index.vue b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/persist/index.vue index c5082c3be9..6351650736 100644 --- a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/persist/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/persist/index.vue @@ -51,15 +51,15 @@ export default { database () { return this.cacheStore.getDatabase }, + access () { + return this.cacheStore.getAccess + }, view () { if (!this.database) { return null } return this.database.views.filter(v => v.id === Number(this.$route.params.view_id))[0] }, - access () { - return this.cacheStore.getAccess - }, canPersistView () { if (!this.view) { return false diff --git a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/schema.vue b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/schema.vue index 5bd1ff5f9c..2cc851a41c 100644 --- a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/schema.vue +++ b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/schema.vue @@ -51,12 +51,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -</script> <script> import TableToolbar from '@/components/table/TableToolbar.vue' import { useCacheStore } from '@/stores/cache.js' @@ -113,11 +107,11 @@ export default { access () { return this.cacheStore.getAccess }, - hasReadAccess () { - if (!this.access) { - return false - } - return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' + roles () { + return this.cacheStore.getRoles + }, + cacheUser () { + return this.cacheStore.getUser }, canViewSchema () { if (!this.view) { @@ -126,10 +120,14 @@ export default { if (this.view.is_schema_public) { return true } - if (!this.userInfo) { + if (!this.access) { + return false + } + if (!this.cacheUser) { return false } - return this.hasReadAccess || this.view.owner.id === this.userInfo.uid || this.database.owner.id === this.userInfo.uid + const userService = useUserService() + return userService.hasReadAccess(this.access) || this.database.owner.id === this.cacheUser.uid }, inputVariant () { const runtimeConfig = useRuntimeConfig() diff --git a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/settings.vue b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/settings.vue index 575e5b5f27..8d77881cec 100644 --- a/dbrepo-ui/pages/database/[database_id]/view/[view_id]/settings.vue +++ b/dbrepo-ui/pages/database/[database_id]/view/[view_id]/settings.vue @@ -90,13 +90,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import ViewToolbar from '@/components/view/ViewToolbar.vue' import { useCacheStore } from '@/stores/cache.js' @@ -167,11 +160,11 @@ export default { access () { return this.cacheStore.getAccess }, - hasReadAccess () { - if (!this.access) { - return false - } - return this.access.type === 'read' || this.access.type === 'write_all' || this.access.type === 'write_own' + roles () { + return this.cacheStore.getRoles + }, + cacheUser () { + return this.cacheStore.getUser }, isChange () { if (!this.view) { @@ -183,22 +176,22 @@ export default { return this.view.is_schema_public !== this.modify.is_schema_public }, canUpdateVisibility () { - if (!this.roles || !this.userInfo || !this.view) { + if (!this.roles || !this.cacheUser || !this.view) { return false } - return this.roles.includes('modify-view-visibility') && this.view.owner.id === this.userInfo.uid + return this.roles.includes('modify-view-visibility') && this.view.owner.id === this.cacheUser.uid }, canDeleteView () { - if (!this.roles || !this.userInfo || !this.view) { + if (!this.roles || !this.cacheUser || !this.view) { return false } - return this.roles.includes('delete-database-view') && this.view.owner.id === this.userInfo.uid + return this.roles.includes('delete-database-view') && this.view.owner.id === this.cacheUser.uid }, canViewSettings () { - if (!this.userInfo || !this.view) { + if (!this.cacheUser || !this.view) { return false } - return this.view.owner.id === this.userInfo.uid + return this.view.owner.id === this.cacheUser.uid }, inputVariant () { const runtimeConfig = useRuntimeConfig() diff --git a/dbrepo-ui/pages/database/[database_id]/view/create.vue b/dbrepo-ui/pages/database/[database_id]/view/create.vue index b9d4a684d7..ab52fd2405 100644 --- a/dbrepo-ui/pages/database/[database_id]/view/create.vue +++ b/dbrepo-ui/pages/database/[database_id]/view/create.vue @@ -6,12 +6,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import Builder from '@/components/subset/Builder.vue' @@ -43,6 +37,9 @@ export default { } }, computed: { + roles () { + return this.cacheStore.getRoles + }, canCreateView () { if (!this.roles) { return false diff --git a/dbrepo-ui/pages/database/[database_id]/view/index.vue b/dbrepo-ui/pages/database/[database_id]/view/index.vue index 64f777dce3..8c3ab4b0e0 100644 --- a/dbrepo-ui/pages/database/[database_id]/view/index.vue +++ b/dbrepo-ui/pages/database/[database_id]/view/index.vue @@ -52,7 +52,10 @@ export default { if (this.error) { return false } - return this.database + if (!this.database) { + return false + } + return this.database.is_schema_public } } } diff --git a/dbrepo-ui/pages/index.vue b/dbrepo-ui/pages/index.vue index 16cbbb283f..b6c225025e 100644 --- a/dbrepo-ui/pages/index.vue +++ b/dbrepo-ui/pages/index.vue @@ -27,9 +27,6 @@ </div> </template> -<script setup> -const { loggedIn, user, login, logout } = useOidcAuth() -</script> <script> import DatabaseList from '@/components/database/DatabaseList.vue' import DatabaseCreate from '@/components/database/DatabaseCreate.vue' @@ -47,17 +44,8 @@ export default { } }, computed: { - userInfo () { - if (!this.user) { - return null - } - return this.user.userInfo - }, roles () { - if (!this.user) { - return [] - } - return [] + return this.cacheStore.getRoles }, canCreateDatabase () { if (!this.roles) { diff --git a/dbrepo-ui/pages/search.vue b/dbrepo-ui/pages/search.vue index ca80b1efda..507f81b731 100644 --- a/dbrepo-ui/pages/search.vue +++ b/dbrepo-ui/pages/search.vue @@ -63,12 +63,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import AdvancedSearch from '@/components/search/AdvancedSearch.vue' @@ -93,12 +87,6 @@ export default { header () { return `${this.results.length} ${this.results.length !== 1 ? this.$t('toolbars.search.results') : this.$t('toolbars.search.result')}` }, - canCreateDatabase () { - if (!this.roles) { - return false - } - return this.roles.includes('create-database') - }, isDatabaseSearch () { return this.type === 'database' } diff --git a/dbrepo-ui/pages/user/authentication.vue b/dbrepo-ui/pages/user/authentication.vue index 03c40e5d82..64d76f7535 100644 --- a/dbrepo-ui/pages/user/authentication.vue +++ b/dbrepo-ui/pages/user/authentication.vue @@ -61,11 +61,7 @@ </template> <script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) +const { loggedIn } = useOidcAuth() </script> <script> import UserToolbar from '@/components/user/UserToolbar.vue' diff --git a/dbrepo-ui/pages/user/index.vue b/dbrepo-ui/pages/user/index.vue index 1d76677059..be3fe8cf67 100644 --- a/dbrepo-ui/pages/user/index.vue +++ b/dbrepo-ui/pages/user/index.vue @@ -2,9 +2,6 @@ <div /> </template> -<script setup> -const { loggedIn, user, login, logout } = useOidcAuth() -</script> <script> export default { mounted () { diff --git a/dbrepo-ui/pages/user/info.vue b/dbrepo-ui/pages/user/info.vue index 58e265b59f..d8739fbab9 100644 --- a/dbrepo-ui/pages/user/info.vue +++ b/dbrepo-ui/pages/user/info.vue @@ -123,13 +123,6 @@ </div> </template> -<script setup> -import { ref } from 'vue' - -const { loggedIn, user, login, logout } = useOidcAuth() -const userInfo = ref(loggedIn ? user.value?.userInfo : null) -const roles = ref(loggedIn ? user.value?.claims?.realm_access?.roles : []) -</script> <script> import UserToolbar from '@/components/user/UserToolbar.vue' import { useCacheStore } from '@/stores/cache.js' @@ -184,8 +177,11 @@ export default { locale () { return this.cacheStore.getLocale }, - canModifyTheme () { - return this.roles.includes('modify-user-theme') + roles () { + return this.cacheStore.getRoles + }, + cacheUser () { + return this.cacheStore.getUser }, canModifyInformation () { return this.roles.includes('modify-user-information') @@ -216,7 +212,7 @@ export default { language: this.model.language, } const userService = useUserService() - userService.update(this.userInfo.id, payload) + userService.update(this.cacheUser.uid, payload) .then((user) => { console.info('Updated user information') const toast = useToastInstance() @@ -252,14 +248,14 @@ export default { return } this.model = { - id: this.userInfo.id, - username: this.userInfo.username, - firstname: this.userInfo.given_name, - lastname: this.userInfo.family_name, - orcid: this.userInfo.attributes.orcid, - affiliation: this.userInfo.attributes.affiliation, - theme: this.userInfo.attributes.theme, - language: this.userInfo.attributes.language + id: this.cacheUser.uid, + username: this.cacheUser.username, + firstname: this.cacheUser.given_name, + lastname: this.cacheUser.family_name, + orcid: this.cacheUser.attributes.orcid, + affiliation: this.cacheUser.attributes.affiliation, + theme: this.cacheUser.attributes.theme, + language: this.cacheUser.attributes.language } }, retrieve () { diff --git a/dbrepo-ui/stores/cache.js b/dbrepo-ui/stores/cache.js index 4582dce199..8ba0d2702f 100644 --- a/dbrepo-ui/stores/cache.js +++ b/dbrepo-ui/stores/cache.js @@ -12,6 +12,8 @@ export const useCacheStore = defineStore('cache', { locale: null, ontologies: [], messages: [], + user: null, + roles: [], uploadProgress: null } }, @@ -24,6 +26,8 @@ export const useCacheStore = defineStore('cache', { getLocale: (state) => state.locale, getOntologies: (state) => state.ontologies, getMessages: (state) => state.messages, + getUser: (state) => state.user, + getRoles: (state) => state.roles, getUploadProgress: (state) => state.uploadProgress, }, actions: { @@ -48,6 +52,12 @@ export const useCacheStore = defineStore('cache', { setOntologies(ontologies) { this.ontologies = ontologies }, + setUser(user) { + this.user = user + }, + setRoles(roles) { + this.roles = roles + }, setUploadProgress(uploadProgress) { this.uploadProgress = uploadProgress }, @@ -120,7 +130,6 @@ export const useCacheStore = defineStore('cache', { setRouteTable(databaseId, tableId) { if (!databaseId || !tableId) { this.table = null - console.error('Cannot set route table: missing database id', databaseId, 'or table id', tableId) return } const tableService = useTableService() @@ -130,7 +139,6 @@ export const useCacheStore = defineStore('cache', { setRouteAccess(databaseId, userId) { if (!databaseId || !userId) { this.access = null - console.error('Cannot set route access: missing database id', databaseId, 'or user id', userId) return } const accessService = useAccessService() @@ -140,7 +148,6 @@ export const useCacheStore = defineStore('cache', { setRouteView(databaseId, viewId) { if (!databaseId || !viewId) { this.view = null - console.error('Cannot set route view: database view id', databaseId, 'or view id', viewId) return } const viewService = useViewService() @@ -150,7 +157,6 @@ export const useCacheStore = defineStore('cache', { setRouteSubset(databaseId, subsetId) { if (!databaseId || !subsetId) { this.subset = null - console.error('Cannot set route subset: missing database id', databaseId, 'or subset id', subsetId) return } const subsetService = useQueryService() -- GitLab