Implement governed distribution lists
This commit is contained in:
@@ -1,11 +1,48 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from govoplan_core.core.access import CAPABILITY_AUTH_PERMISSION_EVALUATOR, CAPABILITY_AUTH_PRINCIPAL_RESOLVER
|
||||
from govoplan_core.core.modules import DocumentationTopic, ModuleInterfaceProvider, ModuleManifest, PermissionDefinition, RoleTemplate
|
||||
from pathlib import Path
|
||||
|
||||
from govoplan_core.core.access import (
|
||||
CAPABILITY_AUTH_PERMISSION_EVALUATOR,
|
||||
CAPABILITY_AUTH_PRINCIPAL_RESOLVER,
|
||||
)
|
||||
from govoplan_core.core.dataflows import CAPABILITY_DATAFLOW_DATASET_OUTPUT
|
||||
from govoplan_core.core.distribution_lists import (
|
||||
CAPABILITY_DISTRIBUTION_LIST_EXPAND,
|
||||
CAPABILITY_DISTRIBUTION_LIST_SOURCE,
|
||||
CAPABILITY_DISTRIBUTION_LIST_WRITER,
|
||||
CAPABILITY_POLICY_DISTRIBUTION_CHANNELS,
|
||||
CAPABILITY_RECIPIENT_CHANNEL_FACTS,
|
||||
)
|
||||
from govoplan_core.core.identity import (
|
||||
CAPABILITY_IDENTITY_DIRECTORY,
|
||||
CAPABILITY_IDENTITY_SEARCH,
|
||||
)
|
||||
from govoplan_core.core.idm import CAPABILITY_IDM_FUNCTION_ASSIGNMENTS
|
||||
from govoplan_core.core.module_guards import (
|
||||
drop_table_retirement_provider,
|
||||
persistent_table_uninstall_guard,
|
||||
)
|
||||
from govoplan_core.core.modules import (
|
||||
DocumentationTopic,
|
||||
FrontendModule,
|
||||
FrontendRoute,
|
||||
MigrationSpec,
|
||||
ModuleContext,
|
||||
ModuleInterfaceProvider,
|
||||
ModuleManifest,
|
||||
NavItem,
|
||||
PermissionDefinition,
|
||||
RoleTemplate,
|
||||
)
|
||||
from govoplan_core.core.organizations import CAPABILITY_ORGANIZATION_DIRECTORY
|
||||
from govoplan_core.core.views import ViewSurface
|
||||
from govoplan_core.db.base import Base
|
||||
from govoplan_dist_lists.backend.db import models as dist_list_models
|
||||
|
||||
MODULE_ID = "dist_lists"
|
||||
MODULE_NAME = "Distribution Lists"
|
||||
MODULE_VERSION = "0.1.8"
|
||||
MODULE_VERSION = "0.1.14"
|
||||
|
||||
READ_SCOPE = "dist_lists:list:read"
|
||||
WRITE_SCOPE = "dist_lists:list:write"
|
||||
@@ -60,6 +97,36 @@ DOCUMENTATION = (
|
||||
)
|
||||
|
||||
|
||||
def _router(_context: ModuleContext):
|
||||
from govoplan_dist_lists.backend.router import router
|
||||
|
||||
return router
|
||||
|
||||
|
||||
def _capability(context: ModuleContext):
|
||||
from govoplan_dist_lists.backend.capabilities import capability
|
||||
|
||||
return capability(context)
|
||||
|
||||
|
||||
def _tenant_summary(session, tenant_id: str) -> dict[str, int]:
|
||||
return {
|
||||
"distribution_lists": (
|
||||
session.query(dist_list_models.DistributionList)
|
||||
.filter(
|
||||
dist_list_models.DistributionList.tenant_id == tenant_id,
|
||||
dist_list_models.DistributionList.deleted_at.is_(None),
|
||||
)
|
||||
.count()
|
||||
),
|
||||
"distribution_list_snapshots": (
|
||||
session.query(dist_list_models.DistributionListSnapshot)
|
||||
.filter(dist_list_models.DistributionListSnapshot.tenant_id == tenant_id)
|
||||
.count()
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
manifest = ModuleManifest(
|
||||
id=MODULE_ID,
|
||||
name=MODULE_NAME,
|
||||
@@ -69,8 +136,15 @@ manifest = ModuleManifest(
|
||||
"addresses",
|
||||
"access",
|
||||
"identity",
|
||||
"idm",
|
||||
"organizations",
|
||||
"datasources",
|
||||
"connectors",
|
||||
"dataflow",
|
||||
"policy",
|
||||
"campaigns",
|
||||
"templates",
|
||||
"reporting",
|
||||
"mail",
|
||||
"postbox",
|
||||
"notifications",
|
||||
@@ -79,14 +153,126 @@ manifest = ModuleManifest(
|
||||
"workflow_engine",
|
||||
"tasks",
|
||||
),
|
||||
optional_capabilities=(CAPABILITY_AUTH_PRINCIPAL_RESOLVER, CAPABILITY_AUTH_PERMISSION_EVALUATOR),
|
||||
optional_capabilities=(
|
||||
CAPABILITY_AUTH_PRINCIPAL_RESOLVER,
|
||||
CAPABILITY_AUTH_PERMISSION_EVALUATOR,
|
||||
CAPABILITY_IDENTITY_DIRECTORY,
|
||||
CAPABILITY_IDENTITY_SEARCH,
|
||||
CAPABILITY_IDM_FUNCTION_ASSIGNMENTS,
|
||||
CAPABILITY_ORGANIZATION_DIRECTORY,
|
||||
CAPABILITY_DATAFLOW_DATASET_OUTPUT,
|
||||
CAPABILITY_RECIPIENT_CHANNEL_FACTS,
|
||||
CAPABILITY_POLICY_DISTRIBUTION_CHANNELS,
|
||||
),
|
||||
provides_interfaces=(
|
||||
ModuleInterfaceProvider(name="dist_lists.source", version=MODULE_VERSION),
|
||||
ModuleInterfaceProvider(name="dist_lists.expand", version=MODULE_VERSION),
|
||||
ModuleInterfaceProvider(name="dist_lists.writer", version=MODULE_VERSION),
|
||||
ModuleInterfaceProvider(
|
||||
name=CAPABILITY_DISTRIBUTION_LIST_SOURCE,
|
||||
version=MODULE_VERSION,
|
||||
),
|
||||
ModuleInterfaceProvider(
|
||||
name=CAPABILITY_DISTRIBUTION_LIST_EXPAND,
|
||||
version=MODULE_VERSION,
|
||||
),
|
||||
ModuleInterfaceProvider(
|
||||
name=CAPABILITY_DISTRIBUTION_LIST_WRITER,
|
||||
version=MODULE_VERSION,
|
||||
),
|
||||
),
|
||||
permissions=PERMISSIONS,
|
||||
role_templates=ROLE_TEMPLATES,
|
||||
nav_items=(
|
||||
NavItem(
|
||||
path="/distribution-lists",
|
||||
label="Distribution Lists",
|
||||
icon="list-tree",
|
||||
required_any=(READ_SCOPE, WRITE_SCOPE, ADMIN_SCOPE),
|
||||
order=74,
|
||||
),
|
||||
),
|
||||
frontend=FrontendModule(
|
||||
module_id=MODULE_ID,
|
||||
package_name="@govoplan/dist-lists-webui",
|
||||
routes=(
|
||||
FrontendRoute(
|
||||
path="/distribution-lists",
|
||||
component="DistributionListsPage",
|
||||
required_any=(READ_SCOPE, WRITE_SCOPE, ADMIN_SCOPE),
|
||||
order=74,
|
||||
),
|
||||
),
|
||||
nav_items=(
|
||||
NavItem(
|
||||
path="/distribution-lists",
|
||||
label="Distribution Lists",
|
||||
icon="list-tree",
|
||||
required_any=(READ_SCOPE, WRITE_SCOPE, ADMIN_SCOPE),
|
||||
order=74,
|
||||
),
|
||||
),
|
||||
view_surfaces=(
|
||||
ViewSurface(
|
||||
id="dist_lists.page",
|
||||
module_id=MODULE_ID,
|
||||
kind="route",
|
||||
label="Distribution Lists",
|
||||
order=74,
|
||||
),
|
||||
ViewSurface(
|
||||
id="dist_lists.editor",
|
||||
module_id=MODULE_ID,
|
||||
kind="section",
|
||||
label="Distribution-list editor",
|
||||
order=10,
|
||||
),
|
||||
ViewSurface(
|
||||
id="dist_lists.preview",
|
||||
module_id=MODULE_ID,
|
||||
kind="section",
|
||||
label="Distribution-list expansion preview",
|
||||
order=20,
|
||||
),
|
||||
ViewSurface(
|
||||
id="dist_lists.picker",
|
||||
module_id=MODULE_ID,
|
||||
kind="action",
|
||||
label="Distribution-list picker",
|
||||
order=30,
|
||||
),
|
||||
),
|
||||
),
|
||||
route_factory=_router,
|
||||
capability_factories={
|
||||
CAPABILITY_DISTRIBUTION_LIST_SOURCE: _capability,
|
||||
CAPABILITY_DISTRIBUTION_LIST_EXPAND: _capability,
|
||||
CAPABILITY_DISTRIBUTION_LIST_WRITER: _capability,
|
||||
},
|
||||
tenant_summary_providers=(_tenant_summary,),
|
||||
migration_spec=MigrationSpec(
|
||||
module_id=MODULE_ID,
|
||||
metadata=Base.metadata,
|
||||
script_location=str(Path(__file__).with_name("migrations") / "versions"),
|
||||
retirement_supported=True,
|
||||
retirement_provider=drop_table_retirement_provider(
|
||||
dist_list_models.DistributionListSnapshot,
|
||||
dist_list_models.DistributionListEntry,
|
||||
dist_list_models.DistributionListRevision,
|
||||
dist_list_models.DistributionList,
|
||||
label=MODULE_NAME,
|
||||
),
|
||||
retirement_notes=(
|
||||
"Destructive retirement drops distribution-list definitions, immutable revisions, "
|
||||
"and frozen expansion evidence after the installer captures a database snapshot."
|
||||
),
|
||||
),
|
||||
uninstall_guard_providers=(
|
||||
persistent_table_uninstall_guard(
|
||||
dist_list_models.DistributionList,
|
||||
dist_list_models.DistributionListRevision,
|
||||
dist_list_models.DistributionListEntry,
|
||||
dist_list_models.DistributionListSnapshot,
|
||||
label=MODULE_NAME,
|
||||
),
|
||||
),
|
||||
documentation=DOCUMENTATION,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user