Implement unified work inbox module
This commit is contained in:
@@ -0,0 +1,341 @@
|
||||
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 (
|
||||
CapabilityDocumentation,
|
||||
DocumentationLink,
|
||||
DocumentationTopic,
|
||||
FrontendModule,
|
||||
FrontendRoute,
|
||||
MigrationSpec,
|
||||
ModuleContext,
|
||||
ModuleInterfaceProvider,
|
||||
ModuleManifest,
|
||||
NavItem,
|
||||
PermissionDefinition,
|
||||
RoleTemplate,
|
||||
)
|
||||
from govoplan_core.core.provider_governance import declared_module_architecture
|
||||
from govoplan_core.core.tasks import (
|
||||
CAPABILITY_TASK_COMMANDS,
|
||||
WorkItemProviderRegistration,
|
||||
)
|
||||
from govoplan_core.core.views import ViewSurface
|
||||
from govoplan_core.db.base import Base
|
||||
from govoplan_tasks.backend.db import models as task_models
|
||||
from govoplan_tasks.backend.service import SqlTaskService
|
||||
|
||||
|
||||
MODULE_ID = "tasks"
|
||||
MODULE_NAME = "Tasks"
|
||||
MODULE_VERSION = "0.1.18"
|
||||
READ_SCOPE = "tasks:item:read"
|
||||
WRITE_SCOPE = "tasks:item:write"
|
||||
ADMIN_SCOPE = "tasks:item:admin"
|
||||
|
||||
|
||||
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="Tasks",
|
||||
level="tenant",
|
||||
module_id=module_id,
|
||||
resource=resource,
|
||||
action=action,
|
||||
)
|
||||
|
||||
|
||||
def _router(context: ModuleContext):
|
||||
from govoplan_tasks.backend.router import create_router
|
||||
|
||||
return create_router(context.registry)
|
||||
|
||||
|
||||
def _service(context: ModuleContext) -> SqlTaskService:
|
||||
return SqlTaskService(context.registry)
|
||||
|
||||
|
||||
def _tenant_summary(session, tenant_id: str) -> dict[str, int]:
|
||||
total = (
|
||||
session.query(task_models.TaskItem)
|
||||
.filter(task_models.TaskItem.tenant_id == tenant_id)
|
||||
.count()
|
||||
)
|
||||
open_items = (
|
||||
session.query(task_models.TaskItem)
|
||||
.filter(
|
||||
task_models.TaskItem.tenant_id == tenant_id,
|
||||
task_models.TaskItem.status.in_(
|
||||
("open", "in_progress", "deferred", "blocked")
|
||||
),
|
||||
)
|
||||
.count()
|
||||
)
|
||||
return {"tasks": total, "open_tasks": open_items}
|
||||
|
||||
|
||||
PERMISSIONS = (
|
||||
_permission(
|
||||
READ_SCOPE,
|
||||
"View assigned work",
|
||||
"Read explicit and contributed work visible to the current account, group, role, or function.",
|
||||
),
|
||||
_permission(
|
||||
WRITE_SCOPE,
|
||||
"Manage assigned work",
|
||||
"Create explicit tasks and advance visible task state.",
|
||||
),
|
||||
_permission(
|
||||
ADMIN_SCOPE,
|
||||
"Administer tenant work",
|
||||
"Read and recover all explicit tasks in the tenant.",
|
||||
),
|
||||
)
|
||||
|
||||
ROLE_TEMPLATES = (
|
||||
RoleTemplate(
|
||||
slug="work_participant",
|
||||
name="Work participant",
|
||||
description="Read and advance assigned work and create explicit tasks.",
|
||||
permissions=(READ_SCOPE, WRITE_SCOPE),
|
||||
),
|
||||
RoleTemplate(
|
||||
slug="work_supervisor",
|
||||
name="Work supervisor",
|
||||
description="Inspect and recover tenant-wide work in addition to participating.",
|
||||
permissions=(READ_SCOPE, WRITE_SCOPE, ADMIN_SCOPE),
|
||||
),
|
||||
)
|
||||
|
||||
DOCUMENTATION = (
|
||||
DocumentationTopic(
|
||||
id="tasks.work-inbox",
|
||||
title="Unified work inbox",
|
||||
summary="Resume explicit tasks and module-owned work requiring attention.",
|
||||
body=(
|
||||
"The Work inbox combines explicit Tasks with work contributed by enabled modules. "
|
||||
"Each source keeps ownership of its commands and completion state. Tasks does not turn a "
|
||||
"Workflow handoff, Postbox message, approval, or notification into a copied task. Filters, "
|
||||
"due dates, priorities, and source links help the current actor resume work safely."
|
||||
),
|
||||
layer="configured",
|
||||
documentation_types=("user", "admin"),
|
||||
audience=("user", "operator", "tenant_admin", "module_admin"),
|
||||
related_modules=(
|
||||
"workflow_engine",
|
||||
"notifications",
|
||||
"postbox",
|
||||
"approvals",
|
||||
"views",
|
||||
"dashboard",
|
||||
),
|
||||
links=(
|
||||
DocumentationLink(
|
||||
label="Tasks domain",
|
||||
href="govoplan-tasks/docs/TASKS_DOMAIN.md",
|
||||
kind="repository",
|
||||
),
|
||||
),
|
||||
translations={
|
||||
"de": {
|
||||
"title": "Gemeinsamer Arbeitsvorrat",
|
||||
"summary": "Explizite Aufgaben und Arbeitsvorgaenge anderer Module sicher fortsetzen.",
|
||||
"body": (
|
||||
"Der Arbeitsvorrat verbindet explizite Aufgaben mit Arbeitsobjekten aktivierter Module. "
|
||||
"Jede Quelle behaelt die Verantwortung fuer Befehle und Abschlussstatus. Tasks kopiert "
|
||||
"keine Workflow-Uebergabe, Postfachnachricht, Freigabe oder Benachrichtigung in einen "
|
||||
"zweiten Fachzustand. Filter, Fristen, Prioritaeten und Quellverweise helfen beim sicheren Fortsetzen."
|
||||
),
|
||||
}
|
||||
},
|
||||
metadata={
|
||||
"help_contexts": [
|
||||
"tasks.route.work",
|
||||
"tasks.page.inbox",
|
||||
"tasks.page.detail",
|
||||
"tasks.action.create",
|
||||
"tasks.action.advance",
|
||||
"tasks.field.assignment",
|
||||
"tasks.field.due-at",
|
||||
"tasks.field.priority",
|
||||
]
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
manifest = ModuleManifest(
|
||||
id=MODULE_ID,
|
||||
name=MODULE_NAME,
|
||||
version=MODULE_VERSION,
|
||||
dependencies=("access",),
|
||||
optional_dependencies=(
|
||||
"idm",
|
||||
"organizations",
|
||||
"workflow_engine",
|
||||
"workflow",
|
||||
"notifications",
|
||||
"postbox",
|
||||
"approvals",
|
||||
"views",
|
||||
"dashboard",
|
||||
"search",
|
||||
),
|
||||
required_capabilities=(
|
||||
CAPABILITY_AUTH_PRINCIPAL_RESOLVER,
|
||||
CAPABILITY_AUTH_PERMISSION_EVALUATOR,
|
||||
),
|
||||
provides_interfaces=(
|
||||
ModuleInterfaceProvider(name=CAPABILITY_TASK_COMMANDS, version="1.0.0"),
|
||||
ModuleInterfaceProvider(name="tasks.work_items", version="1.0.0"),
|
||||
),
|
||||
permissions=PERMISSIONS,
|
||||
role_templates=ROLE_TEMPLATES,
|
||||
route_factory=_router,
|
||||
nav_items=(
|
||||
NavItem(
|
||||
path="/tasks",
|
||||
label="Work",
|
||||
icon="list-checks",
|
||||
required_any=(READ_SCOPE,),
|
||||
order=21,
|
||||
surface_id="tasks.route.work",
|
||||
),
|
||||
),
|
||||
frontend=FrontendModule(
|
||||
module_id=MODULE_ID,
|
||||
package_name="@govoplan/tasks-webui",
|
||||
routes=(
|
||||
FrontendRoute(
|
||||
path="/tasks",
|
||||
component="TasksPage",
|
||||
required_any=(READ_SCOPE,),
|
||||
order=21,
|
||||
surface_id="tasks.route.work",
|
||||
),
|
||||
),
|
||||
view_surfaces=(
|
||||
ViewSurface(
|
||||
id="tasks.page.inbox",
|
||||
module_id=MODULE_ID,
|
||||
kind="section",
|
||||
label="Work inbox",
|
||||
parent_id="tasks.route.work",
|
||||
order=20,
|
||||
),
|
||||
ViewSurface(
|
||||
id="tasks.page.detail",
|
||||
module_id=MODULE_ID,
|
||||
kind="section",
|
||||
label="Work details",
|
||||
parent_id="tasks.route.work",
|
||||
order=30,
|
||||
),
|
||||
ViewSurface(
|
||||
id="tasks.action.create",
|
||||
module_id=MODULE_ID,
|
||||
kind="action",
|
||||
label="Create task",
|
||||
parent_id="tasks.page.inbox",
|
||||
order=40,
|
||||
),
|
||||
ViewSurface(
|
||||
id="tasks.action.advance",
|
||||
module_id=MODULE_ID,
|
||||
kind="action",
|
||||
label="Advance task",
|
||||
parent_id="tasks.page.detail",
|
||||
order=50,
|
||||
),
|
||||
ViewSurface(
|
||||
id="tasks.widget.open-work",
|
||||
module_id=MODULE_ID,
|
||||
kind="section",
|
||||
label="Open work widget",
|
||||
order=60,
|
||||
),
|
||||
),
|
||||
),
|
||||
tenant_summary_providers=(_tenant_summary,),
|
||||
capability_factories={CAPABILITY_TASK_COMMANDS: _service},
|
||||
capability_documentation={
|
||||
CAPABILITY_TASK_COMMANDS: CapabilityDocumentation(
|
||||
label="Task commands",
|
||||
summary="Creates replay-safe explicit tasks without importing the Tasks implementation.",
|
||||
contract_version="1.0.0",
|
||||
)
|
||||
},
|
||||
work_item_providers=(
|
||||
WorkItemProviderRegistration(id="tasks.explicit", factory=_service, order=10),
|
||||
),
|
||||
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(
|
||||
task_models.TaskAssignment, task_models.TaskItem, label="Tasks"
|
||||
),
|
||||
retirement_notes="Destructive retirement removes explicit task state after a database snapshot; contributed work remains with its owner.",
|
||||
),
|
||||
uninstall_guard_providers=(
|
||||
persistent_table_uninstall_guard(
|
||||
task_models.TaskItem, task_models.TaskAssignment, label="Tasks"
|
||||
),
|
||||
),
|
||||
documentation=DOCUMENTATION,
|
||||
architecture=declared_module_architecture(
|
||||
layer="human_work_procedure",
|
||||
kind="domain",
|
||||
maturity="vertical_slice",
|
||||
documentation_ref="docs/TASKS_DOMAIN.md",
|
||||
test_ref="tests/test_tasks.py",
|
||||
known_limits=(
|
||||
"Function assignment resolution depends on the optional IDM directory; source-owned inline commands remain deep links in this first slice.",
|
||||
),
|
||||
supported_authority_modes=("native_authoritative", "linked_reference"),
|
||||
owned_concepts=("explicit task", "task assignment", "unified work inbox"),
|
||||
non_owned_concepts=(
|
||||
"workflow instance",
|
||||
"notification",
|
||||
"postbox message",
|
||||
"approval request",
|
||||
"domain object",
|
||||
),
|
||||
reference_packages=(
|
||||
"product.service-to-decision",
|
||||
"product.governed-communication",
|
||||
"product.governed-data-assurance",
|
||||
),
|
||||
migration_docs=("docs/TASKS_DOMAIN.md",),
|
||||
recovery_docs=("docs/TASKS_DOMAIN.md",),
|
||||
security_docs=("docs/TASKS_DOMAIN.md",),
|
||||
operations_docs=("docs/TASKS_DOMAIN.md",),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def get_manifest() -> ModuleManifest:
|
||||
return manifest
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ADMIN_SCOPE",
|
||||
"MODULE_ID",
|
||||
"MODULE_VERSION",
|
||||
"READ_SCOPE",
|
||||
"WRITE_SCOPE",
|
||||
"get_manifest",
|
||||
"manifest",
|
||||
]
|
||||
Reference in New Issue
Block a user