Skip to content

Commit

Permalink
fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pieroit committed Jul 17, 2024
1 parent f0cebeb commit aac2832
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 35 deletions.
27 changes: 0 additions & 27 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
<script setup lang="ts">
import { createMongoAbility } from '@casl/ability'
import { useMainStore } from '@stores/useMainStore'
import { instantiateApiClient } from '@services/ApiService'
import { useAbility } from '@casl/vue'
import LogService from '@services/LogService'
const { jwtPayload, cookie } = useMainStore()
const perms = useAbility()
console.log("App.vue", jwtPayload)
if (jwtPayload){
instantiateApiClient(cookie)
perms.update(
createMongoAbility(
jwtPayload === null
? []
: Object.entries(jwtPayload.permissions).map(([subject, action]) => ({
subject,
action,
})),
).rules,
)
LogService.success(`Authenticated as ${jwtPayload.username}`)
}
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion src/composables/perms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAbility } from '@casl/vue'
import type { AppAbility } from '@/api'
import type { AppAbility } from '@services/ApiService'

export const usePerms = () => useAbility<AppAbility>()
2 changes: 1 addition & 1 deletion src/services/EmbedderConfigService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiClient, tryRequest } from '@/api'
import { apiClient, tryRequest } from '@services/ApiService'
import type { JSONSettings } from '@models/JSONSchema'

/*
Expand Down
2 changes: 1 addition & 1 deletion src/services/LLMConfigService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiClient, tryRequest } from '@/api'
import { apiClient, tryRequest } from '@services/ApiService'
import type { JSONSettings } from '@models/JSONSchema'

/*
Expand Down
2 changes: 1 addition & 1 deletion src/services/UserService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiClient, tryRequest } from '@/api'
import { apiClient, tryRequest } from '@services/ApiService'
import type { UserCreate, UserCredentials, UserUpdate } from 'ccat-api'

/*
Expand Down
27 changes: 26 additions & 1 deletion src/stores/useMainStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import type { AuthPermission, AuthResource } from 'ccat-api'
import type { JwtPayload } from 'jwt-decode'
import { useJwt } from '@vueuse/integrations/useJwt'
import { useCookies } from '@vueuse/integrations/useCookies'
import { useAbility } from '@casl/vue'
import { createMongoAbility } from '@casl/ability'

import { instantiateApiClient } from '@services/ApiService'
import LogService from '@services/LogService'


Expand Down Expand Up @@ -33,6 +37,26 @@ export const useMainStore = defineStore('main', () => {
return payload.value
})

/**
* User permissions
*/
const perms = useAbility()
if (jwtPayload.value){
instantiateApiClient(cookie.value)

perms.update(
createMongoAbility(
jwtPayload.value === null
? []
: Object.entries(jwtPayload.value.permissions).map(([subject, action]) => ({
subject,
action,
})),
).rules,
)
LogService.success(`Authenticated as ${jwtPayload.value.username}`)

}
/**
* Dark theme
*/
Expand Down Expand Up @@ -65,7 +89,8 @@ export const useMainStore = defineStore('main', () => {
pluginsFilters,
toggleDark,
cookie,
jwtPayload
jwtPayload,
perms
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/views/SettingsView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useUsers } from '@stores/useUsers'
import { startCase, lowerCase, cloneDeep } from 'lodash'
import { apiClient, tryRequest } from '@/api'
import { apiClient, tryRequest } from '@services/ApiService'
import ModalBox from '@components/ModalBox.vue'
import SidePanel from '@components/SidePanel.vue'
import type { Status, UserResponse } from 'ccat-api'
Expand Down
4 changes: 2 additions & 2 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export default defineConfig({
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: 'admin',
password: 'admin',
username: 'user',
password: 'user',
}),
})
).json()
Expand Down

0 comments on commit aac2832

Please sign in to comment.