Skip to content

Commit

Permalink
✨(organization) add admin action for plugin
Browse files Browse the repository at this point in the history
This allows admin user to run the post creation plugins
from the organization list.
  • Loading branch information
qbey committed Jan 16, 2025
1 parent 632a78c commit 76fc789
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to

### Added

- ✨(organization) add admin action for plugin #640
- ✨(anct) fetch and display organization names of communes #583
- ✨(frontend) display email if no username #562
- 🧑‍💻(oidc) add ability to pull registration ID (e.g. SIRET) from OIDC #577
Expand Down
26 changes: 25 additions & 1 deletion src/backend/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""Admin classes and registrations for People's core app."""

from django.contrib import admin
from django.contrib import admin, messages
from django.contrib.auth import admin as auth_admin
from django.utils.translation import gettext_lazy as _

from mailbox_manager.admin import MailDomainAccessInline

from . import models
from .plugins.loader import (
get_organization_plugins,
organization_plugins_run_after_create,
)


class TeamAccessInline(admin.TabularInline):
Expand Down Expand Up @@ -206,10 +210,23 @@ class OrganizationServiceProviderInline(admin.TabularInline):
extra = 0


@admin.action(description=_("Run post creation plugins"), permissions=["change"])
def run_post_creation_plugins(modeladmin, request, queryset): # pylint: disable=unused-argument
"""Run the post creation plugins for the selected organizations."""
for organization in queryset:
organization_plugins_run_after_create(organization)

messages.success(
request,
_("Post creation plugins have been run for the selected organizations."),
)


@admin.register(models.Organization)
class OrganizationAdmin(admin.ModelAdmin):
"""Admin interface for organizations."""

actions = [run_post_creation_plugins]
list_display = (
"name",
"created_at",
Expand All @@ -219,6 +236,13 @@ class OrganizationAdmin(admin.ModelAdmin):
inlines = (OrganizationAccessInline, OrganizationServiceProviderInline)
exclude = ("service_providers",) # Handled by the inline

def get_actions(self, request):
"""Adapt actions list to the context."""
actions = super().get_actions(request)
if not get_organization_plugins():
actions.pop("run_post_creation_plugins", None)
return actions


@admin.register(models.OrganizationAccess)
class OrganizationAccessAdmin(admin.ModelAdmin):
Expand Down

0 comments on commit 76fc789

Please sign in to comment.