Skip to content

Commit

Permalink
refactor: move auth store to pinia
Browse files Browse the repository at this point in the history
Removes the vuex auth store module and adds a pinia store for it instead.
  • Loading branch information
JammingBen committed Jan 11, 2024
1 parent 3eccc5f commit 646a8a4
Show file tree
Hide file tree
Showing 65 changed files with 394 additions and 471 deletions.
1 change: 0 additions & 1 deletion packages/web-app-admin-settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"pinia": "2.1.7",
"uuid": "9.0.1",
"vue-concurrency": "4.0.1",
"vuex": "4.1.0",
"web-app-admin-settings": "workspace:*"
}
}
3 changes: 0 additions & 3 deletions packages/web-app-admin-settings/src/views/Spaces.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import {
eventBus,
configurationManager,
queryItemAsString,
useAccessToken,
useClientService,
useRouteQuery,
useSideBar,
Expand Down Expand Up @@ -99,7 +98,6 @@ export default defineComponent({
},
setup() {
const store = useStore()
const accessToken = useAccessToken({ store })
const spaces = ref([])
const clientService = useClientService()
const { $gettext } = useGettext()
Expand Down Expand Up @@ -272,7 +270,6 @@ export default defineComponent({
sideBarActivePanel,
spaces,
loadResourcesTask,
accessToken,
breadcrumbs,
batchActions,
selectedSpaces,
Expand Down
3 changes: 0 additions & 3 deletions packages/web-app-admin-settings/src/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ import {
NoContentMessage,
eventBus,
queryItemAsString,
useAccessToken,
useCapabilitySpacesMaxQuota,
useClientService,
useConfigurationManager,
Expand Down Expand Up @@ -199,7 +198,6 @@ export default defineComponent({
const route = useRoute()
const store = useStore()
const { showErrorMessage } = useMessages()
const accessToken = useAccessToken({ store })
const clientService = useClientService()
const configurationManager = useConfigurationManager()
const userStore = useUserStore()
Expand Down Expand Up @@ -627,7 +625,6 @@ export default defineComponent({
loadResourcesTask,
loadAdditionalUserDataTask,
clientService,
accessToken,
batchActions,
filterGroups,
filterRoles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ import {
useCapabilityShareJailEnabled,
useCapabilitySpacesEnabled,
useStore,
useUserContext,
useClientService
} from '@ownclouders/web-pkg'
Expand Down Expand Up @@ -432,7 +431,6 @@ export default defineComponent({
isSpacesGenericLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-generic'),
hasShareJail: useCapabilityShareJailEnabled(),
hasSpaces: useCapabilitySpacesEnabled(),
isUserContext: useUserContext({ store }),
canUpload,
currentFolder,
createNewFileActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default defineComponent({
store,
spaceImageInput
})
const { actions: downloadArchiveActions } = useFileActionsDownloadArchive({ store })
const { actions: downloadArchiveActions } = useFileActionsDownloadArchive()
const actions = computed(() =>
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<resource-icon class="details-icon" :resource="resource" size="xxxlarge" />
</div>
<div
v-if="!isPublicLinkContext && shareIndicators.length"
v-if="!publicLinkContextReady && shareIndicators.length"
key="file-shares"
data-testid="sharingInfo"
class="oc-flex oc-flex-middle oc-my-m"
Expand Down Expand Up @@ -125,13 +125,17 @@
import { storeToRefs } from 'pinia'
import { computed, defineComponent, inject, Ref, ref, unref, watch } from 'vue'
import { mapGetters } from 'vuex'
import { ImageDimension, useConfigurationManager, useUserStore } from '@ownclouders/web-pkg'
import {
ImageDimension,
useAuthStore,
useConfigurationManager,
useUserStore
} from '@ownclouders/web-pkg'
import upperFirst from 'lodash-es/upperFirst'
import { ShareTypes } from '@ownclouders/web-client/src/helpers/share'
import {
useCapabilityFilesTags,
useClientService,
usePublicLinkContext,
useStore,
usePreviewService,
useGetMatchingSpace
Expand All @@ -152,7 +156,7 @@ import { AncestorMetaData, ResourceIcon } from '@ownclouders/web-pkg'
import { tagsHelper } from '../../../helpers/contextualHelpers'
import { ContextualHelper } from '@ownclouders/design-system/src/helpers'
import TagsSelect from './TagsSelect.vue'
import WebDavDetails from '@ownclouders/web-pkg/src/components/SideBar/WebDavDetails.vue'
import { WebDavDetails } from '@ownclouders/web-pkg'
export default defineComponent({
name: 'FileDetails',
Expand Down Expand Up @@ -181,13 +185,15 @@ export default defineComponent({
const resource = inject<Ref<Resource>>('resource')
const space = inject<Ref<SpaceResource>>('space')
const isPublicLinkContext = usePublicLinkContext({ store })
const previewService = usePreviewService()
const preview = ref(undefined)
const authStore = useAuthStore()
const { publicLinkContextReady } = storeToRefs(authStore)
const loadData = async () => {
const calls = []
if (unref(resource).type === 'file' && !unref(isPublicLinkContext)) {
if (unref(resource).type === 'file' && !unref(publicLinkContextReady)) {
calls.push(
store.dispatch('Files/loadVersions', {
client: clientService.webdav,
Expand Down Expand Up @@ -269,7 +275,7 @@ export default defineComponent({
return {
user,
preview,
isPublicLinkContext,
publicLinkContextReady,
space,
resource,
hasTags,
Expand Down Expand Up @@ -309,7 +315,7 @@ export default defineComponent({
return this.showShares && this.sharedAncestor
},
showShares() {
if (this.isPublicLinkContext) {
if (this.publicLinkContextReady) {
return false
}
return this.hasAnyShares
Expand Down Expand Up @@ -340,7 +346,7 @@ export default defineComponent({
return this.resourceSize !== '?'
},
showVersions() {
if (this.resource.type === 'folder' || this.isPublicLinkContext) {
if (this.resource.type === 'folder' || this.publicLinkContextReady) {
return
}
return this.versions.length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default defineComponent({
const store = useStore()
const clientService = useClientService()
const { current: currentLanguage } = useGettext()
const { downloadFile } = useDownloadFile({ store, clientService })
const { downloadFile } = useDownloadFile({ clientService })
const space = inject<Ref<SpaceResource>>('space')
const resource = inject<Ref<Resource>>('resource')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default defineComponent({
const { actions: restoreActions } = useSpaceActionsRestore({ store })
const { actions: showDetailsActions } = useFileActionsShowDetails({ store })
const { actions: showMembersActions } = useSpaceActionsShowMembers({ store })
const { actions: downloadArchiveActions } = useFileActionsDownloadArchive({ store })
const { actions: downloadArchiveActions } = useFileActionsDownloadArchive()
const { actions: navigateToTrashActions } = useSpaceActionsNavigateToTrash()
const spaceImageInput: VNodeRef = ref(null)
Expand Down
12 changes: 5 additions & 7 deletions packages/web-app-files/src/views/FilesDrop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { mapGetters } from 'vuex'
import {
createLocationPublic,
createLocationSpaces,
useAuthStore,
useMessages,
useThemeStore,
useUserStore
Expand All @@ -58,13 +59,11 @@ import {
import { useGettext } from 'vue3-gettext'
import {
useClientService,
usePublicLinkToken,
useStore,
useRouter,
useRoute,
useCapabilitySpacesEnabled,
useGetMatchingSpace,
useUserContext,
useRouteQuery,
queryItemAsString,
useUpload
Expand Down Expand Up @@ -94,8 +93,7 @@ export default defineComponent({
const hasSpaces = useCapabilitySpacesEnabled(store)
const authService = useAuthService()
const clientService = useClientService()
const publicToken = usePublicLinkToken({ store })
const isUserContext = useUserContext({ store })
const authStore = useAuthStore()
const { getInternalSpace } = useGetMatchingSpace()
useUpload({ uppyService })
Expand Down Expand Up @@ -152,7 +150,7 @@ export default defineComponent({
const resolvePublicLink = async () => {
loading.value = true
if (unref(isUserContext) && unref(fileId)) {
if (authStore.userContextReady && unref(fileId)) {
try {
const path = await clientService.webdav.getPathForFileId(unref(fileId))
await resolveToInternalLocation(path)
Expand All @@ -164,7 +162,7 @@ export default defineComponent({
}
const spaces: SpaceResource[] = store.getters['runtime/spaces/spaces']
const space = spaces.find((s) => s.driveAlias === `public/${unref(publicToken)}`)
const space = spaces.find((s) => s.driveAlias === `public/${authStore.publicLinkToken}`)
clientService.webdav
.listFiles(space, {}, { depth: 0 })
Expand All @@ -174,7 +172,7 @@ export default defineComponent({
if (linkRoleUploaderFolder.bitmask(false) !== sharePermissions) {
router.replace(
createLocationPublic('files-public-link', {
params: { driveAliasAndItem: `public/${unref(publicToken)}` }
params: { driveAliasAndItem: `public/${authStore.publicLinkToken}` }
})
)
return
Expand Down
8 changes: 4 additions & 4 deletions packages/web-app-files/src/views/spaces/DriveResolver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import GenericTrash from './GenericTrash.vue'
import { computed, defineComponent, onMounted, ref, unref } from 'vue'
import {
queryItemAsString,
useAuthStore,
useClientService,
useConfigurationManager,
useDriveResolver,
useGetMatchingSpace,
useRouteParam,
useRouteQuery,
useRouter,
useStore,
useUserContext
useStore
} from '@ownclouders/web-pkg'
import { useActiveLocation } from '@ownclouders/web-pkg'
import { createLocationSpaces, isLocationTrashActive } from '@ownclouders/web-pkg'
Expand All @@ -50,7 +50,7 @@ export default defineComponent({
},
setup() {
const store = useStore()
const isUserContext = useUserContext({ store })
const authStore = useAuthStore()
const clientService = useClientService()
const router = useRouter()
const driveAliasAndItem = useRouteParam('driveAliasAndItem')
Expand Down Expand Up @@ -135,7 +135,7 @@ export default defineComponent({
const space = unref(resolvedDrive.space)
if (space && isPublicSpaceResource(space)) {
const isRunningOnEos = store.getters.configuration?.options?.runningOnEos
if (unref(isUserContext) && unref(fileId) && !isRunningOnEos) {
if (authStore.userContextReady && unref(fileId) && !isRunningOnEos) {
try {
const path = await clientService.webdav.getPathForFileId(unref(fileId))
await resolveToInternalLocation(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ref } from 'vue'

jest.mock('@ownclouders/web-pkg', () => ({
...jest.requireActual('@ownclouders/web-pkg'),
useAccessToken: jest.fn(),
useExtensionRegistry: jest.fn(),
useRequest: jest.fn(),
useFileActionsCreateNewFile: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ref } from 'vue'

jest.mock('@ownclouders/web-pkg', () => ({
...jest.requireActual('@ownclouders/web-pkg'),
getIndicators: jest.fn(() => []),
useRouteQuery: jest.fn(),
useFileActions: jest.fn()
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ function createWrapper({
storeOptions.modules.runtime.modules.ancestorMetaData.getters.ancestorMetaData.mockReturnValue(
ancestorMetaData
)
storeOptions.modules.runtime.modules.auth.getters.isPublicLinkContextReady.mockReturnValue(
isPublicLinkContext
)
const store = createStore(storeOptions)

const spacesLocation = createLocationSpaces('files-spaces-generic')
Expand All @@ -226,7 +223,15 @@ function createWrapper({
resource,
space: mockDeep<SpaceResource>()
},
plugins: [...defaultPlugins({ piniaOptions: { userState: { user } } }), store],
plugins: [
...defaultPlugins({
piniaOptions: {
userState: { user },
authState: { publicLinkContextReady: isPublicLinkContext }
}
}),
store
],
mocks
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import { mockDeep } from 'jest-mock-extended'
import { Resource } from '@ownclouders/web-client'
import { ClientService, eventBus, useMessages } from '@ownclouders/web-pkg'

jest.mock('@ownclouders/web-pkg', () => ({
...jest.requireActual('@ownclouders/web-pkg'),
useAccessToken: jest.fn()
}))

describe('Tag Select', () => {
it('show tags input form if loaded successfully', () => {
const resource = mockDeep<Resource>({ tags: [] })
Expand Down
3 changes: 2 additions & 1 deletion packages/web-app-files/tests/unit/views/FilesDrop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'web-test-helpers'
import { mock, mockDeep } from 'jest-mock-extended'
import { ClientService } from '@ownclouders/web-pkg'
import { ListFilesResult } from '@ownclouders/web-client/src/webdav/listFiles'

describe('FilesDrop view', () => {
describe('different files view states', () => {
Expand All @@ -29,7 +30,7 @@ describe('FilesDrop view', () => {

function getMountedWrapper() {
const $clientService = mockDeep<ClientService>()
$clientService.webdav.listFiles.mockReturnValue(undefined)
$clientService.webdav.listFiles.mockResolvedValue(mock<ListFilesResult>())
const defaultMocks = {
...defaultComponentMocks({
currentRoute: mock<RouteLocation>({ name: 'files-common-favorites' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,18 @@ function getMountedWrapper({
...(mocks && mocks)
}
const storeOptions = { ...defaultStoreMockOptions }
storeOptions.modules.runtime.modules.auth.getters.isUserContextReady.mockReturnValue(
isUserContextReady
)
const store = createStore(storeOptions)
return {
mocks: defaultMocks,
storeOptions,
wrapper: mount(DriveResolver, {
global: {
plugins: [...defaultPlugins(), store],
plugins: [
...defaultPlugins({
piniaOptions: { authState: { userContextReady: isUserContextReady } }
}),
store
],
mocks: defaultMocks,
provide: defaultMocks,
stubs: { ...defaultStubs, 'app-banner': true }
Expand Down
Loading

0 comments on commit 646a8a4

Please sign in to comment.