SurfSense/surfsense_local/backend/modules/plugins/installed/disconnect.py
Anish Sarkar 02fa327ed7 feat(plugins): disconnect keeps a plugin in Yours, Remove deletes it
Disconnect now drops only the key or sign-in: the plugin stays in Yours
with its tool settings, its tools are not offered, and Connect brings it
back with a sign-in, a key, or nothing to enter. Remove is the old
disconnect and deletes the plugin. The disconnected state is a new
column folded into the unreleased migration 0028.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 03:29:14 +05:30

22 lines
683 B
Python

"""Disconnecting a plugin: its sign-in goes, the row and the user's tool settings stay.
`credential_kind` stays too, so the screen knows whether connecting again needs a key,
an account sign-in, or nothing.
"""
from datetime import UTC, datetime
from sqlalchemy.orm import Session
from modules.plugins.installed.models import InstalledPlugin
def disconnect(session: Session, plugin_id: str) -> InstalledPlugin | None:
"""None when no such plugin is connected."""
plugin = session.get(InstalledPlugin, plugin_id)
if plugin is None:
return None
plugin.credential = None
plugin.disconnected_at = datetime.now(UTC)
session.flush()
return plugin