149 lines
5.5 KiB
Python
149 lines
5.5 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from govoplan_core.core.access import CAPABILITY_AUTH_PERMISSION_EVALUATOR, CAPABILITY_AUTH_PRINCIPAL_RESOLVER
|
|
from govoplan_core.core.module_guards import drop_table_retirement_provider, persistent_table_uninstall_guard
|
|
from govoplan_core.core.modules import (
|
|
DocumentationTopic,
|
|
MigrationSpec,
|
|
ModuleContext,
|
|
ModuleInterfaceProvider,
|
|
ModuleManifest,
|
|
PermissionDefinition,
|
|
RoleTemplate,
|
|
)
|
|
from govoplan_core.db.base import Base
|
|
from govoplan_poll.backend.db import models as poll_models # noqa: F401 - populate Poll ORM metadata
|
|
|
|
MODULE_ID = "poll"
|
|
MODULE_NAME = "Poll"
|
|
MODULE_VERSION = "0.1.8"
|
|
READ_SCOPE = "poll:poll:read"
|
|
WRITE_SCOPE = "poll:poll:write"
|
|
ADMIN_SCOPE = "poll:poll:admin"
|
|
RESPOND_SCOPE = "poll:response:write"
|
|
|
|
|
|
def _permission(scope: str, label: str, description: str) -> PermissionDefinition:
|
|
module_id, resource, action = scope.split(":", 2)
|
|
return PermissionDefinition(
|
|
scope=scope,
|
|
label=label,
|
|
description=description,
|
|
category="Poll",
|
|
level="tenant",
|
|
module_id=module_id,
|
|
resource=resource,
|
|
action=action,
|
|
)
|
|
|
|
|
|
PERMISSIONS = (
|
|
_permission(READ_SCOPE, "View polls", "Read poll definitions, invitations, responses, and result summaries."),
|
|
_permission(WRITE_SCOPE, "Manage polls", "Create, edit, close, reopen, and decide polls."),
|
|
_permission(ADMIN_SCOPE, "Administer polls", "Configure tenant-level polling policies and visibility defaults."),
|
|
_permission(RESPOND_SCOPE, "Respond to polls", "Submit and update own poll responses where policy allows it."),
|
|
)
|
|
|
|
ROLE_TEMPLATES = (
|
|
RoleTemplate(
|
|
slug="poll_manager",
|
|
name="Poll manager",
|
|
description="Create, manage, close, and decide polls.",
|
|
permissions=(READ_SCOPE, WRITE_SCOPE, RESPOND_SCOPE),
|
|
),
|
|
RoleTemplate(
|
|
slug="poll_participant",
|
|
name="Poll participant",
|
|
description="Read assigned polls and submit own responses.",
|
|
permissions=(READ_SCOPE, RESPOND_SCOPE),
|
|
),
|
|
)
|
|
|
|
DOCUMENTATION = (
|
|
DocumentationTopic(
|
|
id="poll.module-boundary",
|
|
title="Poll module boundary",
|
|
summary="Lightweight decision and availability polls for reusable module integrations.",
|
|
body=(
|
|
"Poll owns reusable poll definitions, options, invitations, responses, visibility rules, "
|
|
"closing semantics, and result summaries. Scheduling consumes Poll for availability "
|
|
"matrices, while Evaluation owns heavier surveys, scoring, rubrics, and analytics. "
|
|
"Access is optional: when installed, Poll can use principal resolution, permission "
|
|
"evaluation, and role templates; without it, Poll is limited to anonymous, signed-link, "
|
|
"or adapter-provided participant flows."
|
|
),
|
|
layer="available",
|
|
documentation_types=("admin",),
|
|
audience=("operator", "module_admin", "product_owner"),
|
|
related_modules=("scheduling", "evaluation", "calendar", "campaigns", "portal"),
|
|
metadata={"seed": True},
|
|
),
|
|
)
|
|
|
|
|
|
def _tenant_summary(session, tenant_id: str) -> dict[str, int]:
|
|
from govoplan_poll.backend.db.models import Poll, PollInvitation, PollResponse
|
|
|
|
return {
|
|
"polls": session.query(Poll).filter(Poll.tenant_id == tenant_id, Poll.deleted_at.is_(None)).count(),
|
|
"poll_invitations": session.query(PollInvitation).filter(PollInvitation.tenant_id == tenant_id).count(),
|
|
"poll_responses": session.query(PollResponse).filter(PollResponse.tenant_id == tenant_id, PollResponse.deleted_at.is_(None)).count(),
|
|
}
|
|
|
|
|
|
def _poll_router(_context: ModuleContext):
|
|
from govoplan_poll.backend.router import router
|
|
|
|
return router
|
|
|
|
|
|
manifest = ModuleManifest(
|
|
id=MODULE_ID,
|
|
name=MODULE_NAME,
|
|
version=MODULE_VERSION,
|
|
dependencies=(),
|
|
optional_dependencies=("access", "calendar", "campaigns", "portal", "mail", "notifications", "forms_runtime"),
|
|
optional_capabilities=(CAPABILITY_AUTH_PRINCIPAL_RESOLVER, CAPABILITY_AUTH_PERMISSION_EVALUATOR),
|
|
provides_interfaces=(
|
|
ModuleInterfaceProvider(name="poll.option_selection", version="0.1.8"),
|
|
ModuleInterfaceProvider(name="poll.availability_matrix", version="0.1.8"),
|
|
ModuleInterfaceProvider(name="poll.response_collection", version="0.1.8"),
|
|
ModuleInterfaceProvider(name="poll.workflow_context", version="0.1.8"),
|
|
ModuleInterfaceProvider(name="poll.signed_participation", version="0.1.8"),
|
|
),
|
|
permissions=PERMISSIONS,
|
|
role_templates=ROLE_TEMPLATES,
|
|
route_factory=_poll_router,
|
|
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(
|
|
poll_models.Poll,
|
|
poll_models.PollInvitation,
|
|
poll_models.PollOption,
|
|
poll_models.PollResponse,
|
|
label="Poll",
|
|
),
|
|
retirement_notes="Destructive retirement drops poll-owned database tables after the installer captures a database snapshot.",
|
|
),
|
|
uninstall_guard_providers=(
|
|
persistent_table_uninstall_guard(
|
|
poll_models.Poll,
|
|
poll_models.PollInvitation,
|
|
poll_models.PollOption,
|
|
poll_models.PollResponse,
|
|
label="Poll",
|
|
),
|
|
),
|
|
documentation=DOCUMENTATION,
|
|
)
|
|
|
|
|
|
def get_manifest() -> ModuleManifest:
|
|
return manifest
|