Add admin UI for platform credentials (env-dominant resolution)#60
Merged
Conversation
The README documented a "Settings → Platform Credentials" admin UI, but it never worked: the page was a "coming soon" placeholder, the Django admin forced the credentials field read-only, and nothing ever set the `is_configured` flag the runtime gates on — so the DB-credential path was dead and credentials could only come from `.env`. This makes the existing Django admin usable and wires per-org DB credentials into the runtime, while keeping `.env` authoritative. - PlatformCredential.save() derives `is_configured` from the credential values via a per-platform required-keys map (TikTok `client_key`, Meta/Pinterest `app_id` aliases, etc.), so a row only activates when it is actually usable. - New PlatformCredentialAdminForm: a real `forms.JSONField` (avoids a Python-repr corruption trap on the encrypted field), validates required keys, limits the platform choices to credential-bearing platforms. Admin restricted to superusers (editing reveals decrypted secrets). - resolve_platform_credentials(platform, org_id): one env-dominant resolver (env wins when complete, else the org's admin row). All five credential-resolution call sites route through it (they were DB-first before). - Webhooks: verify the Meta HMAC per owning-org secret (resolve_app_secret) so one org's secret cannot forge events into another org's accounts. - Remove the dormant /credentials/ placeholder (view, url, template, include). - Docs: README + .env.example reflect the real admin path, the env-dominant precedence rule, and how to create a superuser. Tests: per-platform env backwards-compat, cross-tenant webhook isolation, admin superuser gating, resolver precedence. Full suite green; ruff clean; no migration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 9, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes the Django admin usable for entering per-organization platform API credentials and wires them into the runtime, while keeping
.envauthoritative.is_configuredis derived on save from a per-platform required-keys map (TikTokclient_key, Meta/Pinterestapp_id/app_secretaliases, …), so a row only activates when it's actually usable.PlatformCredentialAdminForm— a realforms.JSONField(avoids a Python-repr corruption trap on the encrypted field), validates required keys, and limits platform choices to credential-bearing platforms. The admin is restricted to superusers (editing reveals decrypted secrets).resolve_platform_credentials(platform, org_id)—.envwins when complete, otherwise the org's admin-entered row. All five credential-resolution call sites (social_accounts/views.py,social_accounts/tasks.py,publisher/engine.py,composer/views.py,analytics/tasks.py) route through it (they were DB-first before).resolve_app_secret), so one org's secret can't forge events into another org's accounts./credentials/placeholder (view, url, template, and theconfig/urls.pyinclude); theapps.credentialsapp itself stays..env.exampledescribe the real admin path ({APP_URL}/admin/→ Credentials → Platform credentials, superuser only), the env-dominant precedence rule, and how to create a superuser.Why?
The README advertised a "Settings → Platform Credentials" admin UI that never worked: the page was a "coming soon" placeholder, the admin forced the credentials field read-only, and nothing ever set the
is_configuredflag the runtime gates on — so the DB path was dead and credentials could only be supplied via.env. This closes that gap (self-hosters can configure credentials per org from the admin) without changing behavior for existing.envdeployments.How to test
pytest apps/credentials apps/inbox/tests/test_webhooks.py— covers derivation, env-dominant resolution + per-platform.envbackwards-compat, the admin form round-trip, superuser-only gating, and cross-tenant webhook isolation.SECRET_KEY+ENCRYPTION_KEY_SALTset, runpython manage.py createsuperuser, sign in at{APP_URL}/admin/→ Credentials → Platform credentials, add e.g. ayoutuberow{"client_id": "...", "client_secret": "..."}→ it saves and showsis_configured = True. With no YouTube.envvars the connect flow uses the DB creds; set the.envvars and.envtakes precedence..env-only deployments are unchanged — every platform's real env key shape still resolves (parametrized backwards-compat tests).Checklist
pytest) — full suite greenruff checkandruff format --check) on changed files.env.example)