Skip to content

feat: choose a Google Drive folder for experiment data - #156

Merged
jodeleeuw merged 2 commits into
testfrom
provider-migration
Jul 25, 2026
Merged

feat: choose a Google Drive folder for experiment data#156
jodeleeuw merged 2 commits into
testfrom
provider-migration

Conversation

@jodeleeuw

Copy link
Copy Markdown
Member

What

Lets researchers optionally pick which existing Google Drive folder an experiment's data folder is created in, via the Google Picker. If no folder is chosen, behavior is unchanged (My Drive/DataPipe/<title>). Per-experiment.

Builds on the OAuth fix already on test.

Changes

Backend (022c24a)

  • POST /api/getprovideraccesstoken — owner-authenticated; returns a short-lived drive.file access token to the browser for Picker use (nothing else). Minted via resolve-token from the stored refresh token.
  • gdriveProvider.createDataContainer — creates the experiment folder under a supplied parentId; unchanged My Drive/DataPipe fallback when absent.
  • createExperiment — plumbs optional parentFolderId through.

Front-end (3e0a773)

  • lib/google-picker.js — isolated, memoized, SSR-guarded gapi/Picker loader; pickDriveFolder(){ id, name } | null. Folder-only view, setAppId so the drive.file grant ties to our app.
  • pages/admin/new.js (gdrive path only) — "Choose Drive folder" button → fetches token → opens Picker → passes selection into creation.
  • createProviderExperiment forwards parentFolderId.
  • Deploy workflow env: NEXT_PUBLIC_GOOGLE_PICKER_API_KEY (referrer/API-restricted, browser-safe) + NEXT_PUBLIC_GDRIVE_PROJECT_NUMBER.

Additive / backward-compatible

parentFolderId is optional everywhere; existing OSF and default-folder flows are untouched.

Cloud setup already done (datapipe-test)

Drive API + Picker API enabled; restricted browser API key created; env vars wired.

Tests

Backend: full auth/validation matrix on the endpoint + parent-placement + default-path regression (emulator). Front-end: parentFolderId forwarding/omission, Picker single-injection + PICKED/CANCEL. Verified green (backend 36/36, front-end 11/11), clean builds.

⚠️ Validate after deploy — the linchpin

Session data is written server-side. That only works if the Picker's drive.file grant lets a later server token (same OAuth client) write into the picked folder. Folder creation will work regardless; the real check is: create an experiment in a picked folder, submit a real data session, and confirm the file lands in a subfolder of that folder. If the session write 403s, the grant assumption needs revisiting.

🤖 Generated with Claude Code

jodeleeuw and others added 2 commits July 25, 2026 13:03
Backend for per-experiment Google Drive folder selection. The Picker UI
(front-end, next) lets a researcher pick an existing Drive folder; these
pieces let the picked folder become the experiment's data-folder parent
instead of the fixed My Drive/DataPipe.

- getProviderAccessToken (/api/getprovideraccesstoken): owner-authenticated
  endpoint returning a short-lived drive.file access token to the browser
  for Picker use, minted via resolve-token from the stored refresh token.
  Returns the access token only -- no refresh token or other user data.
- gdriveProvider.createDataContainer: create the experiment folder under a
  researcher-supplied parentId when present; unchanged My Drive/DataPipe
  fallback when absent.
- createExperiment: plumb optional parentFolderId through to the container.

Additive and backward-compatible: parentFolderId is optional and the new
endpoint is unused until the Picker UI lands. Emulator tests cover the
endpoint's full auth/validation matrix and the parent-placement behavior
(plus a default-path regression). Verified green (36/36) + clean build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Lets researchers optionally choose which existing Drive folder an
experiment's data folder is created in, via the Google Picker. If no
folder is chosen, behavior is unchanged (My Drive/DataPipe/<title>).

- lib/google-picker.js: isolated gapi/Picker loader (memoized, SSR-guarded)
  exposing pickDriveFolder() -> { id, name } | null (cancel). Builds a
  folder-only DocsView with setAppId so the drive.file grant ties to our
  app and the picked folder is writable server-side later.
- pages/admin/new.js (gdrive path only): a "Choose Drive folder" button that
  fetches a short-lived token from /api/getprovideraccesstoken, opens the
  Picker, and stores the selection; passed to createProviderExperiment.
- createProviderExperiment forwards the optional parentFolderId.
- firebase-deploy-test.yml: NEXT_PUBLIC_GOOGLE_PICKER_API_KEY (referrer/API
  restricted, browser-safe) + NEXT_PUBLIC_GDRIVE_PROJECT_NUMBER.

Tests: parentFolderId forwarding/omission, picker script single-injection +
PICKED/CANCEL paths; existing new-experiment-page regression intact.
Verified: 11/11 front-end tests green, build compiles.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jodeleeuw
jodeleeuw merged commit ec8380d into test Jul 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant