-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7d937b
commit c4925ba
Showing
7 changed files
with
303 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Enhancement: GDPR export | ||
|
||
Users can now request a GDPR export on their account page. Note that this is only supported when running oCIS as backend. | ||
|
||
https://github.com/owncloud/web/issues/8738 | ||
https://github.com/owncloud/web/pull/8741 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
packages/web-runtime/src/components/Account/GdprExport.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<template> | ||
<span v-if="loading"> | ||
<oc-spinner /> | ||
</span> | ||
<span v-else-if="exportInProgress" class="oc-flex oc-flex-middle" data-testid="export-in-process"> | ||
<oc-icon name="time" fill-type="line" size="small" class="oc-mr-s" /> | ||
<span v-text="$gettext('Export is being processed. This can take up to 24 hours.')" /> | ||
</span> | ||
<div v-else> | ||
<oc-button | ||
appearance="raw" | ||
variation="primary" | ||
data-testid="request-export-btn" | ||
@click="requestExport" | ||
> | ||
<span v-text="$gettext('Request new export')" /> | ||
</oc-button> | ||
<div v-if="exportFile" class="oc-flex oc-flex-middle"> | ||
<oc-button | ||
appearance="raw" | ||
variation="primary" | ||
data-testid="download-export-btn" | ||
@click="downloadExport" | ||
> | ||
<oc-icon name="download" fill-type="line" size="small" /> | ||
<span v-text="$gettext('Download export')" /> | ||
</oc-button> | ||
<span class="oc-ml-s" v-text="`(${exportDate})`" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent, onMounted, onUnmounted, ref, unref } from 'vue' | ||
import { useTask } from 'vue-concurrency' | ||
import { useGettext } from 'vue3-gettext' | ||
import { Resource } from 'web-client' | ||
import { useClientService, useStore } from 'web-pkg/src/composables' | ||
import { useDownloadFile } from 'web-pkg/src/composables/download' | ||
import { formatDateFromJSDate } from 'web-pkg' | ||
import { isPersonalSpaceResource } from 'web-client/src/helpers' | ||
const GDPR_EXPORT_FILE_NAME = '.personal_data_export.json' | ||
const POLLING_INTERVAL = 30000 | ||
export default defineComponent({ | ||
name: 'GdprExport', | ||
setup() { | ||
const store = useStore() | ||
const { $gettext, current: currentLanguage } = useGettext() | ||
const { webdav, graphAuthenticated } = useClientService() | ||
const { downloadFile } = useDownloadFile() | ||
const loading = ref(true) | ||
const checkInterval = ref() | ||
const exportFile = ref<Resource>() | ||
const exportInProgress = ref(false) | ||
const personalSpace = computed(() => { | ||
return store.getters['runtime/spaces/spaces'].find((s) => isPersonalSpaceResource(s)) | ||
}) | ||
const loadExportTask = useTask(function* () { | ||
try { | ||
const resource = yield webdav.getFileInfo(unref(personalSpace), { | ||
path: `/${GDPR_EXPORT_FILE_NAME}` | ||
}) | ||
if (resource.processing) { | ||
exportInProgress.value = true | ||
if (!unref(checkInterval)) { | ||
checkInterval.value = setInterval(() => { | ||
loadExportTask.perform() | ||
}, POLLING_INTERVAL) | ||
} | ||
return | ||
} | ||
exportFile.value = resource | ||
exportInProgress.value = false | ||
if (unref(checkInterval)) { | ||
clearInterval(unref(checkInterval)) | ||
} | ||
} catch (e) { | ||
if (e.statusCode !== 404) { | ||
// resource seems to exist, but something else went wrong | ||
console.error(e) | ||
} | ||
} finally { | ||
loading.value = false | ||
} | ||
}).restartable() | ||
const requestExport = async () => { | ||
try { | ||
await graphAuthenticated.users.exportPersonalData(store.getters.user.uuid, { | ||
storageLocation: `/${GDPR_EXPORT_FILE_NAME}` | ||
}) | ||
await loadExportTask.perform() | ||
return store.dispatch('showMessage', { | ||
title: $gettext('GDPR export has been requested') | ||
}) | ||
} catch (e) { | ||
return store.dispatch('showMessage', { | ||
title: $gettext('GDPR export could not be requested. Please contact an administrator.'), | ||
status: 'danger' | ||
}) | ||
} | ||
} | ||
const downloadExport = () => { | ||
return downloadFile(unref(exportFile)) | ||
} | ||
const exportDate = computed(() => { | ||
return formatDateFromJSDate(new Date(unref(exportFile).mdate), currentLanguage) | ||
}) | ||
onMounted(() => { | ||
loadExportTask.perform() | ||
}) | ||
onUnmounted(() => { | ||
if (unref(checkInterval)) { | ||
clearInterval(unref(checkInterval)) | ||
} | ||
}) | ||
return { | ||
loading, | ||
loadExportTask, | ||
exportFile, | ||
exportInProgress, | ||
requestExport, | ||
downloadExport, | ||
exportDate | ||
} | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/web-runtime/tests/unit/components/Account/GdprExport.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import GdprExport from 'web-runtime/src/components/Account/GdprExport.vue' | ||
import { | ||
createStore, | ||
defaultComponentMocks, | ||
defaultPlugins, | ||
shallowMount, | ||
defaultStoreMockOptions | ||
} from 'web-test-helpers' | ||
import { mock, mockDeep } from 'jest-mock-extended' | ||
import { ClientService } from 'web-pkg' | ||
import { Resource } from 'web-client/src' | ||
|
||
const selectors = { | ||
ocSpinnerStub: 'oc-spinner-stub', | ||
requestExportBtn: '[data-testid="request-export-btn"]', | ||
downloadExportBtn: '[data-testid="download-export-btn"]', | ||
exportInProgress: '[data-testid="export-in-process"]' | ||
} | ||
|
||
const downloadFile = jest.fn() | ||
jest.mock('web-pkg/src/composables/download', () => ({ | ||
useDownloadFile: jest.fn(() => ({ downloadFile })) | ||
})) | ||
|
||
describe('GdprExport component', () => { | ||
it('shows the loading spinner initially', () => { | ||
const { wrapper } = getWrapper() | ||
expect(wrapper.find(selectors.ocSpinnerStub).exists()).toBeTruthy() | ||
}) | ||
it('shows a "in progress"-hint', async () => { | ||
const { wrapper } = getWrapper(mock<Resource>({ processing: true })) | ||
await wrapper.vm.loadExportTask.last | ||
expect(wrapper.find(selectors.exportInProgress).exists()).toBeTruthy() | ||
}) | ||
describe('request button', () => { | ||
it('shows if no export is being processed', async () => { | ||
const { wrapper } = getWrapper(mock<Resource>({ processing: false })) | ||
await wrapper.vm.loadExportTask.last | ||
expect(wrapper.find(selectors.requestExportBtn).exists()).toBeTruthy() | ||
}) | ||
it('does not show when an export is being processed', async () => { | ||
const { wrapper } = getWrapper(mock<Resource>({ processing: true })) | ||
await wrapper.vm.loadExportTask.last | ||
expect(wrapper.find(selectors.requestExportBtn).exists()).toBeFalsy() | ||
}) | ||
it('triggers the export when being clicked', async () => { | ||
const { wrapper, mocks } = getWrapper(mock<Resource>({ processing: false })) | ||
await wrapper.vm.loadExportTask.last | ||
await wrapper.find(selectors.requestExportBtn).trigger('click') | ||
expect(mocks.$clientService.graphAuthenticated.users.exportPersonalData).toHaveBeenCalled() | ||
}) | ||
}) | ||
describe('download button', () => { | ||
it('shows if a gdpr export exists', async () => { | ||
const { wrapper } = getWrapper(mock<Resource>({ processing: false })) | ||
await wrapper.vm.loadExportTask.last | ||
expect(wrapper.find(selectors.downloadExportBtn).exists()).toBeTruthy() | ||
}) | ||
it('does not show if no export exists', async () => { | ||
const { wrapper } = getWrapper() | ||
await wrapper.vm.loadExportTask.last | ||
expect(wrapper.find(selectors.downloadExportBtn).exists()).toBeFalsy() | ||
}) | ||
it('triggers the download when being clicked', async () => { | ||
const { wrapper } = getWrapper(mock<Resource>({ processing: false })) | ||
await wrapper.vm.loadExportTask.last | ||
await wrapper.find(selectors.downloadExportBtn).trigger('click') | ||
expect(downloadFile).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper(resource = undefined) { | ||
const clientService = mockDeep<ClientService>() | ||
if (resource) { | ||
clientService.webdav.getFileInfo.mockResolvedValue(resource) | ||
} else { | ||
clientService.webdav.getFileInfo.mockRejectedValue({ statusCode: 404 }) | ||
} | ||
const mocks = defaultComponentMocks() | ||
mocks.$clientService = clientService | ||
const store = createStore(defaultStoreMockOptions) | ||
return { | ||
mocks, | ||
wrapper: shallowMount(GdprExport, { | ||
global: { | ||
mocks, | ||
plugins: [...defaultPlugins(), store] | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters