Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move auth store to pinia #10323

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions changelog/unreleased/change-auth-store
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Change: Auth store to pinia

BREAKING CHANGE for developers: Auth information is no longer stored in a vuex store but in pinia instead. You can access all the store functionality via the new `useAuthStore` composable.

Note that the following composables have also been removed in favour of the pinia composable:

- `useAccessToken`
- `usePublicLinkContext`
- `usePublicLinkPassword`
- `usePublicLinkToken`
- `useUserContext`

For more details please see the linked PR down below.

https://github.com/owncloud/web/pull/10323
https://github.com/owncloud/web/issues/10210
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 @@ -200,7 +199,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 @@ -629,7 +627,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 @@ -205,7 +205,6 @@ import {
useCapabilityShareJailEnabled,
useCapabilitySpacesEnabled,
useStore,
useUserContext,
useClientService
} from '@ownclouders/web-pkg'

Expand Down Expand Up @@ -437,7 +436,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 @@ -66,7 +66,7 @@ export default defineComponent({
const { actions: uploadImageActions, uploadImageSpace } = useSpaceActionsUploadImage({
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()
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
14 changes: 7 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,
useSpacesStore,
useThemeStore,
Expand All @@ -59,13 +60,11 @@ import {
import { useGettext } from 'vue3-gettext'
import {
useClientService,
usePublicLinkToken,
useStore,
useRouter,
useRoute,
useCapabilitySpacesEnabled,
useGetMatchingSpace,
useUserContext,
useRouteQuery,
queryItemAsString,
useUpload
Expand Down Expand Up @@ -95,8 +94,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 @@ -154,7 +152,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 @@ -165,7 +163,9 @@ export default defineComponent({
}
}

const space = spacesStore.spaces.find((s) => s.driveAlias === `public/${unref(publicToken)}`)
const space = spacesStore.spaces.find(
(s) => s.driveAlias === `public/${authStore.publicLinkToken}`
)

clientService.webdav
.listFiles(space, {}, { depth: 0 })
Expand All @@ -175,7 +175,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 @@ -23,7 +23,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