Prevent google drive actions to open new workspaces

This commit is contained in:
Benoit Schweblin 2018-01-04 22:13:20 +00:00
parent d0ea2f7850
commit 4b9bb3b833

View File

@ -33,6 +33,25 @@ export default providerRegistry.register({
}); });
}) })
.then((token) => { .then((token) => {
const openWorkspaceIfExists = (file) => {
const folderId = file
&& file.appProperties
&& file.appProperties.folderId;
if (folderId) {
// See if we have the corresponding workspace
const workspaceParams = {
providerId: 'googleDriveWorkspace',
folderId,
};
const workspaceId = utils.makeWorkspaceId(workspaceParams);
const workspace = store.getters['data/sanitizedWorkspaces'][workspaceId];
// If we have the workspace, open it by changing the current URL
if (workspace) {
utils.setQueryParams(workspaceParams);
}
}
};
switch (state.action) { switch (state.action) {
case 'create': case 'create':
default: default:
@ -41,24 +60,17 @@ export default providerRegistry.register({
.then((folder) => { .then((folder) => {
folder.appProperties = folder.appProperties || {}; folder.appProperties = folder.appProperties || {};
googleHelper.driveActionFolder = folder; googleHelper.driveActionFolder = folder;
if (folder.appProperties.folderId) { openWorkspaceIfExists(folder);
// Change current URL to workspace URL
utils.setQueryParams({
providerId: 'googleDriveWorkspace',
folderId: folder.appProperties.folderId,
sub: state.userId,
});
}
}, (err) => { }, (err) => {
if (!err || err.status !== 404) { if (!err || err.status !== 404) {
throw err; throw err;
} }
// We received a 404 error meaning we have no permission to read the folder // We received an HTTP 404 meaning we have no permission to read the folder
googleHelper.driveActionFolder = { id: state.folderId }; googleHelper.driveActionFolder = { id: state.folderId };
}); });
case 'open': { case 'open': {
const getOneFile = (ids) => { const getOneFile = (ids = state.ids || []) => {
const id = ids.shift(); const id = ids.shift();
return id && googleHelper.getFile(token, id) return id && googleHelper.getFile(token, id)
.then((file) => { .then((file) => {
@ -68,31 +80,20 @@ export default providerRegistry.register({
}); });
}; };
return getOneFile(state.ids || []) return getOneFile()
.then(() => { // Check if first file is part of a workspace
// Check if first file is part of a workspace .then(() => openWorkspaceIfExists(googleHelper.driveActionFiles[0]));
const firstFile = googleHelper.driveActionFiles[0];
if (firstFile && firstFile.appProperties && firstFile.appProperties.folderId) {
// Change current URL to workspace URL
utils.setQueryParams({
providerId: 'googleDriveWorkspace',
folderId: firstFile.appProperties.folderId,
sub: state.userId,
});
}
});
} }
} }
}); });
}, },
performAction() { performAction() {
const state = googleHelper.driveState || {}; return Promise.resolve()
const token = store.getters['data/googleTokens'][state.userId];
return token && Promise.resolve()
.then(() => { .then(() => {
switch (state.action) { const state = googleHelper.driveState || {};
const token = store.getters['data/googleTokens'][state.userId];
switch (token && state.action) {
case 'create': case 'create':
default:
return store.dispatch('createFile') return store.dispatch('createFile')
.then((file) => { .then((file) => {
store.commit('file/setCurrentId', file.id); store.commit('file/setCurrentId', file.id);
@ -102,6 +103,8 @@ export default providerRegistry.register({
case 'open': case 'open':
return store.dispatch('queue/enqueue', return store.dispatch('queue/enqueue',
() => this.openFiles(token, googleHelper.driveActionFiles)); () => this.openFiles(token, googleHelper.driveActionFiles));
default:
return null;
} }
}); });
}, },