After a manifest refresh, clear source_repo on any installed plugins whose slug is no longer listed in the repo's manifest. Also syncs the 'deprecated' flag for all plugins that remain managed by this repo.
(repo, new_manifest_data)
| 363 | |
| 364 | |
| 365 | def _unmanage_dropped_slugs(repo, new_manifest_data): |
| 366 | """After a manifest refresh, clear source_repo on any installed plugins |
| 367 | whose slug is no longer listed in the repo's manifest. Also syncs the |
| 368 | 'deprecated' flag for all plugins that remain managed by this repo.""" |
| 369 | manifest = new_manifest_data.get("manifest", new_manifest_data) |
| 370 | plugin_entries = {p["slug"]: p for p in manifest.get("plugins", []) if p.get("slug")} |
| 371 | current_slugs = set(plugin_entries.keys()) |
| 372 | |
| 373 | dropped = PluginConfig.objects.filter(source_repo=repo).exclude(slug__in=current_slugs) |
| 374 | count = dropped.update(source_repo=None, slug="", deprecated=False) |
| 375 | if count: |
| 376 | logger.info( |
| 377 | "Unmanaged %d plugin(s) removed from repo '%s' manifest", |
| 378 | count, repo.name, |
| 379 | ) |
| 380 | |
| 381 | # Sync deprecated flag for retained managed plugins |
| 382 | for cfg in PluginConfig.objects.filter(source_repo=repo, slug__in=current_slugs): |
| 383 | new_deprecated = bool(plugin_entries.get(cfg.slug, {}).get("deprecated", False)) |
| 384 | if cfg.deprecated != new_deprecated: |
| 385 | cfg.deprecated = new_deprecated |
| 386 | cfg.save(update_fields=["deprecated", "updated_at"]) |
| 387 | |
| 388 | |
| 389 | class PluginImportAPIView(PluginAuthMixin, APIView): |