Skip to content

Commit

Permalink
update to latest common admin
Browse files Browse the repository at this point in the history
  • Loading branch information
volar committed Dec 15, 2023
1 parent 8f451d1 commit c3d5213
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 122 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"cy:open": "CYPRESS_CACHE_FOLDER='node_modules/.cache/Cypress' yarn cypress open -C cypress/config/cypress.config.ts"
},
"dependencies": {
"@anzusystems/common-admin": "1.40.0-alpha17",
"@anzusystems/common-admin": "1.40.0-alpha19",
"@mdi/font": "7.3.67",
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
Expand All @@ -43,7 +43,7 @@
"devDependencies": {
"@cypress/grep": "^4.0.1",
"@intlify/unplugin-vue-i18n": "^1.6.0",
"@rushstack/eslint-patch": "^1.6.0",
"@rushstack/eslint-patch": "^1.6.1",
"@types/node": "^20.10.4",
"@types/rusha": "^0.8.3",
"@types/sortablejs": "^1.15.7",
Expand All @@ -68,7 +68,7 @@
"stylelint-config-recommended-vue": "^1.5.0",
"stylelint-config-standard-scss": "^12.0.0",
"typescript": "^4.9.5",
"vite": "^5.0.9",
"vite": "^5.0.10",
"vite-plugin-vuetify": "^2.0.1",
"vue-tsc": "1.8.25"
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/system/CurrentUserDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts" setup>
import { ROUTE } from '@/router/routes'
import { useCurrentUser } from '@/composables/system/currentUser'
import { useDamCurrentUser } from '@anzusystems/common-admin'
import { ACurrentUserDropdown } from '@anzusystems/common-admin'
const { currentUser } = useCurrentUser()
const { damCurrentUser } = useDamCurrentUser()
</script>

<template>
<ACurrentUserDropdown
:current-user="currentUser"
:current-user="damCurrentUser"
:settings-route-name="ROUTE.SYSTEM.SETTINGS"
:logout-route-name="ROUTE.SYSTEM.LOGOUT"
/>
Expand Down
15 changes: 10 additions & 5 deletions src/composables/system/appInitialize.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { useCookies } from '@vueuse/integrations/useCookies'
import { ref } from 'vue'
import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
import { updateCurrentUser, useCurrentUser } from '@/composables/system/currentUser'
import {
isDefined,
isUndefined,
updateDamCurrentUser,
useDamConfigState,
useDamCurrentUser,
} from '@anzusystems/common-admin'
import { ROUTE } from '@/router/routes'
import { checkAbility } from '@/router/checkAbility'
import { isDefined, isUndefined, useDamConfigState } from '@anzusystems/common-admin'
import { envConfig } from '@/services/EnvConfigService'
import { initCurrentExtSystemAndLicence, useCurrentExtSystem } from '@/composables/system/currentExtSystem'
import { initAppNotificationListeners } from '@/composables/system/appNotificationListeners'
Expand All @@ -24,7 +29,7 @@ export async function createAppInitialize(
useDamConfigState(damClient)

try {
const updateCurrentUserPromise = updateCurrentUser()
const updateCurrentUserPromise = updateDamCurrentUser(damClient)
const loadDamConfigPromise = loadDamPrvConfig()
await Promise.all([updateCurrentUserPromise, loadDamConfigPromise])
} catch (error) {
Expand All @@ -50,11 +55,11 @@ export async function createAppInitialize(
return
}

const { currentUser } = useCurrentUser()
const { damCurrentUser } = useDamCurrentUser()

if (
(isStatusNotDefined() || isStatusSsoCommunicationFailure() || isStatusInternalErrorFailure()) &&
isUndefined(currentUser.value)
isUndefined(damCurrentUser.value)
) {
next({ name: ROUTE.SYSTEM.LOGIN })
} else if (isStatusUnauthorized()) {
Expand Down
6 changes: 3 additions & 3 deletions src/composables/system/appNotificationListeners.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useUploadQueuesStore } from '@/stores/coreDam/uploadQueuesStore'
import { updateCurrentUser } from '@/composables/system/currentUser'
import { useDistributionListStore } from '@/stores/coreDam/distributionListStore'
import {
DamDistributionStatus,
DamNotificationName,
initDamNotifications,
initDamNotifications, updateDamCurrentUser,
useDamNotifications,
} from '@anzusystems/common-admin'
import { damClient } from '@/services/api/clients/damClient'

export const initAppNotificationListeners = () => {
const { openConnection } = initDamNotifications()
Expand Down Expand Up @@ -46,7 +46,7 @@ export const initAppNotificationListeners = () => {
distributionListStore.authorizationMessage(event.data.distributionService, event.data.success)
break
case DamNotificationName.UserUpdated:
updateCurrentUser()
updateDamCurrentUser(damClient)
break
}
})
Expand Down
19 changes: 9 additions & 10 deletions src/composables/system/currentExtSystem.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { readonly, ref, watch } from 'vue'
import type { DamExtSystem } from '@anzusystems/common-admin'
import { isDocId, isString, useDamConfigState, useDamCurrentUser } from '@anzusystems/common-admin'
import { fetchExtSystem } from '@/services/api/coreDam/extSystemApi'
import { useCurrentUser } from '@/composables/system/currentUser'
import { fetchAssetLicence } from '@/services/api/coreDam/assetLicenceApi'
import type { AssetLicence } from '@/types/coreDam/AssetLicence'
import { fetchAsset } from '@/services/api/coreDam/assetApi'
import { isDocId, isString, useDamConfigState } from '@anzusystems/common-admin'
import { useAssetDetailStore } from '@/stores/coreDam/assetDetailStore'

const currentExtSystemId = ref(0)
Expand All @@ -15,7 +14,7 @@ const currentAssetLicence = ref<AssetLicence>()
const currentAssetLicenceId = ref(0)

export const initCurrentExtSystemAndLicence = (loadFromAsset = false, assetId: string | undefined = undefined) => {
const { currentUser } = useCurrentUser()
const { damCurrentUser } = useDamCurrentUser()
const { damPrvConfig, initialized } = useDamConfigState()

watch(currentExtSystemId, async (newValue, oldValue) => {
Expand All @@ -38,7 +37,7 @@ export const initCurrentExtSystemAndLicence = (loadFromAsset = false, assetId: s
reject(false)
return
}
if (!currentUser.value) {
if (!damCurrentUser.value) {
console.error('Current user must be loaded first.')
reject(false)
return
Expand Down Expand Up @@ -73,14 +72,14 @@ export const initCurrentExtSystemAndLicence = (loadFromAsset = false, assetId: s
})
}
if (damPrvConfig.value.settings.allowSelectExtSystem && damPrvConfig.value.settings.allowSelectLicenceId) {
if (currentUser.value.selectedLicence) {
currentExtSystemId.value = currentUser.value.selectedLicence.extSystem
currentAssetLicenceId.value = currentUser.value.selectedLicence.id
if (damCurrentUser.value.selectedLicence) {
currentExtSystemId.value = damCurrentUser.value.selectedLicence.extSystem
currentAssetLicenceId.value = damCurrentUser.value.selectedLicence.id
resolve(true)
return
} else if (currentUser.value.assetLicences[0]) {
currentExtSystemId.value = currentUser.value.assetLicences[0].extSystem
currentAssetLicenceId.value = currentUser.value.assetLicences[0].id
} else if (damCurrentUser.value.assetLicences[0]) {
currentExtSystemId.value = damCurrentUser.value.assetLicences[0].extSystem
currentAssetLicenceId.value = damCurrentUser.value.assetLicences[0].id
resolve(true)
return
}
Expand Down
39 changes: 0 additions & 39 deletions src/composables/system/currentUser.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
import { fetchCurrentUser } from '@/services/api/coreDam/userApi'
import { envConfig } from '@/services/EnvConfigService'
import { computed, readonly, ref } from 'vue'
import type { CurrentUserDto } from '@/types/coreDam/CurrentUser'
import { ROLE_SUPER_ADMIN } from '@anzusystems/common-admin'
import { useUserDisplayHelper } from '@/composables/system/userDisplayHelper'

const currentUser = ref<CurrentUserDto | undefined>(undefined)
const currentUserIsSuperAdmin = ref(false)
const showDevFeature = ref(false)

export function logoutUser() {
window.location.pathname = '/logout'
}

export function updateCurrentUser() {
return new Promise((resolve, reject) => {
fetchCurrentUser()
.then((res: CurrentUserDto) => {
currentUser.value = res
if (res.roles.includes(ROLE_SUPER_ADMIN)) currentUserIsSuperAdmin.value = true
if (currentUserIsSuperAdmin.value || envConfig.appVersion === 'dev') showDevFeature.value = true

resolve(currentUser)
})
.catch((err) => {
reject(err)
})
})
}

const { getUsername } = useUserDisplayHelper()
const currentUserUsername = computed(() => getUsername(currentUser.value))

export function useCurrentUser() {
return {
currentUser: readonly(currentUser),
currentUserIsSuperAdmin: readonly(currentUserIsSuperAdmin),
currentUserUsername: readonly(currentUserUsername),
showDevFeature,
}
}
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
loadCommonFonts,
type PluginOptions,
} from '@anzusystems/common-admin'
import { useCurrentUser } from '@/composables/system/currentUser'
import { useDamCurrentUser } from '@anzusystems/common-admin'
import type { AclValue } from '@/types/Permission'
import '@anzusystems/common-admin/styles'
import { damClient } from '@/services/api/clients/damClient'
Expand All @@ -29,7 +29,7 @@ export const AVAILABLE_LANGUAGES: Array<LanguageCode> = ['en', 'sk']

dayjs.extend(Duration)

const { currentUser } = useCurrentUser()
const { damCurrentUser } = useDamCurrentUser()

loadCommonFonts()

Expand All @@ -40,7 +40,7 @@ loadEnvConfig(() => {
.use(vuetify)
.use(router)
.use<PluginOptions<AclValue>>(AnzuSystemsCommonAdmin, {
currentUser,
currentUser: damCurrentUser,
languages: {
available: AVAILABLE_LANGUAGES,
default: DEFAULT_LANGUAGE,
Expand Down
7 changes: 3 additions & 4 deletions src/router/checkAbility.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
import { isUndefined, useAcl } from '@anzusystems/common-admin'
import { isUndefined, useAcl, useDamCurrentUser } from '@anzusystems/common-admin'
import type { AclValue } from '@/types/Permission'
import { useCurrentUser } from '@/composables/system/currentUser'

export const checkAbility = async (
to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext
) => {
const { currentUser } = useCurrentUser()
const { canForAll } = useAcl<AclValue>({ currentUser, disableInject: true })
const { damCurrentUser } = useDamCurrentUser()
const { canForAll } = useAcl<AclValue>({ currentUser: damCurrentUser, disableInject: true })

if (isUndefined(to.meta.requiredPermissions)) {
next()
Expand Down
9 changes: 3 additions & 6 deletions src/services/api/coreDam/userApi.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { damClient } from '@/services/api/clients/damClient'
import { SYSTEM_CORE_DAM } from '@/model/systems'
import type { FilterBag, Pagination } from '@anzusystems/common-admin'
import type { DamCurrentUserDto, FilterBag, Pagination } from '@anzusystems/common-admin'
import { apiAnyRequest, apiFetchByIds, apiFetchList, apiFetchOne, apiUpdateOne } from '@anzusystems/common-admin'
import type { UpdateUser, User } from '@/types/coreDam/User'
import type { CurrentUserDto, UpdateCurrentUserDto } from '@/types/coreDam/CurrentUser'
import type { UpdateCurrentUserDto } from '@/types/coreDam/CurrentUser'

const END_POINT = '/adm/v1/user'
export const CURRENT_USER_END_POINT = END_POINT + '/current'
export const ENTITY = 'user'

export const fetchCurrentUser = () =>
apiFetchOne<CurrentUserDto>(damClient, CURRENT_USER_END_POINT, {}, SYSTEM_CORE_DAM, ENTITY)

export const updateCurrentUser = (data: UpdateCurrentUserDto) =>
apiAnyRequest<UpdateCurrentUserDto, CurrentUserDto>(
apiAnyRequest<UpdateCurrentUserDto, DamCurrentUserDto>(
damClient,
'PATCH',
CURRENT_USER_END_POINT,
Expand Down
23 changes: 1 addition & 22 deletions src/types/coreDam/CurrentUser.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import type { AnzuUser, IntegerId } from '@anzusystems/common-admin'
import type { User } from '@/types/coreDam/User'

export interface CurrentUserExtSystem {
id: IntegerId
name: string
}

export interface CurrentUserAssetLicence {
id: IntegerId
name: string
extSystem: IntegerId
}

export interface CurrentUserDto
extends AnzuUser,
Pick<User, 'person' | 'avatar' | 'allowedAssetExternalProviders' | 'allowedDistributionServices'> {
selectedLicence: CurrentUserAssetLicence | null
adminToExtSystems: CurrentUserExtSystem[]
userToExtSystems: CurrentUserExtSystem[]
assetLicences: CurrentUserAssetLicence[]
}
import type { IntegerId } from '@anzusystems/common-admin'

export interface UpdateCurrentUserDto {
selectedLicence: IntegerId
Expand Down
11 changes: 9 additions & 2 deletions src/views/coreDam/asset/components/ImagePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { computed, ref, watch } from 'vue'
import placeholder16x9 from '@/assets/image/placeholder16x9.jpg'
import { fetchImageFile } from '@/services/api/coreDam/imageApi'
import { useI18n } from 'vue-i18n'
import { useCurrentAssetLicence } from '@/composables/system/currentExtSystem'
import { useCurrentAssetLicence, useCurrentExtSystem } from '@/composables/system/currentExtSystem'
const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -47,6 +47,7 @@ const fetchImage = async (id: DocId) => {
}
const { currentAssetLicenceId } = useCurrentAssetLicence()
const { currentExtSystemId } = useCurrentExtSystem()
const imagePreviewModel = computed({
get() {
Expand Down Expand Up @@ -178,7 +179,13 @@ watch(
{{ t('system.imagePreview.actions.unassign') }}
</VBtn>
<AAssetSelect
:asset-licence-id="currentAssetLicenceId"
:select-config="[
{
title: 'Default',
licence: currentAssetLicenceId,
extSystem: currentExtSystemId,
},
]"
:min-count="1"
:max-count="1"
:asset-type="AssetTypeValue.Image"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { computed, onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useCurrentAssetLicence, useCurrentExtSystem } from '@/composables/system/currentExtSystem'
import { useCurrentUser } from '@/composables/system/currentUser'
import {
ADialogToolbar,
ASystemEntityScope,
Expand All @@ -14,6 +13,7 @@ import {
isUndefined,
useAlerts,
useDamConfigState,
useDamCurrentUser,
useValidate,
} from '@anzusystems/common-admin'
import useVuelidate, { type ErrorObject } from '@vuelidate/core'
Expand Down Expand Up @@ -53,7 +53,7 @@ const { t } = useI18n()
const { currentExtSystemId } = useCurrentExtSystem()
const { currentAssetLicenceId } = useCurrentAssetLicence()
const { currentUser, currentUserIsSuperAdmin } = useCurrentUser()
const { damCurrentUser, damCurrentUserIsSuperAdmin } = useDamCurrentUser()
const saving = ref(false)
const selectedExtSystem = ref<null | IntegerId>(null)
Expand All @@ -63,8 +63,8 @@ const selectedExtSystemSearch = ref<null | IntegerId>(null)
const selectedLicenceSearch = ref<null | IntegerId>(null)
const extSystemsItems = computed(() => {
if (currentUser.value && currentUser.value.userToExtSystems.length > 0) {
return currentUser.value.userToExtSystems.map((item) => {
if (damCurrentUser.value && damCurrentUser.value.userToExtSystems.length > 0) {
return damCurrentUser.value.userToExtSystems.map((item) => {
return {
value: item.id,
title: item.name,
Expand All @@ -75,8 +75,8 @@ const extSystemsItems = computed(() => {
})
const licenceItems = computed(() => {
if (currentUser.value && currentUser.value.assetLicences.length > 0 && !isUndefined(selectedExtSystem.value)) {
return currentUser.value.assetLicences
if (damCurrentUser.value && damCurrentUser.value.assetLicences.length > 0 && !isUndefined(selectedExtSystem.value)) {
return damCurrentUser.value.assetLicences
.filter((licence) => licence.extSystem === selectedExtSystem.value)
.map((item) => {
return {
Expand Down Expand Up @@ -179,7 +179,7 @@ onMounted(async () => {
>
{{ t('system.mainBar.extSystemLicenceSwitch.title') }}
</ADialogToolbar>
<VCardText v-if="currentUserIsSuperAdmin">
<VCardText v-if="damCurrentUserIsSuperAdmin">
<div class="mb-4 text-caption">
{{ t('system.mainBar.extSystemLicenceSwitch.currentExtSystem') }}: {{ currentExtSystemId }} ({{
extSystemName
Expand Down
Loading

0 comments on commit c3d5213

Please sign in to comment.