Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
faf6b3305a | ||
|
|
88bd0e6aae | ||
|
|
39bb6c0d18 | ||
|
|
a8646e76a8 | ||
|
|
e8076700b0 | ||
|
|
f4739efd86 | ||
|
|
b9c2d061e5 | ||
|
|
4ec5d56055 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@govoplan/tasks",
|
"name": "@govoplan/tasks",
|
||||||
"version": "0.1.19",
|
"version": "0.1.20",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Governed work items and unified work inbox for GovOPlaN.",
|
"description": "Governed work items and unified work inbox for GovOPlaN.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "govoplan-tasks"
|
name = "govoplan-tasks"
|
||||||
version = "0.1.19"
|
version = "0.1.20"
|
||||||
description = "Governed work items and unified work inbox for GovOPlaN."
|
description = "Governed work items and unified work inbox for GovOPlaN."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"""GovOPlaN Tasks module."""
|
"""GovOPlaN Tasks module."""
|
||||||
|
|
||||||
__version__ = "0.1.19"
|
__version__ = "0.1.20"
|
||||||
|
|||||||
@@ -0,0 +1,410 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping, Sequence
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
from sqlalchemy import or_
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from govoplan_core.core.dsar import (
|
||||||
|
DsarErasureActionRef,
|
||||||
|
DsarExecutionResultRef,
|
||||||
|
DsarRecordRef,
|
||||||
|
DsarSubjectRef,
|
||||||
|
dsar_capability_name,
|
||||||
|
)
|
||||||
|
from govoplan_tasks.backend.db.models import TaskAssignment, TaskItem
|
||||||
|
|
||||||
|
|
||||||
|
TASKS_DSAR_CAPABILITY = dsar_capability_name("tasks")
|
||||||
|
_MAX_RECORDS = 5_000
|
||||||
|
_MAX_SOURCES = 100
|
||||||
|
_CONFLICT = object()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class _SubjectSelectors:
|
||||||
|
account_id: str | None
|
||||||
|
actor_ids: tuple[str, ...]
|
||||||
|
task_id: str | None
|
||||||
|
|
||||||
|
|
||||||
|
class TasksDsarProvider:
|
||||||
|
provider_id = "tasks"
|
||||||
|
module_id = "tasks"
|
||||||
|
|
||||||
|
def search_subject(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
subject: DsarSubjectRef,
|
||||||
|
) -> Sequence[DsarRecordRef]:
|
||||||
|
db = _session(session)
|
||||||
|
selectors = _subject_selectors(subject)
|
||||||
|
if selectors is None:
|
||||||
|
return ()
|
||||||
|
|
||||||
|
assigned_ids: set[str] = set()
|
||||||
|
if selectors.account_id:
|
||||||
|
assigned = (
|
||||||
|
db.query(TaskAssignment.task_id)
|
||||||
|
.join(TaskItem, TaskAssignment.task_id == TaskItem.id)
|
||||||
|
.filter(
|
||||||
|
TaskItem.tenant_id == tenant_id,
|
||||||
|
TaskAssignment.tenant_id == tenant_id,
|
||||||
|
TaskAssignment.assignment_kind == "account",
|
||||||
|
TaskAssignment.assignment_id == selectors.account_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if selectors.task_id:
|
||||||
|
assigned = assigned.filter(TaskItem.id == selectors.task_id)
|
||||||
|
rows = assigned.limit(_MAX_RECORDS + 1).all()
|
||||||
|
if len(rows) > _MAX_RECORDS:
|
||||||
|
raise ValueError(
|
||||||
|
"Tasks DSAR assignment result limit exceeded; narrow the selectors."
|
||||||
|
)
|
||||||
|
assigned_ids = {str(task_id) for (task_id,) in rows}
|
||||||
|
|
||||||
|
actor_query = db.query(TaskItem.id).filter(
|
||||||
|
TaskItem.tenant_id == tenant_id,
|
||||||
|
or_(
|
||||||
|
TaskItem.created_by.in_(selectors.actor_ids),
|
||||||
|
TaskItem.updated_by.in_(selectors.actor_ids),
|
||||||
|
TaskItem.completed_by.in_(selectors.actor_ids),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if selectors.task_id:
|
||||||
|
actor_query = actor_query.filter(TaskItem.id == selectors.task_id)
|
||||||
|
actor_rows = actor_query.limit(_MAX_RECORDS + 1).all()
|
||||||
|
if len(actor_rows) > _MAX_RECORDS:
|
||||||
|
raise ValueError(
|
||||||
|
"Tasks DSAR actor result limit exceeded; narrow the selectors."
|
||||||
|
)
|
||||||
|
actor_ids = {str(task_id) for (task_id,) in actor_rows}
|
||||||
|
|
||||||
|
task_ids = assigned_ids | actor_ids
|
||||||
|
if len(task_ids) > _MAX_RECORDS:
|
||||||
|
raise ValueError("Tasks DSAR result limit exceeded; narrow the selectors.")
|
||||||
|
if not task_ids:
|
||||||
|
return ()
|
||||||
|
tasks = (
|
||||||
|
db.query(TaskItem)
|
||||||
|
.filter(
|
||||||
|
TaskItem.tenant_id == tenant_id,
|
||||||
|
TaskItem.id.in_(task_ids),
|
||||||
|
)
|
||||||
|
.order_by(TaskItem.created_at, TaskItem.id)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
return tuple(
|
||||||
|
_assigned_task_record(
|
||||||
|
task,
|
||||||
|
account_id=selectors.account_id,
|
||||||
|
actor_ids=selectors.actor_ids,
|
||||||
|
)
|
||||||
|
if task.id in assigned_ids
|
||||||
|
else _actor_attribution_record(task, selectors.actor_ids)
|
||||||
|
for task in tasks
|
||||||
|
)
|
||||||
|
|
||||||
|
def plan_erasure(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
subject: DsarSubjectRef,
|
||||||
|
records: Sequence[DsarRecordRef],
|
||||||
|
) -> Sequence[DsarErasureActionRef]:
|
||||||
|
del tenant_id
|
||||||
|
_session(session)
|
||||||
|
if _subject_selectors(subject) is None:
|
||||||
|
raise ValueError("Tasks DSAR subject selectors conflict.")
|
||||||
|
actions: list[DsarErasureActionRef] = []
|
||||||
|
for record in records:
|
||||||
|
_validate_record(record)
|
||||||
|
if record.resource_type == "assigned_task":
|
||||||
|
actions.append(
|
||||||
|
DsarErasureActionRef(
|
||||||
|
action_id=f"tasks:manual_review:assigned_task:{record.resource_id}",
|
||||||
|
provider_id=self.provider_id,
|
||||||
|
module_id=self.module_id,
|
||||||
|
kind="manual_review",
|
||||||
|
resource_type=record.resource_type,
|
||||||
|
resource_id=record.resource_id,
|
||||||
|
title=f"Review {record.title}",
|
||||||
|
rationale=(
|
||||||
|
"The account assignment and task content may be shared "
|
||||||
|
"institutional work. Its source owner and retention state "
|
||||||
|
"must be reviewed before detachment or minimization."
|
||||||
|
),
|
||||||
|
executable=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
actions.append(
|
||||||
|
DsarErasureActionRef(
|
||||||
|
action_id=(
|
||||||
|
f"tasks:retain:task_actor_attribution:{record.resource_id}"
|
||||||
|
),
|
||||||
|
provider_id=self.provider_id,
|
||||||
|
module_id=self.module_id,
|
||||||
|
kind="retain",
|
||||||
|
resource_type=record.resource_type,
|
||||||
|
resource_id=record.resource_id,
|
||||||
|
title=f"Retain {record.title}",
|
||||||
|
rationale=record.retention_reason
|
||||||
|
or "Task lifecycle attribution is accountability evidence.",
|
||||||
|
executable=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return tuple(actions)
|
||||||
|
|
||||||
|
def execute_erasure(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
subject: DsarSubjectRef,
|
||||||
|
actions: Sequence[DsarErasureActionRef],
|
||||||
|
request_id: str,
|
||||||
|
) -> Sequence[DsarExecutionResultRef]:
|
||||||
|
del tenant_id
|
||||||
|
_session(session)
|
||||||
|
if _subject_selectors(subject) is None:
|
||||||
|
raise ValueError("Tasks DSAR subject selectors conflict.")
|
||||||
|
results: list[DsarExecutionResultRef] = []
|
||||||
|
for action in actions:
|
||||||
|
_validate_action(action)
|
||||||
|
if action.executable or action.kind not in {"retain", "manual_review"}:
|
||||||
|
raise ValueError("Tasks DSAR publishes non-executable actions only.")
|
||||||
|
results.append(
|
||||||
|
DsarExecutionResultRef(
|
||||||
|
action_id=action.action_id,
|
||||||
|
status="blocked",
|
||||||
|
summary=(
|
||||||
|
"The Task remains unchanged pending its institutional "
|
||||||
|
"retention and source-owner review."
|
||||||
|
if action.kind == "manual_review"
|
||||||
|
else "Task lifecycle attribution remains immutable evidence."
|
||||||
|
),
|
||||||
|
evidence={"request_id": request_id},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return tuple(results)
|
||||||
|
|
||||||
|
|
||||||
|
def _subject_selectors(subject: DsarSubjectRef) -> _SubjectSelectors | None:
|
||||||
|
references = subject.external_references
|
||||||
|
values = {
|
||||||
|
"account_id": _coalesce(
|
||||||
|
subject.account_id,
|
||||||
|
references.get("tasks.account"),
|
||||||
|
references.get("access.account"),
|
||||||
|
),
|
||||||
|
"membership_id": _coalesce(
|
||||||
|
subject.membership_id,
|
||||||
|
references.get("tasks.membership"),
|
||||||
|
references.get("tenancy.membership"),
|
||||||
|
),
|
||||||
|
"identity_id": _coalesce(
|
||||||
|
subject.identity_id,
|
||||||
|
references.get("tasks.identity"),
|
||||||
|
references.get("identity.id"),
|
||||||
|
),
|
||||||
|
"task_id": _coalesce(
|
||||||
|
references.get("tasks.task"),
|
||||||
|
references.get("tasks.item"),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
if any(value is _CONFLICT for value in values.values()):
|
||||||
|
return None
|
||||||
|
actor_ids = tuple(
|
||||||
|
dict.fromkeys(
|
||||||
|
value
|
||||||
|
for key in ("account_id", "membership_id", "identity_id")
|
||||||
|
if (value := _optional_string(values[key]))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if not actor_ids:
|
||||||
|
return None
|
||||||
|
return _SubjectSelectors(
|
||||||
|
account_id=_optional_string(values["account_id"]),
|
||||||
|
actor_ids=actor_ids,
|
||||||
|
task_id=_optional_string(values["task_id"]),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _coalesce(*values: str | None) -> str | None | object:
|
||||||
|
normalized = {str(value).strip() for value in values if str(value or "").strip()}
|
||||||
|
if len(normalized) > 1:
|
||||||
|
return _CONFLICT
|
||||||
|
return next(iter(normalized), None)
|
||||||
|
|
||||||
|
|
||||||
|
def _optional_string(value: object) -> str | None:
|
||||||
|
return value if isinstance(value, str) and value else None
|
||||||
|
|
||||||
|
|
||||||
|
def _assigned_task_record(
|
||||||
|
task: TaskItem,
|
||||||
|
*,
|
||||||
|
account_id: str | None,
|
||||||
|
actor_ids: Sequence[str],
|
||||||
|
) -> DsarRecordRef:
|
||||||
|
assignments = [
|
||||||
|
{
|
||||||
|
"id": assignment.id,
|
||||||
|
"kind": assignment.assignment_kind,
|
||||||
|
"assignment_id": assignment.assignment_id,
|
||||||
|
"label": (assignment.assignment_label or "")[:500] or None,
|
||||||
|
}
|
||||||
|
for assignment in task.assignments
|
||||||
|
if account_id
|
||||||
|
and assignment.assignment_kind == "account"
|
||||||
|
and assignment.assignment_id == account_id
|
||||||
|
]
|
||||||
|
if len(assignments) > 100:
|
||||||
|
raise ValueError("Task account assignments exceed the DSAR bound.")
|
||||||
|
return DsarRecordRef(
|
||||||
|
provider_id="tasks",
|
||||||
|
module_id="tasks",
|
||||||
|
resource_type="assigned_task",
|
||||||
|
resource_id=task.id,
|
||||||
|
category="assigned_institutional_work",
|
||||||
|
title=f"Assigned task: {task.title[:500]}",
|
||||||
|
data={
|
||||||
|
"title": task.title[:500],
|
||||||
|
"summary": (task.summary or "")[:4_000] or None,
|
||||||
|
"status": task.status,
|
||||||
|
"priority": task.priority,
|
||||||
|
"required_action": (task.required_action or "")[:500] or None,
|
||||||
|
"action_url": (task.action_url or "")[:1_500] or None,
|
||||||
|
"due_at": _iso(task.due_at),
|
||||||
|
"deferred_until": _iso(task.deferred_until),
|
||||||
|
"completed_at": _iso(task.completed_at),
|
||||||
|
"cancelled_at": _iso(task.cancelled_at),
|
||||||
|
"revision": task.revision,
|
||||||
|
"assignments": assignments,
|
||||||
|
"sources": _source_projection(task.sources),
|
||||||
|
"actor_activities": _actor_activities(task, actor_ids),
|
||||||
|
"created_at": _iso(task.created_at),
|
||||||
|
"updated_at": _iso(task.updated_at),
|
||||||
|
},
|
||||||
|
observed_at=_aware(task.updated_at),
|
||||||
|
retention_reason=(
|
||||||
|
"The task may be shared institutional work and requires source-owner "
|
||||||
|
"and retention review before its account assignment can be changed."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _actor_attribution_record(
|
||||||
|
task: TaskItem,
|
||||||
|
actor_ids: Sequence[str],
|
||||||
|
) -> DsarRecordRef:
|
||||||
|
return DsarRecordRef(
|
||||||
|
provider_id="tasks",
|
||||||
|
module_id="tasks",
|
||||||
|
resource_type="task_actor_attribution",
|
||||||
|
resource_id=task.id,
|
||||||
|
category="operator_accountability_evidence",
|
||||||
|
title="Task lifecycle attribution",
|
||||||
|
data={
|
||||||
|
"activities": _actor_activities(task, actor_ids),
|
||||||
|
"status": task.status,
|
||||||
|
"priority": task.priority,
|
||||||
|
"source_module": task.source_module,
|
||||||
|
"source_resource_type": task.source_resource_type,
|
||||||
|
"source_resource_id": task.source_resource_id,
|
||||||
|
"source_revision": task.source_revision,
|
||||||
|
"revision": task.revision,
|
||||||
|
"created_at": _iso(task.created_at),
|
||||||
|
"updated_at": _iso(task.updated_at),
|
||||||
|
"completed_at": _iso(task.completed_at),
|
||||||
|
},
|
||||||
|
observed_at=_aware(task.updated_at),
|
||||||
|
immutable_evidence=True,
|
||||||
|
retention_reason=(
|
||||||
|
"Task creation, update, and completion attribution is immutable "
|
||||||
|
"accountability evidence; task content and metadata are excluded."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _actor_activities(task: TaskItem, actor_ids: Sequence[str]) -> list[str]:
|
||||||
|
actor_set = set(actor_ids)
|
||||||
|
activities = []
|
||||||
|
if task.created_by in actor_set:
|
||||||
|
activities.append("created_task")
|
||||||
|
if task.updated_by in actor_set:
|
||||||
|
activities.append("updated_task")
|
||||||
|
if task.completed_by in actor_set:
|
||||||
|
activities.append("completed_task")
|
||||||
|
return activities
|
||||||
|
|
||||||
|
|
||||||
|
def _source_projection(value: object) -> list[dict[str, str | None]]:
|
||||||
|
if not isinstance(value, list) or len(value) > _MAX_SOURCES:
|
||||||
|
raise ValueError("Tasks source references exceed the DSAR bound.")
|
||||||
|
projected: list[dict[str, str | None]] = []
|
||||||
|
for item in value:
|
||||||
|
if not isinstance(item, Mapping):
|
||||||
|
raise ValueError("Task source reference is invalid.")
|
||||||
|
projected.append(
|
||||||
|
{
|
||||||
|
"module_id": _bounded(item.get("module_id"), 100),
|
||||||
|
"resource_type": _bounded(item.get("resource_type"), 100),
|
||||||
|
"resource_id": _bounded(item.get("resource_id"), 255),
|
||||||
|
"revision": _bounded(item.get("revision"), 255),
|
||||||
|
"url": _bounded(item.get("url"), 1_500),
|
||||||
|
"label": _bounded(item.get("label"), 500),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return projected
|
||||||
|
|
||||||
|
|
||||||
|
def _bounded(value: object, limit: int) -> str | None:
|
||||||
|
return str(value)[:limit] if value is not None else None
|
||||||
|
|
||||||
|
|
||||||
|
def _iso(value: datetime | None) -> str | None:
|
||||||
|
aware = _aware(value)
|
||||||
|
return aware.isoformat() if aware else None
|
||||||
|
|
||||||
|
|
||||||
|
def _aware(value: datetime | None) -> datetime | None:
|
||||||
|
if value is None or value.tzinfo is not None:
|
||||||
|
return value
|
||||||
|
return value.replace(tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
def _session(value: object) -> Session:
|
||||||
|
if not isinstance(value, Session):
|
||||||
|
raise TypeError("Tasks DSAR requires a SQLAlchemy Session.")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_record(record: DsarRecordRef) -> None:
|
||||||
|
if record.provider_id != "tasks" or record.module_id != "tasks":
|
||||||
|
raise ValueError("Tasks DSAR cannot plan a foreign provider record.")
|
||||||
|
if (
|
||||||
|
record.resource_type
|
||||||
|
not in {
|
||||||
|
"assigned_task",
|
||||||
|
"task_actor_attribution",
|
||||||
|
}
|
||||||
|
or not record.resource_id
|
||||||
|
):
|
||||||
|
raise ValueError("Tasks DSAR record identity is invalid.")
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_action(action: DsarErasureActionRef) -> None:
|
||||||
|
if action.provider_id != "tasks" or action.module_id != "tasks":
|
||||||
|
raise ValueError("Tasks DSAR cannot execute a foreign provider action.")
|
||||||
|
if not action.action_id.startswith("tasks:"):
|
||||||
|
raise ValueError("Tasks DSAR action identity is invalid.")
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["TASKS_DSAR_CAPABILITY", "TasksDsarProvider"]
|
||||||
@@ -12,6 +12,7 @@ from govoplan_core.core.module_guards import (
|
|||||||
)
|
)
|
||||||
from govoplan_core.core.modules import (
|
from govoplan_core.core.modules import (
|
||||||
CapabilityDocumentation,
|
CapabilityDocumentation,
|
||||||
|
DocumentationCondition,
|
||||||
DocumentationLink,
|
DocumentationLink,
|
||||||
DocumentationTopic,
|
DocumentationTopic,
|
||||||
FrontendModule,
|
FrontendModule,
|
||||||
@@ -34,12 +35,16 @@ from govoplan_core.core.tasks import (
|
|||||||
from govoplan_core.core.views import ViewSurface
|
from govoplan_core.core.views import ViewSurface
|
||||||
from govoplan_core.db.base import Base
|
from govoplan_core.db.base import Base
|
||||||
from govoplan_tasks.backend.db import models as task_models
|
from govoplan_tasks.backend.db import models as task_models
|
||||||
|
from govoplan_tasks.backend.dsar_provider import (
|
||||||
|
TASKS_DSAR_CAPABILITY,
|
||||||
|
TasksDsarProvider,
|
||||||
|
)
|
||||||
from govoplan_tasks.backend.service import SqlTaskService
|
from govoplan_tasks.backend.service import SqlTaskService
|
||||||
|
|
||||||
|
|
||||||
MODULE_ID = "tasks"
|
MODULE_ID = "tasks"
|
||||||
MODULE_NAME = "Tasks"
|
MODULE_NAME = "Tasks"
|
||||||
MODULE_VERSION = "0.1.19"
|
MODULE_VERSION = "0.1.20"
|
||||||
READ_SCOPE = "tasks:item:read"
|
READ_SCOPE = "tasks:item:read"
|
||||||
WRITE_SCOPE = "tasks:item:write"
|
WRITE_SCOPE = "tasks:item:write"
|
||||||
ADMIN_SCOPE = "tasks:item:admin"
|
ADMIN_SCOPE = "tasks:item:admin"
|
||||||
@@ -69,6 +74,10 @@ def _service(context: ModuleContext) -> SqlTaskService:
|
|||||||
return SqlTaskService(context.registry)
|
return SqlTaskService(context.registry)
|
||||||
|
|
||||||
|
|
||||||
|
def _dsar_provider(_context: ModuleContext) -> TasksDsarProvider:
|
||||||
|
return TasksDsarProvider()
|
||||||
|
|
||||||
|
|
||||||
def _tenant_summary(session, tenant_id: str) -> dict[str, int]:
|
def _tenant_summary(session, tenant_id: str) -> dict[str, int]:
|
||||||
total = (
|
total = (
|
||||||
session.query(task_models.TaskItem)
|
session.query(task_models.TaskItem)
|
||||||
@@ -122,14 +131,86 @@ ROLE_TEMPLATES = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
DOCUMENTATION = (
|
DOCUMENTATION = (
|
||||||
|
DocumentationTopic(
|
||||||
|
id="tasks.data-subject-requests",
|
||||||
|
title="Task data-subject requests",
|
||||||
|
summary=(
|
||||||
|
"Export account-assigned task data and lifecycle attribution while "
|
||||||
|
"keeping shared institutional work under owner review."
|
||||||
|
),
|
||||||
|
body=(
|
||||||
|
"Tasks correlates exact account and actor identifiers only inside the "
|
||||||
|
"active tenant. Account-assigned explicit Tasks contribute bounded "
|
||||||
|
"title, summary, required action, lifecycle state, due dates, the exact "
|
||||||
|
"matching account assignment, source references, and any create, update, "
|
||||||
|
"or completion activities performed by the subject. Group, role, function, "
|
||||||
|
"and anyone visibility is not inferred from external directories and other "
|
||||||
|
"assignment targets are excluded. When the subject acted on a Task without "
|
||||||
|
"being its direct account assignee, only minimized lifecycle attribution "
|
||||||
|
"and source identity are exported. Provenance, arbitrary metadata, request "
|
||||||
|
"hashes, idempotency keys, and source-module payloads are excluded; source "
|
||||||
|
"references are never traversed. Task attribution is retained as immutable "
|
||||||
|
"accountability evidence. Assignment or content erasure requires manual "
|
||||||
|
"source-owner and retention review because a Task can be shared institutional "
|
||||||
|
"work; the provider performs no automatic mutation."
|
||||||
|
),
|
||||||
|
layer="configured",
|
||||||
|
documentation_types=("admin", "user"),
|
||||||
|
audience=("user", "tenant_admin", "operator", "auditor"),
|
||||||
|
related_modules=("core", "workflow_engine", "approvals", "notifications"),
|
||||||
|
translations={
|
||||||
|
"de": {
|
||||||
|
"title": "Betroffenenanfragen für Aufgaben",
|
||||||
|
"summary": (
|
||||||
|
"Kontobezogene Aufgabendaten und Lebenszykluszuordnungen exportieren, "
|
||||||
|
"während gemeinsam verantwortete institutionelle Arbeit der fachlichen Prüfung unterliegt."
|
||||||
|
),
|
||||||
|
"body": (
|
||||||
|
"Tasks gleicht ausschließlich exakte Konto- und Akteurskennungen innerhalb des aktiven Mandanten ab. "
|
||||||
|
"Direkt einem Konto zugewiesene Aufgaben tragen begrenzte Angaben zu Titel, Zusammenfassung, erforderlicher "
|
||||||
|
"Handlung, Lebenszyklusstatus, Fristen, exakter Kontozuweisung, Quellverweisen sowie vom Betroffenen ausgeführten "
|
||||||
|
"Erstellungs-, Änderungs- oder Abschlussaktivitäten bei. Sichtbarkeit für Gruppen, Rollen, Funktionen oder alle "
|
||||||
|
"wird nicht aus externen Verzeichnissen abgeleitet; andere Zuweisungsziele bleiben ausgeschlossen. Hat die "
|
||||||
|
"betroffene Person an einer Aufgabe gehandelt, ohne deren direkte Kontozuweisung zu sein, werden nur minimierte "
|
||||||
|
"Lebenszykluszuordnung und Quellidentität exportiert. Herkunftsmetadaten, beliebige Metadaten, Anfrage-Hashes, "
|
||||||
|
"Idempotenzschlüssel und Nutzdaten des Quellmoduls bleiben ausgeschlossen; Quellverweise werden niemals verfolgt. "
|
||||||
|
"Aufgabenzuordnungen bleiben als unveränderlicher Verantwortungsnachweis erhalten. Die Löschung einer Zuweisung "
|
||||||
|
"oder von Inhalten erfordert eine manuelle Prüfung durch Quellverantwortliche und Aufbewahrungsstelle, da eine "
|
||||||
|
"Aufgabe gemeinsam verantwortete institutionelle Arbeit sein kann; der Anbieter nimmt keine automatische Änderung vor."
|
||||||
|
),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
metadata={
|
||||||
|
"help_contexts": [
|
||||||
|
"tasks.page.inbox",
|
||||||
|
"tasks.page.detail",
|
||||||
|
"tasks.field.assignment",
|
||||||
|
"privacy.data-subject-requests",
|
||||||
|
],
|
||||||
|
"consequence_classes": {
|
||||||
|
"export_assigned_task": (
|
||||||
|
"Returns bounded Task-owned data and exact account assignment only."
|
||||||
|
),
|
||||||
|
"review_assignment_erasure": (
|
||||||
|
"Requires the Task source owner and retention authority before "
|
||||||
|
"changing shared work."
|
||||||
|
),
|
||||||
|
"retain_actor_attribution": (
|
||||||
|
"Preserves minimized Task lifecycle accountability evidence."
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
DocumentationTopic(
|
DocumentationTopic(
|
||||||
id="tasks.quick-access-and-product-area",
|
id="tasks.quick-access-and-product-area",
|
||||||
title="Work in product navigation and Quick Access",
|
title="Work in product navigation and Quick Access",
|
||||||
summary="Keep assigned work available in the Work area and the optional right-side Quick Access rail.",
|
summary="Keep assigned work available in the Work area and the optional right-side Quick Access rail.",
|
||||||
body=(
|
body=(
|
||||||
"Tasks contributes its authorized workspace to the Work product area. When Quick Access is enabled, "
|
"Tasks contributes its authorized workspace to the Work product area. When Quick Access is enabled, "
|
||||||
"the same provider-owned open-work summary can appear beside the current page. Views may hide or reorder "
|
"a bounded seven-item authorized inbox and detail can appear beside the current page. Explicit Tasks can be "
|
||||||
"the contribution, but neither presentation grants task access or changes completion state."
|
"started or completed there; work from another provider exposes only that provider's launch path. Every load "
|
||||||
|
"and command is rechecked by Tasks, and completion returns a typed work-item reference to the host. Views may "
|
||||||
|
"hide or reorder the contribution, but neither presentation grants task access or copies completion state."
|
||||||
),
|
),
|
||||||
layer="configured",
|
layer="configured",
|
||||||
documentation_types=("user", "admin"),
|
documentation_types=("user", "admin"),
|
||||||
@@ -141,8 +222,10 @@ DOCUMENTATION = (
|
|||||||
"summary": "Zugewiesene Arbeit im Produktbereich Arbeit und optional in der rechten Schnellzugriffsleiste verwenden.",
|
"summary": "Zugewiesene Arbeit im Produktbereich Arbeit und optional in der rechten Schnellzugriffsleiste verwenden.",
|
||||||
"body": (
|
"body": (
|
||||||
"Tasks ordnet den berechtigten Arbeitsbereich dem Produktbereich Arbeit zu. Ist der Schnellzugriff aktiviert, "
|
"Tasks ordnet den berechtigten Arbeitsbereich dem Produktbereich Arbeit zu. Ist der Schnellzugriff aktiviert, "
|
||||||
"kann dieselbe vom Modul verantwortete Zusammenfassung offener Arbeit neben der aktuellen Seite erscheinen. "
|
"kann ein begrenzter, berechtigungsgeprüfter Arbeitsvorrat mit sieben Einträgen und Details neben der "
|
||||||
"Ansichten dürfen den Beitrag ausblenden oder ordnen, erteilen aber keine Aufgabenberechtigung."
|
"aktuellen Seite erscheinen. Explizite Tasks lassen sich dort beginnen oder abschließen; fremde Quellen "
|
||||||
|
"behalten ihre eigenen Befehle und Startpfade. Jeder Aufruf wird erneut durch Tasks geprüft. Ansichten "
|
||||||
|
"dürfen den Beitrag ausblenden oder ordnen, erteilen aber keine Aufgabenberechtigung."
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -170,6 +253,12 @@ DOCUMENTATION = (
|
|||||||
"views",
|
"views",
|
||||||
"dashboard",
|
"dashboard",
|
||||||
),
|
),
|
||||||
|
conditions=(
|
||||||
|
DocumentationCondition(
|
||||||
|
required_modules=("tasks",),
|
||||||
|
required_scopes=(READ_SCOPE,),
|
||||||
|
),
|
||||||
|
),
|
||||||
links=(
|
links=(
|
||||||
DocumentationLink(
|
DocumentationLink(
|
||||||
label="Tasks domain",
|
label="Tasks domain",
|
||||||
@@ -180,16 +269,17 @@ DOCUMENTATION = (
|
|||||||
translations={
|
translations={
|
||||||
"de": {
|
"de": {
|
||||||
"title": "Gemeinsamer Arbeitsvorrat",
|
"title": "Gemeinsamer Arbeitsvorrat",
|
||||||
"summary": "Explizite Aufgaben und Arbeitsvorgaenge anderer Module sicher fortsetzen.",
|
"summary": "Explizite Aufgaben und Arbeitsvorgänge anderer Module sicher fortsetzen.",
|
||||||
"body": (
|
"body": (
|
||||||
"Der Arbeitsvorrat verbindet explizite Aufgaben mit Arbeitsobjekten aktivierter Module. "
|
"Der Arbeitsvorrat verbindet explizite Aufgaben mit Arbeitsobjekten aktivierter Module. "
|
||||||
"Jede Quelle behaelt die Verantwortung fuer Befehle und Abschlussstatus. Tasks kopiert "
|
"Jede Quelle behält die Verantwortung für Befehle und Abschlussstatus. Tasks kopiert "
|
||||||
"keine Workflow-Uebergabe, Postfachnachricht, Freigabe oder Benachrichtigung in einen "
|
"keine Workflow-Übergabe, Postfachnachricht, Freigabe oder Benachrichtigung in einen "
|
||||||
"zweiten Fachzustand. Filter, Fristen, Prioritaeten und Quellverweise helfen beim sicheren Fortsetzen."
|
"zweiten Fachzustand. Filter, Fristen, Prioritäten und Quellverweise helfen beim sicheren Fortsetzen."
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
metadata={
|
metadata={
|
||||||
|
"kind": "workflow",
|
||||||
"help_contexts": [
|
"help_contexts": [
|
||||||
"tasks.route.work",
|
"tasks.route.work",
|
||||||
"tasks.page.inbox",
|
"tasks.page.inbox",
|
||||||
@@ -228,6 +318,7 @@ manifest = ModuleManifest(
|
|||||||
provides_interfaces=(
|
provides_interfaces=(
|
||||||
ModuleInterfaceProvider(name=CAPABILITY_TASK_COMMANDS, version="1.0.0"),
|
ModuleInterfaceProvider(name=CAPABILITY_TASK_COMMANDS, version="1.0.0"),
|
||||||
ModuleInterfaceProvider(name="tasks.work_items", version="1.0.0"),
|
ModuleInterfaceProvider(name="tasks.work_items", version="1.0.0"),
|
||||||
|
ModuleInterfaceProvider(name=TASKS_DSAR_CAPABILITY, version="0.1.0"),
|
||||||
),
|
),
|
||||||
permissions=PERMISSIONS,
|
permissions=PERMISSIONS,
|
||||||
role_templates=ROLE_TEMPLATES,
|
role_templates=ROLE_TEMPLATES,
|
||||||
@@ -326,17 +417,30 @@ manifest = ModuleManifest(
|
|||||||
required_any=(READ_SCOPE,),
|
required_any=(READ_SCOPE,),
|
||||||
order=10,
|
order=10,
|
||||||
modes=("browse", "resume"),
|
modes=("browse", "resume"),
|
||||||
|
returned_reference_kinds=("tasks.work-item",),
|
||||||
|
help_context_id="tasks.quick_access.work",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
tenant_summary_providers=(_tenant_summary,),
|
tenant_summary_providers=(_tenant_summary,),
|
||||||
capability_factories={CAPABILITY_TASK_COMMANDS: _service},
|
capability_factories={
|
||||||
|
CAPABILITY_TASK_COMMANDS: _service,
|
||||||
|
TASKS_DSAR_CAPABILITY: _dsar_provider,
|
||||||
|
},
|
||||||
capability_documentation={
|
capability_documentation={
|
||||||
CAPABILITY_TASK_COMMANDS: CapabilityDocumentation(
|
CAPABILITY_TASK_COMMANDS: CapabilityDocumentation(
|
||||||
label="Task commands",
|
label="Task commands",
|
||||||
summary="Creates replay-safe explicit tasks without importing the Tasks implementation.",
|
summary="Creates replay-safe explicit tasks without importing the Tasks implementation.",
|
||||||
contract_version="1.0.0",
|
contract_version="1.0.0",
|
||||||
)
|
),
|
||||||
|
TASKS_DSAR_CAPABILITY: CapabilityDocumentation(
|
||||||
|
label="Tasks data-subject request provider",
|
||||||
|
summary=(
|
||||||
|
"Exports account-assigned Tasks and minimized actor attribution "
|
||||||
|
"with governed non-executable erasure outcomes."
|
||||||
|
),
|
||||||
|
contract_version="0.1.0",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
work_item_providers=(
|
work_item_providers=(
|
||||||
WorkItemProviderRegistration(id="tasks.explicit", factory=_service, order=10),
|
WorkItemProviderRegistration(id="tasks.explicit", factory=_service, order=10),
|
||||||
|
|||||||
@@ -0,0 +1,376 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from govoplan_core.core.dsar import (
|
||||||
|
DsarErasureActionRef,
|
||||||
|
DsarProvider,
|
||||||
|
DsarRecordRef,
|
||||||
|
DsarSubjectRef,
|
||||||
|
)
|
||||||
|
from govoplan_core.db.base import Base
|
||||||
|
from govoplan_core.privacy.dsar_workflow import (
|
||||||
|
create_data_subject_request,
|
||||||
|
search_data_subject_request,
|
||||||
|
)
|
||||||
|
from govoplan_tasks.backend.db.models import TaskAssignment, TaskItem
|
||||||
|
from govoplan_tasks.backend.dsar_provider import (
|
||||||
|
TASKS_DSAR_CAPABILITY,
|
||||||
|
TasksDsarProvider,
|
||||||
|
)
|
||||||
|
from govoplan_tasks.backend.manifest import manifest
|
||||||
|
|
||||||
|
|
||||||
|
class _Registry:
|
||||||
|
def __init__(self, provider: TasksDsarProvider, *, active: bool = True) -> None:
|
||||||
|
self.provider = provider
|
||||||
|
self.active = active
|
||||||
|
|
||||||
|
def capability_names(self):
|
||||||
|
return (TASKS_DSAR_CAPABILITY,)
|
||||||
|
|
||||||
|
def capability_owner(self, name):
|
||||||
|
self._assert_capability(name)
|
||||||
|
return "tasks"
|
||||||
|
|
||||||
|
def tenant_entitlement_resolver(self):
|
||||||
|
active = self.active
|
||||||
|
|
||||||
|
class _Resolver:
|
||||||
|
@staticmethod
|
||||||
|
def resolve(session, tenant_id):
|
||||||
|
del session, tenant_id
|
||||||
|
return type(
|
||||||
|
"State",
|
||||||
|
(),
|
||||||
|
{"effective_modules": ("tasks",) if active else ()},
|
||||||
|
)()
|
||||||
|
|
||||||
|
return _Resolver()
|
||||||
|
|
||||||
|
def require_tenant_capability(self, name, session, **kwargs):
|
||||||
|
del session, kwargs
|
||||||
|
self._assert_capability(name)
|
||||||
|
return self.provider
|
||||||
|
|
||||||
|
def manifests(self):
|
||||||
|
return (type("Manifest", (), {"id": "tasks"})(),)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _assert_capability(name: str) -> None:
|
||||||
|
if name != TASKS_DSAR_CAPABILITY:
|
||||||
|
raise KeyError(name)
|
||||||
|
|
||||||
|
|
||||||
|
class TasksDsarProviderTests(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.engine = create_engine("sqlite+pysqlite:///:memory:")
|
||||||
|
Base.metadata.create_all(self.engine)
|
||||||
|
self.session = Session(self.engine)
|
||||||
|
self.provider = TasksDsarProvider()
|
||||||
|
self.assertIsInstance(self.provider, DsarProvider)
|
||||||
|
self._seed()
|
||||||
|
self.session.commit()
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
self.session.close()
|
||||||
|
self.engine.dispose()
|
||||||
|
|
||||||
|
def _task(
|
||||||
|
self,
|
||||||
|
task_id: str,
|
||||||
|
*,
|
||||||
|
tenant_id: str = "tenant-1",
|
||||||
|
created_by: str = "account-other",
|
||||||
|
updated_by: str = "account-other",
|
||||||
|
completed_by: str | None = None,
|
||||||
|
) -> TaskItem:
|
||||||
|
return TaskItem(
|
||||||
|
id=task_id,
|
||||||
|
tenant_id=tenant_id,
|
||||||
|
title=f"Private title for {task_id}",
|
||||||
|
summary=f"Private summary for {task_id}",
|
||||||
|
status="completed" if completed_by else "open",
|
||||||
|
priority="high",
|
||||||
|
required_action="Review the source decision",
|
||||||
|
action_url="/cases/case-1",
|
||||||
|
source_module="cases",
|
||||||
|
source_resource_type="case",
|
||||||
|
source_resource_id="case-1",
|
||||||
|
source_revision="4",
|
||||||
|
sources=[
|
||||||
|
{
|
||||||
|
"module_id": "cases",
|
||||||
|
"resource_type": "case",
|
||||||
|
"resource_id": "case-1",
|
||||||
|
"revision": "4",
|
||||||
|
"url": "/cases/case-1",
|
||||||
|
"label": "Case reference",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
provenance={"secret": "provenance-secret-do-not-export"},
|
||||||
|
metadata_={"secret": "metadata-secret-do-not-export"},
|
||||||
|
revision=2,
|
||||||
|
idempotency_key=f"idempotency-{task_id}-do-not-export",
|
||||||
|
request_sha256="a" * 64,
|
||||||
|
created_by=created_by,
|
||||||
|
updated_by=updated_by,
|
||||||
|
completed_by=completed_by,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _seed(self) -> None:
|
||||||
|
assigned = self._task("task-assigned")
|
||||||
|
assigned.assignments.extend(
|
||||||
|
(
|
||||||
|
TaskAssignment(
|
||||||
|
id="assignment-account",
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
assignment_kind="account",
|
||||||
|
assignment_id="account-1",
|
||||||
|
assignment_label="Resident account",
|
||||||
|
),
|
||||||
|
TaskAssignment(
|
||||||
|
id="assignment-group",
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
assignment_kind="group",
|
||||||
|
assignment_id="group-private",
|
||||||
|
assignment_label="Private group label do not export",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
actor_only = self._task(
|
||||||
|
"task-actor-only",
|
||||||
|
created_by="account-1",
|
||||||
|
updated_by="account-1",
|
||||||
|
completed_by="account-1",
|
||||||
|
)
|
||||||
|
actor_only.assignments.append(
|
||||||
|
TaskAssignment(
|
||||||
|
id="assignment-other",
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
assignment_kind="account",
|
||||||
|
assignment_id="account-other",
|
||||||
|
assignment_label="Other account",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
other = self._task("task-other")
|
||||||
|
other.assignments.append(
|
||||||
|
TaskAssignment(
|
||||||
|
id="assignment-other-task",
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
assignment_kind="account",
|
||||||
|
assignment_id="account-other",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
other_tenant = self._task(
|
||||||
|
"task-other-tenant",
|
||||||
|
tenant_id="tenant-2",
|
||||||
|
created_by="account-1",
|
||||||
|
updated_by="account-1",
|
||||||
|
)
|
||||||
|
other_tenant.assignments.append(
|
||||||
|
TaskAssignment(
|
||||||
|
id="assignment-other-tenant",
|
||||||
|
tenant_id="tenant-2",
|
||||||
|
assignment_kind="account",
|
||||||
|
assignment_id="account-1",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.session.add_all((assigned, actor_only, other, other_tenant))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _subject() -> DsarSubjectRef:
|
||||||
|
return DsarSubjectRef(account_id="account-1")
|
||||||
|
|
||||||
|
def test_search_exports_assigned_task_and_minimized_actor_attribution(self) -> None:
|
||||||
|
records = self.provider.search_subject(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=self._subject(),
|
||||||
|
)
|
||||||
|
|
||||||
|
by_id = {record.resource_id: record for record in records}
|
||||||
|
self.assertEqual(
|
||||||
|
{"task-assigned", "task-actor-only"},
|
||||||
|
set(by_id),
|
||||||
|
)
|
||||||
|
self.assertEqual("assigned_task", by_id["task-assigned"].resource_type)
|
||||||
|
self.assertEqual(
|
||||||
|
"task_actor_attribution",
|
||||||
|
by_id["task-actor-only"].resource_type,
|
||||||
|
)
|
||||||
|
exported = json.dumps([record.to_dict() for record in records])
|
||||||
|
self.assertIn("Private summary for task-assigned", exported)
|
||||||
|
self.assertIn('"module_id": "cases"', exported)
|
||||||
|
self.assertIn('"resource_id": "case-1"', exported)
|
||||||
|
self.assertIn("completed_task", exported)
|
||||||
|
self.assertNotIn("Private summary for task-actor-only", exported)
|
||||||
|
self.assertNotIn("Private group label do not export", exported)
|
||||||
|
self.assertNotIn("group-private", exported)
|
||||||
|
self.assertNotIn("provenance-secret-do-not-export", exported)
|
||||||
|
self.assertNotIn("metadata-secret-do-not-export", exported)
|
||||||
|
self.assertNotIn("idempotency-task-assigned-do-not-export", exported)
|
||||||
|
self.assertNotIn("task-other-tenant", exported)
|
||||||
|
|
||||||
|
def test_exact_task_reference_narrows_and_conflicts_fail_closed(self) -> None:
|
||||||
|
narrowed = self.provider.search_subject(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=DsarSubjectRef(
|
||||||
|
account_id="account-1",
|
||||||
|
external_references={"tasks.task": "task-assigned"},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
conflict = self.provider.search_subject(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=DsarSubjectRef(
|
||||||
|
account_id="account-1",
|
||||||
|
external_references={"tasks.account": "account-other"},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
reference_only = self.provider.search_subject(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=DsarSubjectRef(external_references={"tasks.task": "task-assigned"}),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(["task-assigned"], [item.resource_id for item in narrowed])
|
||||||
|
self.assertEqual((), conflict)
|
||||||
|
self.assertEqual((), reference_only)
|
||||||
|
|
||||||
|
def test_erasure_requires_review_or_retention_and_changes_nothing(self) -> None:
|
||||||
|
subject = self._subject()
|
||||||
|
records = self.provider.search_subject(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=subject,
|
||||||
|
)
|
||||||
|
actions = self.provider.plan_erasure(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=subject,
|
||||||
|
records=records,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
{"manual_review", "retain"},
|
||||||
|
{action.kind for action in actions},
|
||||||
|
)
|
||||||
|
self.assertTrue(all(not action.executable for action in actions))
|
||||||
|
|
||||||
|
results = self.provider.execute_erasure(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=subject,
|
||||||
|
actions=actions,
|
||||||
|
request_id="dsar-1",
|
||||||
|
)
|
||||||
|
self.assertTrue(all(result.status == "blocked" for result in results))
|
||||||
|
self.assertIsNotNone(self.session.get(TaskItem, "task-assigned"))
|
||||||
|
self.assertIsNotNone(self.session.get(TaskAssignment, "assignment-account"))
|
||||||
|
|
||||||
|
def test_foreign_records_and_actions_are_rejected(self) -> None:
|
||||||
|
subject = self._subject()
|
||||||
|
with self.assertRaisesRegex(ValueError, "foreign provider record"):
|
||||||
|
self.provider.plan_erasure(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=subject,
|
||||||
|
records=(
|
||||||
|
DsarRecordRef(
|
||||||
|
provider_id="workflow_engine",
|
||||||
|
module_id="workflow_engine",
|
||||||
|
resource_type="assigned_task",
|
||||||
|
resource_id="task-assigned",
|
||||||
|
category="work",
|
||||||
|
title="Foreign task",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
with self.assertRaisesRegex(ValueError, "foreign provider action"):
|
||||||
|
self.provider.execute_erasure(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
subject=subject,
|
||||||
|
actions=(
|
||||||
|
DsarErasureActionRef(
|
||||||
|
action_id="workflow_engine:retain:task:task-assigned",
|
||||||
|
provider_id="workflow_engine",
|
||||||
|
module_id="workflow_engine",
|
||||||
|
kind="retain",
|
||||||
|
resource_type="task_actor_attribution",
|
||||||
|
resource_id="task-assigned",
|
||||||
|
title="Retain task",
|
||||||
|
rationale="Foreign action",
|
||||||
|
executable=False,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
request_id="dsar-1",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_core_workflow_and_manifest_register_provider(self) -> None:
|
||||||
|
row = create_data_subject_request(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
reference="DSAR-TASKS-1",
|
||||||
|
request_kind="access",
|
||||||
|
subject=self._subject(),
|
||||||
|
purpose="Respond to a verified request.",
|
||||||
|
legal_basis="Article 15 GDPR",
|
||||||
|
due_at=None,
|
||||||
|
requested_by_account_id="privacy-officer",
|
||||||
|
)
|
||||||
|
self.session.commit()
|
||||||
|
search_data_subject_request(
|
||||||
|
self.session,
|
||||||
|
registry=_Registry(self.provider),
|
||||||
|
row=row,
|
||||||
|
expected_revision=1,
|
||||||
|
)
|
||||||
|
self.assertEqual([TASKS_DSAR_CAPABILITY], row.coverage["provider_capabilities"])
|
||||||
|
self.assertEqual(2, row.search_result["record_count"])
|
||||||
|
|
||||||
|
inactive = create_data_subject_request(
|
||||||
|
self.session,
|
||||||
|
tenant_id="tenant-1",
|
||||||
|
reference="DSAR-TASKS-2",
|
||||||
|
request_kind="access",
|
||||||
|
subject=self._subject(),
|
||||||
|
purpose="Respond to a verified request.",
|
||||||
|
legal_basis="Article 15 GDPR",
|
||||||
|
due_at=None,
|
||||||
|
requested_by_account_id="privacy-officer",
|
||||||
|
)
|
||||||
|
self.session.commit()
|
||||||
|
search_data_subject_request(
|
||||||
|
self.session,
|
||||||
|
registry=_Registry(self.provider, active=False),
|
||||||
|
row=inactive,
|
||||||
|
expected_revision=1,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
[TASKS_DSAR_CAPABILITY],
|
||||||
|
inactive.coverage["inactive_provider_capabilities"],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn(TASKS_DSAR_CAPABILITY, manifest.capability_factories)
|
||||||
|
self.assertIn(TASKS_DSAR_CAPABILITY, manifest.capability_documentation)
|
||||||
|
self.assertIn(
|
||||||
|
TASKS_DSAR_CAPABILITY,
|
||||||
|
{item.name for item in manifest.provides_interfaces},
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
any(
|
||||||
|
topic.id == "tasks.data-subject-requests"
|
||||||
|
and {"admin", "user"}.issubset(topic.documentation_types)
|
||||||
|
for topic in manifest.documentation
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from govoplan_tasks.backend.manifest import get_manifest
|
||||||
|
|
||||||
|
|
||||||
|
REPOSITORY_ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
|
||||||
|
|
||||||
|
class TasksQuickAccessContractTests(unittest.TestCase):
|
||||||
|
def test_public_topics_have_complete_german_workflow_and_reference_coverage(
|
||||||
|
self,
|
||||||
|
) -> None:
|
||||||
|
topics = get_manifest().documentation
|
||||||
|
kinds = {topic.metadata.get("kind", "system") for topic in topics}
|
||||||
|
|
||||||
|
self.assertEqual(3, len(topics))
|
||||||
|
self.assertTrue({"workflow", "reference"}.issubset(kinds))
|
||||||
|
for topic in topics:
|
||||||
|
translation = topic.translations["de"]
|
||||||
|
self.assertEqual({"title", "summary", "body"}, set(translation))
|
||||||
|
self.assertTrue(
|
||||||
|
all(str(translation[field]).strip() for field in translation)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_manifest_declares_typed_work_result_and_help(self) -> None:
|
||||||
|
tool = get_manifest().frontend.quick_access_tools[0]
|
||||||
|
|
||||||
|
self.assertEqual("tasks.work", tool.id)
|
||||||
|
self.assertEqual(("tasks.work-item",), tool.returned_reference_kinds)
|
||||||
|
self.assertEqual("tasks.quick_access.work", tool.help_context_id)
|
||||||
|
self.assertEqual("/tasks", tool.full_page_path)
|
||||||
|
|
||||||
|
def test_renderer_is_bounded_and_keeps_commands_source_owned(self) -> None:
|
||||||
|
source = (
|
||||||
|
REPOSITORY_ROOT
|
||||||
|
/ "webui"
|
||||||
|
/ "src"
|
||||||
|
/ "features"
|
||||||
|
/ "tasks"
|
||||||
|
/ "TasksQuickAccess.tsx"
|
||||||
|
).read_text()
|
||||||
|
|
||||||
|
self.assertIn("limit: 7", source)
|
||||||
|
self.assertIn('selected.provider_id !== "tasks.explicit"', source)
|
||||||
|
self.assertIn("transitionTask(settings, selected, action)", source)
|
||||||
|
self.assertIn("quickAccessLaunchState(launchContext)", source)
|
||||||
|
self.assertIn('kind: "work-item"', source)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@govoplan/tasks-webui",
|
"name": "@govoplan/tasks-webui",
|
||||||
"version": "0.1.19",
|
"version": "0.1.20",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
|
|||||||
@@ -6,24 +6,27 @@ import {
|
|||||||
ExternalLink,
|
ExternalLink,
|
||||||
ListChecks,
|
ListChecks,
|
||||||
Plus,
|
Plus,
|
||||||
RefreshCw,
|
|
||||||
RotateCcw,
|
RotateCcw,
|
||||||
Search,
|
Search,
|
||||||
XCircle
|
XCircle
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { Link } from "react-router";
|
import { Link } from "react-router";
|
||||||
import {
|
import { FormGrid,
|
||||||
AdminIconButton,
|
|
||||||
Button,
|
Button,
|
||||||
DateTimeField,
|
DateTimeField,
|
||||||
Dialog,
|
Dialog,
|
||||||
DismissibleAlert,
|
DismissibleAlert,
|
||||||
DocumentationHelpLink,
|
DocumentationHelpLink,
|
||||||
FormField,
|
FormField,
|
||||||
|
FilterBar,
|
||||||
SegmentedControl,
|
SegmentedControl,
|
||||||
SelectionList,
|
SelectionList,
|
||||||
SelectionListItem,
|
SelectionListItem,
|
||||||
|
StatePanel,
|
||||||
StatusBadge,
|
StatusBadge,
|
||||||
|
WorkspaceActionBar,
|
||||||
|
WorkspaceFrame,
|
||||||
|
WorkspaceLayout,
|
||||||
hasScope,
|
hasScope,
|
||||||
type ApiSettings,
|
type ApiSettings,
|
||||||
type AuthInfo
|
type AuthInfo
|
||||||
@@ -120,30 +123,40 @@ export default function TasksPage({ settings, auth }: { settings: ApiSettings; a
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="tasks-page" data-help-context-id="tasks.page.inbox">
|
<WorkspaceFrame as="main" height="viewport" surface="plain" className="tasks-page" label="Task inbox" data-help-context-id="tasks.page.inbox">
|
||||||
<div className="tasks-shell">
|
<WorkspaceLayout
|
||||||
<aside className="tasks-sidebar">
|
variant="split"
|
||||||
<div className="tasks-sidebar-bar">
|
primarySize="default"
|
||||||
<span className="tasks-title"><ListChecks size={18} /><strong>i18n:govoplan-tasks.work</strong></span>
|
primaryScrollable={false}
|
||||||
<span className="tasks-toolbar-actions">
|
contentScrollable={false}
|
||||||
<AdminIconButton
|
surface="contained"
|
||||||
label="i18n:govoplan-tasks.refresh"
|
primaryClassName="tasks-sidebar"
|
||||||
icon={<RefreshCw size={16} aria-hidden="true" />}
|
contentClassName="tasks-workspace"
|
||||||
onClick={() => void load()}
|
primaryLabel="i18n:govoplan-tasks.work"
|
||||||
disabled={loading || busy}
|
contentLabel="i18n:govoplan-tasks.work_details"
|
||||||
/>
|
interfaceId="tasks.inbox.workspace"
|
||||||
{canWrite ? (
|
helpContextId="tasks.page.inbox"
|
||||||
<AdminIconButton
|
helpModuleId="tasks"
|
||||||
label="i18n:govoplan-tasks.create_task"
|
primary={<>
|
||||||
icon={<Plus size={16} aria-hidden="true" />}
|
<WorkspaceActionBar
|
||||||
onClick={() => setCreateOpen(true)}
|
scope="collection-pane"
|
||||||
disabled={busy}
|
variant="collection"
|
||||||
helpContextId="tasks.action.create"
|
refreshable
|
||||||
/>
|
reloadAction={{ onReload: () => void load(), loading: loading || busy, label: "i18n:govoplan-tasks.refresh" }}
|
||||||
) : null}
|
className="tasks-sidebar-bar"
|
||||||
</span>
|
contextActions={<span className="tasks-title"><ListChecks size={18} /><strong>i18n:govoplan-tasks.work</strong></span>}
|
||||||
</div>
|
createAction={canWrite ? (
|
||||||
<form className="tasks-search" onSubmit={submitSearch} role="search">
|
<Button
|
||||||
|
variant="primary"
|
||||||
|
onClick={() => setCreateOpen(true)}
|
||||||
|
disabled={busy}
|
||||||
|
helpContextId="tasks.action.create"
|
||||||
|
>
|
||||||
|
<Plus size={16} aria-hidden="true" /> i18n:govoplan-tasks.create_task
|
||||||
|
</Button>
|
||||||
|
) : undefined}
|
||||||
|
/>
|
||||||
|
<FilterBar as="form" surface="control" wrap="never" className="tasks-search" onSubmit={submitSearch} role="search">
|
||||||
<Search size={15} aria-hidden="true" />
|
<Search size={15} aria-hidden="true" />
|
||||||
<input
|
<input
|
||||||
value={searchDraft}
|
value={searchDraft}
|
||||||
@@ -151,7 +164,7 @@ export default function TasksPage({ settings, auth }: { settings: ApiSettings; a
|
|||||||
placeholder="i18n:govoplan-tasks.search_placeholder"
|
placeholder="i18n:govoplan-tasks.search_placeholder"
|
||||||
aria-label="i18n:govoplan-tasks.search"
|
aria-label="i18n:govoplan-tasks.search"
|
||||||
/>
|
/>
|
||||||
</form>
|
</FilterBar>
|
||||||
<SegmentedControl
|
<SegmentedControl
|
||||||
className="tasks-status-filter"
|
className="tasks-status-filter"
|
||||||
options={[
|
options={[
|
||||||
@@ -168,7 +181,7 @@ export default function TasksPage({ settings, auth }: { settings: ApiSettings; a
|
|||||||
{loading ? <p className="tasks-note">i18n:govoplan-tasks.loading</p> : null}
|
{loading ? <p className="tasks-note">i18n:govoplan-tasks.loading</p> : null}
|
||||||
{!loading && items.length === 0 ? <p className="tasks-note">i18n:govoplan-tasks.empty</p> : null}
|
{!loading && items.length === 0 ? <p className="tasks-note">i18n:govoplan-tasks.empty</p> : null}
|
||||||
{items.length ? (
|
{items.length ? (
|
||||||
<SelectionList label="i18n:govoplan-tasks.work_items">
|
<SelectionList variant="navigation" label="i18n:govoplan-tasks.work_items">
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<SelectionListItem
|
<SelectionListItem
|
||||||
key={`${item.provider_id}:${item.id}`}
|
key={`${item.provider_id}:${item.id}`}
|
||||||
@@ -183,25 +196,31 @@ export default function TasksPage({ settings, auth }: { settings: ApiSettings; a
|
|||||||
</SelectionList>
|
</SelectionList>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</>}
|
||||||
|
>
|
||||||
|
|
||||||
<section className="tasks-workspace" data-help-context-id="tasks.page.detail">
|
<WorkspaceActionBar
|
||||||
<div className="tasks-topbar">
|
scope="detail-pane"
|
||||||
<span className="tasks-detail-title"><ListChecks size={18} /><strong>{selected?.title ?? "i18n:govoplan-tasks.work_details"}</strong></span>
|
variant="detail"
|
||||||
<span className="tasks-toolbar-actions">
|
className="tasks-topbar"
|
||||||
<DocumentationHelpLink reference={DOCUMENTATION} />
|
data-help-context-id="tasks.page.detail"
|
||||||
{selected?.provider_id === "tasks.explicit" && canWrite ? <TaskActions item={selected} busy={busy} onAction={(action) => action === "defer" ? setDeferOpen(true) : void runAction(action)} /> : null}
|
contextActions={<span className="tasks-detail-title"><ListChecks size={18} /><strong>{selected?.title ?? "i18n:govoplan-tasks.work_details"}</strong></span>}
|
||||||
</span>
|
helpAction={<DocumentationHelpLink reference={DOCUMENTATION} />}
|
||||||
</div>
|
primaryActions={selected?.provider_id === "tasks.explicit" && canWrite ? (
|
||||||
|
<TaskPrimaryActions item={selected} busy={busy} onAction={(action) => action === "defer" ? setDeferOpen(true) : void runAction(action)} />
|
||||||
|
) : undefined}
|
||||||
|
destructiveActions={selected?.provider_id === "tasks.explicit" && canWrite && !["completed", "cancelled"].includes(selected.status) ? (
|
||||||
|
<Button variant="danger" onClick={() => void runAction("cancel")} disabled={busy}><XCircle size={15} /> i18n:govoplan-tasks.cancel_task</Button>
|
||||||
|
) : undefined}
|
||||||
|
/>
|
||||||
|
|
||||||
{error ? <DismissibleAlert tone="danger" compact resetKey={error}>{error}</DismissibleAlert> : null}
|
{error ? <DismissibleAlert tone="danger" compact resetKey={error}>{error}</DismissibleAlert> : null}
|
||||||
{diagnostics.map((message) => <DismissibleAlert key={message} tone="warning" compact resetKey={message}>{message}</DismissibleAlert>)}
|
{diagnostics.map((message) => <DismissibleAlert key={message} tone="warning" compact resetKey={message}>{message}</DismissibleAlert>)}
|
||||||
|
|
||||||
{selected ? <TaskDetails item={selected} /> : (
|
{selected ? <TaskDetails item={selected} /> : (
|
||||||
<div className="tasks-empty-detail"><ListChecks size={24} /><h1>i18n:govoplan-tasks.work</h1><p>i18n:govoplan-tasks.select_help</p></div>
|
<StatePanel size="fill" icon={<ListChecks size={24} />} title="i18n:govoplan-tasks.work" description="i18n:govoplan-tasks.select_help" />
|
||||||
)}
|
)}
|
||||||
</section>
|
</WorkspaceLayout>
|
||||||
</div>
|
|
||||||
|
|
||||||
<CreateTaskDialog
|
<CreateTaskDialog
|
||||||
open={createOpen}
|
open={createOpen}
|
||||||
@@ -230,11 +249,11 @@ export default function TasksPage({ settings, auth }: { settings: ApiSettings; a
|
|||||||
<DateTimeField value={deferredUntil} onChange={setDeferredUntil} min={localDateTime(new Date())} />
|
<DateTimeField value={deferredUntil} onChange={setDeferredUntil} min={localDateTime(new Date())} />
|
||||||
</FormField>
|
</FormField>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</main>
|
</WorkspaceFrame>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TaskActions({ item, busy, onAction }: { item: WorkItem; busy: boolean; onAction: (action: "start" | "complete" | "defer" | "reopen" | "cancel") => void }) {
|
function TaskPrimaryActions({ item, busy, onAction }: { item: WorkItem; busy: boolean; onAction: (action: "start" | "complete" | "defer" | "reopen") => void }) {
|
||||||
if (["completed", "cancelled"].includes(item.status)) {
|
if (["completed", "cancelled"].includes(item.status)) {
|
||||||
return <Button onClick={() => onAction("reopen")} disabled={busy}><RotateCcw size={15} /> i18n:govoplan-tasks.reopen</Button>;
|
return <Button onClick={() => onAction("reopen")} disabled={busy}><RotateCcw size={15} /> i18n:govoplan-tasks.reopen</Button>;
|
||||||
}
|
}
|
||||||
@@ -243,7 +262,6 @@ function TaskActions({ item, busy, onAction }: { item: WorkItem; busy: boolean;
|
|||||||
{["open", "deferred"].includes(item.status) ? <Button onClick={() => onAction("start")} disabled={busy}><CirclePlay size={15} /> i18n:govoplan-tasks.start</Button> : null}
|
{["open", "deferred"].includes(item.status) ? <Button onClick={() => onAction("start")} disabled={busy}><CirclePlay size={15} /> i18n:govoplan-tasks.start</Button> : null}
|
||||||
<Button variant="primary" onClick={() => onAction("complete")} disabled={busy}><Check size={15} /> i18n:govoplan-tasks.complete</Button>
|
<Button variant="primary" onClick={() => onAction("complete")} disabled={busy}><Check size={15} /> i18n:govoplan-tasks.complete</Button>
|
||||||
<Button onClick={() => onAction("defer")} disabled={busy}><CalendarClock size={15} /> i18n:govoplan-tasks.defer</Button>
|
<Button onClick={() => onAction("defer")} disabled={busy}><CalendarClock size={15} /> i18n:govoplan-tasks.defer</Button>
|
||||||
<Button variant="danger" onClick={() => onAction("cancel")} disabled={busy}><XCircle size={15} /> i18n:govoplan-tasks.cancel_task</Button>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -323,10 +341,10 @@ function CreateTaskDialog({ open, busy, settings, auth, onClose, onCreated, onEr
|
|||||||
<form id="tasks-create-form" className="tasks-create-form" onSubmit={submit}>
|
<form id="tasks-create-form" className="tasks-create-form" onSubmit={submit}>
|
||||||
<FormField label="i18n:govoplan-tasks.title"><input value={title} onChange={(event) => setTitle(event.target.value)} maxLength={500} autoFocus required /></FormField>
|
<FormField label="i18n:govoplan-tasks.title"><input value={title} onChange={(event) => setTitle(event.target.value)} maxLength={500} autoFocus required /></FormField>
|
||||||
<FormField label="i18n:govoplan-tasks.summary"><textarea value={summary} onChange={(event) => setSummary(event.target.value)} maxLength={4000} rows={4} /></FormField>
|
<FormField label="i18n:govoplan-tasks.summary"><textarea value={summary} onChange={(event) => setSummary(event.target.value)} maxLength={4000} rows={4} /></FormField>
|
||||||
<div className="tasks-create-grid">
|
<FormGrid columns={2} gap="small" collapseAt="workspace" className="tasks-create-grid">
|
||||||
<FormField label="i18n:govoplan-tasks.priority" helpContextId="tasks.field.priority"><select value={priority} onChange={(event) => setPriority(event.target.value as WorkPriority)}><option value="low">i18n:govoplan-tasks.priority.low</option><option value="normal">i18n:govoplan-tasks.priority.normal</option><option value="high">i18n:govoplan-tasks.priority.high</option><option value="urgent">i18n:govoplan-tasks.priority.urgent</option></select></FormField>
|
<FormField label="i18n:govoplan-tasks.priority" helpContextId="tasks.field.priority"><select value={priority} onChange={(event) => setPriority(event.target.value as WorkPriority)}><option value="low">i18n:govoplan-tasks.priority.low</option><option value="normal">i18n:govoplan-tasks.priority.normal</option><option value="high">i18n:govoplan-tasks.priority.high</option><option value="urgent">i18n:govoplan-tasks.priority.urgent</option></select></FormField>
|
||||||
<FormField label="i18n:govoplan-tasks.due_at" helpContextId="tasks.field.due-at"><DateTimeField value={dueAt} onChange={setDueAt} min={localDateTime(new Date())} /></FormField>
|
<FormField label="i18n:govoplan-tasks.due_at" helpContextId="tasks.field.due-at"><DateTimeField value={dueAt} onChange={setDueAt} min={localDateTime(new Date())} /></FormField>
|
||||||
</div>
|
</FormGrid>
|
||||||
<FormField label="i18n:govoplan-tasks.required_action"><input value={requiredAction} onChange={(event) => setRequiredAction(event.target.value)} maxLength={500} /></FormField>
|
<FormField label="i18n:govoplan-tasks.required_action"><input value={requiredAction} onChange={(event) => setRequiredAction(event.target.value)} maxLength={500} /></FormField>
|
||||||
<p className="tasks-assignment-note">i18n:govoplan-tasks.assigned_to_you</p>
|
<p className="tasks-assignment-note">i18n:govoplan-tasks.assigned_to_you</p>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -0,0 +1,220 @@
|
|||||||
|
import { Check, CirclePlay, ExternalLink, ListChecks } from "lucide-react";
|
||||||
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { Link } from "react-router";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DismissibleAlert,
|
||||||
|
LoadingFrame,
|
||||||
|
SelectionList,
|
||||||
|
SelectionListItem,
|
||||||
|
SelectionListItemContent,
|
||||||
|
StatusBadge,
|
||||||
|
hasScope,
|
||||||
|
quickAccessLaunchState,
|
||||||
|
useDashboardWidgetData,
|
||||||
|
type QuickAccessToolRenderContext
|
||||||
|
} from "@govoplan/core-webui";
|
||||||
|
import {
|
||||||
|
listWork,
|
||||||
|
transitionTask,
|
||||||
|
type WorkItem,
|
||||||
|
type WorkStatus
|
||||||
|
} from "../../api/tasks";
|
||||||
|
|
||||||
|
const ACTIVE_STATUSES: WorkStatus[] = [
|
||||||
|
"open",
|
||||||
|
"in_progress",
|
||||||
|
"deferred",
|
||||||
|
"blocked"
|
||||||
|
];
|
||||||
|
|
||||||
|
type Props = Pick<
|
||||||
|
QuickAccessToolRenderContext,
|
||||||
|
"settings" | "auth" | "launchContext" | "complete"
|
||||||
|
>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A bounded projection of the unified inbox. Every load and command goes back
|
||||||
|
* through Tasks, so optional providers retain ownership of visibility and
|
||||||
|
* completion semantics.
|
||||||
|
*/
|
||||||
|
export default function TasksQuickAccess({
|
||||||
|
settings,
|
||||||
|
auth,
|
||||||
|
launchContext,
|
||||||
|
complete
|
||||||
|
}: Props) {
|
||||||
|
const [refreshKey, setRefreshKey] = useState(0);
|
||||||
|
const [selectedKey, setSelectedKey] = useState("");
|
||||||
|
const [commandError, setCommandError] = useState("");
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
const load = useCallback(
|
||||||
|
() => listWork(settings, { statuses: ACTIVE_STATUSES, limit: 7 }),
|
||||||
|
[settings]
|
||||||
|
);
|
||||||
|
const { data, loading, error } = useDashboardWidgetData(load, refreshKey);
|
||||||
|
const items = data?.items ?? [];
|
||||||
|
const selected = useMemo(
|
||||||
|
() => items.find((item) => workKey(item) === selectedKey) ?? items[0] ?? null,
|
||||||
|
[items, selectedKey]
|
||||||
|
);
|
||||||
|
const canWrite = hasScope(auth, "tasks:item:write");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!selectedKey && items[0]) setSelectedKey(workKey(items[0]));
|
||||||
|
if (selectedKey && !items.some((item) => workKey(item) === selectedKey)) {
|
||||||
|
setSelectedKey(items[0] ? workKey(items[0]) : "");
|
||||||
|
}
|
||||||
|
}, [items, selectedKey]);
|
||||||
|
|
||||||
|
async function runCommand(action: "start" | "complete") {
|
||||||
|
if (!selected || selected.provider_id !== "tasks.explicit" || !canWrite) return;
|
||||||
|
setBusy(true);
|
||||||
|
setCommandError("");
|
||||||
|
try {
|
||||||
|
const updated = await transitionTask(settings, selected, action);
|
||||||
|
if (action === "complete") {
|
||||||
|
complete(workResult(updated, "completed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setRefreshKey((value) => value + 1);
|
||||||
|
} catch (reason) {
|
||||||
|
setCommandError(errorMessage(reason));
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectForHost(item: WorkItem) {
|
||||||
|
complete(workResult(item, "selected"));
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionPath = selected ? safeActionUrl(selected.action_url) : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LoadingFrame loading={loading} label="i18n:govoplan-tasks.loading">
|
||||||
|
{error ? <DismissibleAlert tone="warning" resetKey={error}>{error}</DismissibleAlert> : null}
|
||||||
|
{commandError ? <DismissibleAlert tone="danger" resetKey={commandError}>{commandError}</DismissibleAlert> : null}
|
||||||
|
{data?.diagnostics.map((diagnostic) => (
|
||||||
|
<DismissibleAlert
|
||||||
|
key={`${diagnostic.provider_id}:${diagnostic.code}`}
|
||||||
|
tone="warning"
|
||||||
|
resetKey={`${diagnostic.provider_id}:${diagnostic.code}:${diagnostic.message}`}
|
||||||
|
>
|
||||||
|
{diagnostic.message}
|
||||||
|
</DismissibleAlert>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{items.length ? (
|
||||||
|
<SelectionList variant="navigation" label="i18n:govoplan-tasks.work_items">
|
||||||
|
{items.map((item) => (
|
||||||
|
<SelectionListItem
|
||||||
|
key={workKey(item)}
|
||||||
|
selected={selected ? workKey(item) === workKey(selected) : false}
|
||||||
|
onClick={() => setSelectedKey(workKey(item))}
|
||||||
|
>
|
||||||
|
<SelectionListItemContent
|
||||||
|
leading={<ListChecks size={16} aria-hidden="true" />}
|
||||||
|
title={item.title}
|
||||||
|
description={item.required_action || item.summary || moduleLabel(item.owner_module)}
|
||||||
|
/>
|
||||||
|
<StatusBadge status={item.status} label={statusLabel(item.status)} />
|
||||||
|
</SelectionListItem>
|
||||||
|
))}
|
||||||
|
</SelectionList>
|
||||||
|
) : !loading && !error ? (
|
||||||
|
<p className="muted">i18n:govoplan-tasks.empty</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{selected ? (
|
||||||
|
<section className="tasks-quick-detail" aria-label="i18n:govoplan-tasks.work_details">
|
||||||
|
<div className="tasks-quick-detail-heading">
|
||||||
|
<strong>{selected.title}</strong>
|
||||||
|
<span>{moduleLabel(selected.owner_module)} · {dueLabel(selected.due_at)}</span>
|
||||||
|
</div>
|
||||||
|
{selected.summary ? <p>{selected.summary}</p> : null}
|
||||||
|
{selected.required_action ? (
|
||||||
|
<p><strong>i18n:govoplan-tasks.required_action:</strong> {selected.required_action}</p>
|
||||||
|
) : null}
|
||||||
|
<div className="button-row compact-actions">
|
||||||
|
{selected.provider_id === "tasks.explicit" && canWrite && ["open", "deferred"].includes(selected.status) ? (
|
||||||
|
<Button onClick={() => void runCommand("start")} disabled={busy}>
|
||||||
|
<CirclePlay size={15} aria-hidden="true" /> i18n:govoplan-tasks.start
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
{selected.provider_id === "tasks.explicit" && canWrite ? (
|
||||||
|
<Button variant="primary" onClick={() => void runCommand("complete")} disabled={busy}>
|
||||||
|
<Check size={15} aria-hidden="true" /> i18n:govoplan-tasks.complete
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
{actionPath ? (
|
||||||
|
<Link
|
||||||
|
className="btn btn-secondary"
|
||||||
|
to={actionPath}
|
||||||
|
state={quickAccessLaunchState(launchContext)}
|
||||||
|
onClick={() => selectForHost(selected)}
|
||||||
|
>
|
||||||
|
<ExternalLink size={15} aria-hidden="true" /> i18n:govoplan-tasks.open_work
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<Button onClick={() => selectForHost(selected)}>
|
||||||
|
i18n:govoplan-tasks.select_help
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{data && data.total > items.length ? (
|
||||||
|
<p className="muted small-note">
|
||||||
|
{items.length} / {data.total} · i18n:govoplan-tasks.open_work_inbox
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</LoadingFrame>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function workResult(item: WorkItem, action: "selected" | "completed") {
|
||||||
|
return {
|
||||||
|
contractVersion: "1" as const,
|
||||||
|
outcome: "completed" as const,
|
||||||
|
action,
|
||||||
|
reference: {
|
||||||
|
ownerModule: "tasks",
|
||||||
|
kind: "work-item",
|
||||||
|
objectId: `${item.provider_id}:${item.id}`,
|
||||||
|
tenantId: item.tenant_id,
|
||||||
|
label: item.title,
|
||||||
|
version: item.revision,
|
||||||
|
path: safeActionUrl(item.action_url) || "/tasks"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function workKey(item: WorkItem): string {
|
||||||
|
return `${item.provider_id}:${item.id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeActionUrl(value?: string | null): string | null {
|
||||||
|
if (!value || !value.startsWith("/") || value.startsWith("//") || value.includes("\\")) return null;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusLabel(value: string): string {
|
||||||
|
return `i18n:govoplan-tasks.status.${value}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function moduleLabel(value: string): string {
|
||||||
|
return value.replaceAll("_", " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
function dueLabel(value?: string | null): string {
|
||||||
|
if (!value) return "i18n:govoplan-tasks.no_due_date";
|
||||||
|
const parsed = new Date(value);
|
||||||
|
if (Number.isNaN(parsed.getTime())) return value;
|
||||||
|
return new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short" }).format(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
function errorMessage(reason: unknown): string {
|
||||||
|
return reason instanceof Error ? reason.message : "i18n:govoplan-tasks.request_failed";
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { MetricGrid } from "@govoplan/core-webui";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Link } from "react-router";
|
import { Link } from "react-router";
|
||||||
import {
|
import {
|
||||||
@@ -35,11 +36,11 @@ export default function TasksSummaryWidget({ settings, refreshKey }: { settings:
|
|||||||
return (
|
return (
|
||||||
<LoadingFrame loading={loading} label="i18n:govoplan-tasks.loading_summary">
|
<LoadingFrame loading={loading} label="i18n:govoplan-tasks.loading_summary">
|
||||||
{error ? <DismissibleAlert tone="warning" resetKey={error}>{error}</DismissibleAlert> : null}
|
{error ? <DismissibleAlert tone="warning" resetKey={error}>{error}</DismissibleAlert> : null}
|
||||||
<div className="metric-grid inside dashboard-widget-metrics">
|
<MetricGrid columns={3} spacing="none">
|
||||||
<MetricCard label="i18n:govoplan-tasks.open" value={(summary?.open ?? 0) + (summary?.in_progress ?? 0)} tone="info" detail="i18n:govoplan-tasks.actionable_work" />
|
<MetricCard label="i18n:govoplan-tasks.open" value={(summary?.open ?? 0) + (summary?.in_progress ?? 0)} tone="info" detail="i18n:govoplan-tasks.actionable_work" />
|
||||||
<MetricCard label="i18n:govoplan-tasks.overdue" value={summary?.overdue ?? 0} tone={summary?.overdue ? "danger" : "good"} detail="i18n:govoplan-tasks.due_date_passed" />
|
<MetricCard label="i18n:govoplan-tasks.overdue" value={summary?.overdue ?? 0} tone={summary?.overdue ? "danger" : "good"} detail="i18n:govoplan-tasks.due_date_passed" />
|
||||||
<MetricCard label="i18n:govoplan-tasks.blocked" value={summary?.blocked ?? 0} tone={summary?.blocked ? "warning" : "good"} detail="i18n:govoplan-tasks.needs_resolution" />
|
<MetricCard label="i18n:govoplan-tasks.blocked" value={summary?.blocked ?? 0} tone={summary?.blocked ? "warning" : "good"} detail="i18n:govoplan-tasks.needs_resolution" />
|
||||||
</div>
|
</MetricGrid>
|
||||||
<div className="tasks-widget-actions"><Link className="btn btn-secondary" to="/tasks">i18n:govoplan-tasks.open_work_inbox</Link></div>
|
<div className="tasks-widget-actions"><Link className="btn btn-secondary" to="/tasks">i18n:govoplan-tasks.open_work_inbox</Link></div>
|
||||||
</LoadingFrame>
|
</LoadingFrame>
|
||||||
);
|
);
|
||||||
|
|||||||
+3
-5
@@ -5,6 +5,7 @@ import type {
|
|||||||
QuickAccessToolsUiCapability
|
QuickAccessToolsUiCapability
|
||||||
} from "@govoplan/core-webui";
|
} from "@govoplan/core-webui";
|
||||||
import TasksSummaryWidget from "./features/tasks/TasksSummaryWidget";
|
import TasksSummaryWidget from "./features/tasks/TasksSummaryWidget";
|
||||||
|
import TasksQuickAccess from "./features/tasks/TasksQuickAccess";
|
||||||
import { generatedTranslations } from "./i18n/generatedTranslations";
|
import { generatedTranslations } from "./i18n/generatedTranslations";
|
||||||
import "./styles/tasks.css";
|
import "./styles/tasks.css";
|
||||||
|
|
||||||
@@ -35,10 +36,7 @@ const quickAccessTools: QuickAccessToolsUiCapability = {
|
|||||||
tools: [
|
tools: [
|
||||||
{
|
{
|
||||||
id: "tasks.work",
|
id: "tasks.work",
|
||||||
render: ({ settings }) => createElement(TasksSummaryWidget, {
|
render: (context) => createElement(TasksQuickAccess, context)
|
||||||
settings,
|
|
||||||
refreshKey: 0
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
@@ -46,7 +44,7 @@ const quickAccessTools: QuickAccessToolsUiCapability = {
|
|||||||
export const tasksModule: PlatformWebModule = {
|
export const tasksModule: PlatformWebModule = {
|
||||||
id: "tasks",
|
id: "tasks",
|
||||||
label: "i18n:govoplan-tasks.work",
|
label: "i18n:govoplan-tasks.work",
|
||||||
version: "0.1.19",
|
version: "0.1.20",
|
||||||
dependencies: ["access"],
|
dependencies: ["access"],
|
||||||
optionalDependencies: ["idm", "organizations", "workflow_engine", "workflow", "notifications", "postbox", "approvals", "views", "dashboard", "search"],
|
optionalDependencies: ["idm", "organizations", "workflow_engine", "workflow", "notifications", "postbox", "approvals", "views", "dashboard", "search"],
|
||||||
translations: generatedTranslations,
|
translations: generatedTranslations,
|
||||||
|
|||||||
+24
-90
@@ -1,28 +1,3 @@
|
|||||||
.tasks-page {
|
|
||||||
box-sizing: border-box;
|
|
||||||
height: calc(100vh - 115px);
|
|
||||||
min-height: 0;
|
|
||||||
overflow: hidden;
|
|
||||||
color: var(--text);
|
|
||||||
background: var(--bg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-page *,
|
|
||||||
.tasks-page *::before,
|
|
||||||
.tasks-page *::after {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-shell {
|
|
||||||
height: 100%;
|
|
||||||
min-height: 0;
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: minmax(285px, 350px) minmax(0, 1fr);
|
|
||||||
border: var(--border-line);
|
|
||||||
background: var(--panel);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-sidebar,
|
.tasks-sidebar,
|
||||||
.tasks-workspace {
|
.tasks-workspace {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
@@ -32,13 +7,6 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tasks-sidebar {
|
|
||||||
border-right: var(--border-line);
|
|
||||||
background: var(--panel-soft);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-sidebar-bar,
|
|
||||||
.tasks-topbar,
|
|
||||||
.tasks-title,
|
.tasks-title,
|
||||||
.tasks-detail-title,
|
.tasks-detail-title,
|
||||||
.tasks-toolbar-actions,
|
.tasks-toolbar-actions,
|
||||||
@@ -51,15 +19,6 @@
|
|||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tasks-sidebar-bar,
|
|
||||||
.tasks-topbar {
|
|
||||||
min-height: 54px;
|
|
||||||
justify-content: space-between;
|
|
||||||
border-bottom: var(--border-line);
|
|
||||||
background: var(--panel-header);
|
|
||||||
padding: 9px 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-detail-title {
|
.tasks-detail-title {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
@@ -82,19 +41,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tasks-search {
|
.tasks-search {
|
||||||
height: 36px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 7px;
|
|
||||||
border: var(--border-line);
|
|
||||||
border-radius: 5px;
|
|
||||||
background: var(--surface);
|
|
||||||
margin: 8px 8px 0;
|
margin: 8px 8px 0;
|
||||||
padding: 0 9px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-search:focus-within {
|
|
||||||
border-color: var(--accent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tasks-search input {
|
.tasks-search input {
|
||||||
@@ -168,7 +115,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tasks-detail-main > p {
|
.tasks-detail-main > p {
|
||||||
max-width: 850px;
|
max-width: 900px;
|
||||||
line-height: 1.55;
|
line-height: 1.55;
|
||||||
white-space: pre-line;
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
@@ -179,7 +126,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tasks-required-action {
|
.tasks-required-action {
|
||||||
max-width: 850px;
|
max-width: 900px;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
border-left: 3px solid var(--accent);
|
border-left: 3px solid var(--accent);
|
||||||
@@ -232,22 +179,6 @@
|
|||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tasks-empty-detail {
|
|
||||||
min-height: 100%;
|
|
||||||
display: grid;
|
|
||||||
place-content: center;
|
|
||||||
justify-items: center;
|
|
||||||
color: var(--muted);
|
|
||||||
text-align: center;
|
|
||||||
padding: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-empty-detail h1 {
|
|
||||||
margin: 10px 0 0;
|
|
||||||
color: var(--text-strong);
|
|
||||||
font-size: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-create-form {
|
.tasks-create-form {
|
||||||
width: min(620px, 75vw);
|
width: min(620px, 75vw);
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -259,9 +190,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tasks-create-grid {
|
.tasks-create-grid {
|
||||||
display: grid;
|
|
||||||
grid-template-columns: minmax(150px, .75fr) minmax(260px, 1.25fr);
|
grid-template-columns: minmax(150px, .75fr) minmax(260px, 1.25fr);
|
||||||
gap: 12px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tasks-assignment-note {
|
.tasks-assignment-note {
|
||||||
@@ -276,32 +205,37 @@
|
|||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 820px) {
|
.tasks-quick-detail {
|
||||||
.tasks-shell {
|
display: grid;
|
||||||
grid-template-columns: minmax(230px, 42%) minmax(0, 1fr);
|
gap: 10px;
|
||||||
}
|
margin-top: 12px;
|
||||||
|
border-top: var(--border-line);
|
||||||
|
padding-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tasks-quick-detail-heading {
|
||||||
|
display: grid;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tasks-quick-detail-heading span,
|
||||||
|
.tasks-quick-detail > p {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 760px) {
|
||||||
.tasks-topbar {
|
.tasks-topbar {
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tasks-properties dl,
|
.tasks-properties dl {
|
||||||
.tasks-create-grid {
|
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 620px) {
|
@media (max-width: 680px) {
|
||||||
.tasks-shell {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
grid-template-rows: minmax(250px, 44%) minmax(0, 1fr);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-sidebar {
|
|
||||||
border-right: 0;
|
|
||||||
border-bottom: var(--border-line);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tasks-create-form {
|
.tasks-create-form {
|
||||||
width: min(100%, 88vw);
|
width: min(100%, 88vw);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user