mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Decided on 2026-10-14. On the import page each of the six asks for what its service needs - a self-hosted Planka its address, username and password; the others an access token (Basecamp also its account id) - lists what that account can import, and fetches the chosen board, list or project. The credentials go with each call and are used for that call's requests only; they are never stored or logged, and the page clears secret fields once a fetch has used them. The fetched JSON fills the import text box and the import goes on as for a pasted export: the service's parser (models/lib/<key>ApiFormat.js) into the generalized importer, with the members step and the loss report. The same JSON can be pasted, or posted to POST /api/boards/import/<key>. - server/apiImport.js: apiImportList and apiImportFetch, signed in only, off with the Admin Panel's import switch, not in Sandstorm, rate limited; credentials checked against the service's own fields (models/lib/apiImportServices.js). - server/lib/apiImportRequest.js: every request through the SSRF guard - pinned address, no redirects, bounded in time and size - so a Planka address cannot point the server at its own network; an administrator can allow such a host with API_IMPORT_ALLOWED_PRIVATE_HOSTS. An error names only the origin and the status. - models/lib/apiImport/<key>.js: each service's client, plain Node with the request injected, paging bounded and the token only in a header. - Each has a docs page under docs/Features/ImportExport/, listed in the coverage index and External-Tools.md. Tests: tests/<key>ApiImport.test.cjs (client with a fake request, every parsed field, wrong shapes), tests/apiImport.test.cjs (credentials, the gate, the wiring, the shapes refused), api-import.e2e.js (the form for every service, fetched JSON imported through the page, refusals incl. a private address). Live tests, read only, run from build.sh / build.bat -> Tests -> Live tests with your own accounts (releases/live-tests/README.md); they were not run here. New strings translated in all locales. Also: the release risk baseline allows the services' API addresses, and the guards that count import creators, list the import sources and pin the platform fetch() calls know the new ones. Thanks to xet7 !
68 lines
3.2 KiB
JavaScript
68 lines
3.2 KiB
JavaScript
// Google Tasks API client for the import page (models/lib/apiImportServices.js).
|
|
// credentials: { token } - an OAuth 2 access token with the scope
|
|
// https://www.googleapis.com/auth/tasks.readonly. The token goes in the
|
|
// Authorization header only, never in a URL.
|
|
|
|
const API = 'https://tasks.googleapis.com/tasks/v1';
|
|
export const ALL = 'all';
|
|
export const MAX_LISTS = 100;
|
|
export const MAX_PAGES = 200;
|
|
export const MAX_TASKS = 20000;
|
|
|
|
function headers(credentials) {
|
|
const token = credentials && typeof credentials.token === 'string' ? credentials.token.trim() : '';
|
|
if (!token) throw new Error('A Google Tasks access token is required');
|
|
return { Authorization: `Bearer ${token}`, Accept: 'application/json' };
|
|
}
|
|
|
|
// Every item of a paged Google API collection, following nextPageToken. A
|
|
// page token seen before, too many pages or too many items stop it.
|
|
async function paged(url, credentials, request, limit) {
|
|
const items = [];
|
|
const seen = new Set();
|
|
let pageToken = '';
|
|
for (let page = 0; ; page += 1) {
|
|
if (page >= MAX_PAGES) throw new Error('Google Tasks returned too many pages');
|
|
const answer = await request(pageToken ? `${url}&pageToken=${encodeURIComponent(pageToken)}` : url,
|
|
{ method: 'GET', headers: headers(credentials) });
|
|
if (!answer || typeof answer !== 'object') throw new Error('Google Tasks returned an unexpected answer');
|
|
if (Array.isArray(answer.items)) items.push(...answer.items);
|
|
if (items.length > limit) throw new Error(`Google Tasks has more than ${limit} items to import`);
|
|
const next = typeof answer.nextPageToken === 'string' ? answer.nextPageToken : '';
|
|
if (!next) return items;
|
|
if (seen.has(next)) throw new Error('Google Tasks repeated a page token');
|
|
seen.add(next);
|
|
pageToken = next;
|
|
}
|
|
}
|
|
|
|
const listsOf = (credentials, request) =>
|
|
paged(`${API}/users/@me/lists?maxResults=100`, credentials, request, MAX_LISTS);
|
|
|
|
export async function list(credentials, request) {
|
|
const lists = await listsOf(credentials, request);
|
|
return [{ id: ALL, name: 'Google Tasks (all lists)' }, ...lists
|
|
.filter(item => item && typeof item.id === 'string' && item.id)
|
|
.map(item => ({ id: item.id, name: typeof item.title === 'string' && item.title.trim() ? item.title.trim() : item.id }))];
|
|
}
|
|
|
|
export async function fetch(credentials, id, request) {
|
|
if (typeof id !== 'string' || !id) throw new Error('Choose what to import');
|
|
let lists;
|
|
if (id === ALL) {
|
|
lists = (await listsOf(credentials, request)).filter(item => item && typeof item.id === 'string' && item.id);
|
|
} else {
|
|
const one = await request(`${API}/users/@me/lists/${encodeURIComponent(id)}`, { method: 'GET', headers: headers(credentials) });
|
|
lists = [{ id, title: one && typeof one.title === 'string' ? one.title : id }];
|
|
}
|
|
let count = 0;
|
|
const out = [];
|
|
for (const taskList of lists) {
|
|
const tasks = await paged(`${API}/lists/${encodeURIComponent(taskList.id)}/tasks?maxResults=100&showCompleted=true&showHidden=true`,
|
|
credentials, request, MAX_TASKS - count);
|
|
count += tasks.length;
|
|
out.push({ id: taskList.id, title: typeof taskList.title === 'string' ? taskList.title : '', tasks });
|
|
}
|
|
return { googletasks: true, lists: out };
|
|
}
|