mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Adding import from google drive to the home screen
Summary: Importing from google drive from home screen (also for anonymous users) Test Plan: Browser tests Reviewers: dsagal, paulfitz Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2943
This commit is contained in:
57
app/client/lib/HomePluginManager.ts
Normal file
57
app/client/lib/HomePluginManager.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import {ClientScope} from 'app/client/components/ClientScope';
|
||||
import {SafeBrowser} from 'app/client/lib/SafeBrowser';
|
||||
import {LocalPlugin} from 'app/common/plugin';
|
||||
import {createRpcLogger, PluginInstance} from 'app/common/PluginInstance';
|
||||
|
||||
/**
|
||||
* Home plugins are all plugins that contributes to a general Grist management tasks.
|
||||
* They operate on Grist as a whole, without current document context.
|
||||
* TODO: currently it is used primary for importing documents on home screen and supports
|
||||
* only safeBrowser components without any access to Grist.
|
||||
*/
|
||||
export class HomePluginManager {
|
||||
|
||||
public pluginsList: PluginInstance[];
|
||||
|
||||
constructor(localPlugins: LocalPlugin[],
|
||||
_untrustedContentOrigin: string,
|
||||
_clientScope: ClientScope) {
|
||||
this.pluginsList = [];
|
||||
for (const plugin of localPlugins) {
|
||||
try {
|
||||
const components = plugin.manifest.components || {};
|
||||
// Home plugins supports only safeBrowser components
|
||||
if (components.safePython || components.unsafeNode) {
|
||||
continue;
|
||||
}
|
||||
// and currently implements only safe imports
|
||||
const importSources = plugin.manifest.contributions.importSources;
|
||||
if (!importSources?.some(i => i.safeHome)) {
|
||||
continue;
|
||||
}
|
||||
const pluginInstance = new PluginInstance(plugin, createRpcLogger(console, `HOME PLUGIN ${plugin.id}:`));
|
||||
const safeBrowser = pluginInstance.safeBrowser = new SafeBrowser(pluginInstance,
|
||||
_clientScope, _untrustedContentOrigin, components.safeBrowser);
|
||||
if (components.safeBrowser) {
|
||||
pluginInstance.rpc.registerForwarder(components.safeBrowser, safeBrowser);
|
||||
}
|
||||
const forwarder = new NotAvailableForwarder();
|
||||
// Block any calls to internal apis.
|
||||
pluginInstance.rpc.registerForwarder('*', {
|
||||
forwardCall: (call) => forwarder.forwardPluginRpc(plugin.id, call),
|
||||
forwardMessage: (msg) => forwarder.forwardPluginRpc(plugin.id, msg),
|
||||
});
|
||||
this.pluginsList.push(pluginInstance);
|
||||
} catch (err) {
|
||||
console.error( // tslint:disable-line:no-console
|
||||
`HomePluginManager: failed to instantiate ${plugin.id}: ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NotAvailableForwarder {
|
||||
public async forwardPluginRpc(pluginId: string, msg: any) {
|
||||
throw new Error("This api is not available");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user