docs: surface permission-gated Campaign tasks

This commit is contained in:
2026-07-21 18:53:07 +02:00
parent 99ef25b08f
commit c05bb8e474
3 changed files with 624 additions and 15 deletions

View File

@@ -31,18 +31,6 @@ _CAMPAIGN_USER_SCOPES = (
_CAMPAIGN_HELP_CONTEXTS = ( _CAMPAIGN_HELP_CONTEXTS = (
"campaigns.list", "campaigns.list",
"campaign.overview", "campaign.overview",
"campaign.settings",
"campaign.fields",
"campaign.template",
"campaign.attachments",
"campaign.recipients",
"campaign.recipient-data",
"campaign.server-settings",
"campaign.global-settings",
"campaign.review-send",
"campaign.report",
"campaign.audit",
"campaign.json",
) )
_FILES_INTEGRATION = "files.campaign_attachments" _FILES_INTEGRATION = "files.campaign_attachments"
@@ -52,6 +40,417 @@ _ADDRESSES_SOURCE_INTEGRATION = "addresses.recipient_source"
_NOTIFICATIONS_INTEGRATION = "notifications.dispatch" _NOTIFICATIONS_INTEGRATION = "notifications.dispatch"
def _workflow_topic(
*,
topic_id: str,
title: str,
summary: str,
body: str,
order: int,
audience: tuple[str, ...],
required_scopes: tuple[str, ...],
route: str,
screen: str,
help_contexts: tuple[str, ...],
prerequisites: tuple[str, ...],
steps: tuple[str, ...],
outcome: str,
verification: str,
related_topic_ids: tuple[str, ...] = (),
required_modules: tuple[str, ...] = ("campaigns",),
required_capabilities: tuple[str, ...] = (),
links: tuple[DocumentationLink, ...] = (DocumentationLink(label="Campaigns", href="/campaigns", kind="runtime"),),
related_modules: tuple[str, ...] = (),
limitations: tuple[str, ...] = (),
) -> DocumentationTopic:
metadata: dict[str, object] = {
"kind": "workflow",
"route": route,
"screen": screen,
"help_contexts": list(help_contexts),
"prerequisites": list(prerequisites),
"steps": list(steps),
"outcome": outcome,
"verification": verification,
"related_topic_ids": list(related_topic_ids),
}
if limitations:
metadata["limitations"] = list(limitations)
return DocumentationTopic(
id=topic_id,
title=title,
summary=summary,
body=body,
layer="configured",
documentation_types=("user",),
audience=audience,
order=order,
conditions=(
DocumentationCondition(
required_modules=required_modules,
required_capabilities=required_capabilities,
required_scopes=required_scopes,
),
),
links=links,
related_modules=related_modules,
unlocks=(outcome,),
source_module_id="campaigns",
metadata=metadata,
)
CAMPAIGN_USER_DOCUMENTATION = (
_workflow_topic(
topic_id="campaigns.workflow.create-campaign",
title="Create a campaign",
summary="Start a governed campaign as an editable draft and complete its purpose and ownership before adding delivery data.",
body="A new campaign starts with one editable working version. Creating it does not grant access to Mail profiles, managed files, address sources, or delivery actions; those remain separately authorized.",
order=30,
audience=("campaign_manager", "campaign_author"),
required_scopes=("campaigns:campaign:create",),
route="/campaigns",
screen="Campaigns",
help_contexts=("campaigns.list", "campaign.overview"),
prerequisites=("You may create campaigns in the active tenant.",),
steps=(
"Open Campaigns and select New campaign.",
"Use the creation wizard to enter a clear name, identifier, and purpose.",
"Open the new campaign and confirm its owner before adding recipient or delivery data.",
"Continue through the preparation sections and save the editable working version.",
),
outcome="An owned campaign draft with an editable working version.",
verification="The Campaign overview shows the new campaign as a draft and identifies its current working version.",
related_topic_ids=("campaigns.workflow.prepare-validate-and-build", "campaigns.workflow.import-recipients"),
),
_workflow_topic(
topic_id="campaigns.workflow.create-editable-successor",
title="Create an editable successor",
summary="Continue work after a permanent or delivery-final lock without rewriting the preserved version.",
body="Create editable copy means creating the campaign's next working version. Validation locks and temporary user locks are removed in place instead; they must not create parallel drafts.",
order=31,
audience=("campaign_manager", "campaign_author"),
required_scopes=("campaigns:campaign:read", "campaigns:campaign:copy", "campaigns:recipient:read"),
route="/campaigns/{campaign_id}",
screen="Campaign workspace",
help_contexts=("campaign.overview", "campaign.audit"),
prerequisites=(
"You have write access to the selected campaign.",
"Its current version is permanently user-locked or delivery-final.",
),
steps=(
"Open the locked current version and review the reason it is read-only.",
"Select Create editable copy in the locked-version notice.",
"If the notice instead offers an unlock action, unlock that validation or temporary user lock rather than creating a successor.",
"Review the new working version, reselect any Mail profile when requested, and validate and build again before delivery.",
),
outcome="A new editable working version while the source version and its evidence remain unchanged.",
verification="The Campaign overview identifies a new current version number and the earlier version remains in history.",
related_topic_ids=("campaigns.workflow.prepare-validate-and-build", "campaigns.mail-profile-user-journey"),
),
_workflow_topic(
topic_id="campaigns.workflow.import-recipients",
title="Import recipients into a campaign",
summary="Turn a text, CSV, or spreadsheet table into reviewed campaign-local recipient rows with source provenance.",
body="Import copies valid rows into the editable campaign version. Invalid rows stay visible during preview instead of disappearing, and later changes to the source file do not silently change the saved campaign.",
order=33,
audience=("campaign_manager", "campaign_author"),
required_scopes=(
"campaigns:campaign:read",
"campaigns:campaign:update",
"campaigns:recipient:read",
"campaigns:recipient:write",
"campaigns:recipient:import",
),
route="/campaigns/{campaign_id}/recipients",
screen="Recipient data",
help_contexts=("campaign.recipients", "campaign.recipient-data"),
prerequisites=(
"The current campaign version is editable and you have write access to it.",
"The source is tabular and contains only data needed for this campaign.",
),
steps=(
"Open Recipient data and select Import.",
"Upload or paste the table, then confirm its encoding, sheet, header rows, and separator where applicable.",
"Map address and campaign fields, choose append or replace, and review every invalid or excluded row.",
"Select Import valid rows, inspect the resulting recipient table, and save the campaign page.",
),
outcome="A campaign-local recipient snapshot with mapping and source evidence.",
verification="Reopen Recipient data, confirm the expected row count and addressing, then validate before building messages.",
related_topic_ids=("campaigns.workflow.import-address-source", "campaigns.workflow.prepare-validate-and-build"),
),
_workflow_topic(
topic_id="campaigns.workflow.import-address-source",
title="Import a recipient source from Addresses",
summary="Copy a permitted reusable address book or list into the campaign as a traceable versioned snapshot.",
body="Campaign does not follow the address source live. It records the selected source revision and warns when a newer source revision is available, so re-import is always an explicit author action.",
order=32,
audience=("campaign_manager", "campaign_author"),
required_modules=("campaigns", "addresses"),
required_capabilities=(_ADDRESSES_SOURCE_INTEGRATION,),
required_scopes=(
"campaigns:campaign:read",
"campaigns:campaign:update",
"campaigns:recipient:read",
"campaigns:recipient:write",
"campaigns:recipient:import",
),
route="/campaigns/{campaign_id}/recipients",
screen="Recipient data",
help_contexts=("campaign.recipients", "campaign.recipient-data"),
prerequisites=(
"Addresses offers at least one source visible to you.",
"The current campaign version is editable and you have write access to it.",
),
steps=(
"Open Recipient data and select Import address book/list.",
"Choose the permitted source and review the returned snapshot and its revision.",
"Choose append or replace, import the snapshot, inspect the recipient rows, and save.",
"When a stale-source warning appears later, compare the source and re-import deliberately if the campaign should use the new revision.",
),
outcome="A campaign-local recipient snapshot whose Addresses source and revision can be traced.",
verification="Recipient data records the source provenance, and a later source revision does not alter the saved rows until you re-import it.",
related_topic_ids=("campaigns.workflow.import-recipients", "campaigns.workflow.prepare-validate-and-build"),
related_modules=("addresses",),
),
_workflow_topic(
topic_id="campaigns.workflow.use-managed-attachments",
title="Use managed files as campaign attachments",
summary="Select governed file versions, preview rule matches, and preserve exactly which files were used for the campaign build.",
body="Managed attachments remain owned by Files. Campaign stores governed references and frozen build evidence; it does not copy Files administration authority or accept arbitrary server paths.",
order=34,
audience=("campaign_manager", "campaign_author"),
required_modules=("campaigns", "files"),
required_capabilities=(_FILES_INTEGRATION,),
required_scopes=(
"campaigns:campaign:read",
"campaigns:campaign:update",
"campaigns:campaign:validate",
"campaigns:recipient:read",
"files:file:read",
"files:file:share",
),
route="/campaigns/{campaign_id}/files",
screen="Attachments",
help_contexts=("campaign.attachments",),
prerequisites=(
"The current campaign version is editable and you have write access to it.",
"The required file versions exist in Files and may be shared with this campaign.",
),
steps=(
"Open Attachments and choose managed files or patterns from Files.",
"Define campaign-wide and recipient-specific rules, including unmatched-file and archive behavior.",
"Preview the matches and link the exact managed versions to the campaign.",
"Save, validate, and build, then inspect the resolved attachment evidence in Review and send.",
),
outcome="Governed file versions linked to the campaign and frozen into the exact build evidence.",
verification="Attachment preview and the built-message evidence show the expected file versions, matches, checksums, and archive behavior.",
related_topic_ids=("campaigns.workflow.prepare-validate-and-build",),
links=(
DocumentationLink(label="Campaigns", href="/campaigns", kind="runtime"),
DocumentationLink(label="Files", href="/files", kind="runtime"),
),
related_modules=("files",),
),
_workflow_topic(
topic_id="campaigns.workflow.queue-delivery",
title="Queue a campaign for controlled delivery",
summary="Place an exact reviewed build into the worker queue while preserving recipient-level state and retry protection.",
body="Queueing is a controlled state change, not proof of delivery. Ordinary batches should use background workers, and accepted or outcome-unknown effects remain protected from blind retry.",
order=35,
audience=("campaign_sender", "campaign_operator"),
required_modules=("campaigns", "mail"),
required_capabilities=(_MAIL_INTEGRATION,),
required_scopes=(
"campaigns:campaign:read",
"campaigns:campaign:queue",
"campaigns:recipient:read",
"mail:profile:use",
),
route="/campaigns/{campaign_id}/review",
screen="Review and send",
help_contexts=("campaign.review-send",),
prerequisites=(
"The selected version is validated, locked, built, and reviewed.",
"Its Mail profile remains available and authorized for the current campaign context.",
"You have write access to the selected campaign.",
),
steps=(
"Open Review and send and confirm the selected version, build, recipients, warnings, and review completion.",
"Run the queue estimate or dry run when offered and resolve every blocker.",
"Queue the build for background delivery; use the synchronous path only for an intentionally small controlled run.",
"Open the campaign Report and monitor queue, SMTP, IMAP, failure, and uncertain-outcome counts.",
),
outcome="Eligible jobs queued with an auditable execution snapshot and protected delivery state.",
verification="The Report shows the selected version's jobs as queued or progressing, without changing any accepted job back to retryable.",
related_topic_ids=("campaigns.workflow.complete-review", "campaigns.workflow.retry-and-reconcile"),
related_modules=("mail", "notifications"),
),
_workflow_topic(
topic_id="campaigns.workflow.send-small-controlled-run",
title="Send a small controlled campaign run",
summary="Use the synchronous delivery action only for a deliberately small, fully reviewed campaign build.",
body="The synchronous action is intentionally bounded and does not replace the worker queue for ordinary batches. It preserves the same protected SMTP, IMAP, retry, and uncertain-outcome rules.",
order=36,
audience=("campaign_sender", "campaign_operator"),
required_modules=("campaigns", "mail"),
required_capabilities=(_MAIL_INTEGRATION,),
required_scopes=(
"campaigns:campaign:read",
"campaigns:campaign:send",
"campaigns:recipient:read",
"mail:profile:use",
),
route="/campaigns/{campaign_id}/review",
screen="Review and send",
help_contexts=("campaign.review-send",),
prerequisites=(
"The selected version is validated, locked, built, and reviewed.",
"The run is small enough for the configured synchronous limit.",
"Its Mail profile remains available and authorized for the current campaign context.",
),
steps=(
"Open Review and send and inspect the exact build and delivery readiness checks.",
"Confirm that this is an intentionally small controlled run; use Queue for an ordinary batch.",
"Select Send now and confirm the protected delivery action.",
"Open Report and inspect each resulting delivery state before attempting any recovery action.",
),
outcome="A bounded real delivery run with recipient-level attempt and outcome evidence.",
verification="The Report distinguishes accepted, failed, unattempted, cancelled, and outcome-unknown jobs and retains their attempt history.",
related_topic_ids=("campaigns.workflow.queue-delivery", "campaigns.workflow.retry-and-reconcile"),
related_modules=("mail",),
),
_workflow_topic(
topic_id="campaigns.workflow.view-delivery-report",
title="Review a campaign delivery report",
summary="Inspect aggregate delivery outcomes and, when separately authorized, recipient-level job evidence.",
body="Report access does not imply access to recipient details or diagnostics. Aggregate business state remains useful for readers, while recipient rows and infrastructure diagnostics require separate authority.",
order=37,
audience=("campaign_reader", "campaign_manager", "campaign_reviewer", "campaign_sender"),
required_scopes=("campaigns:campaign:read", "campaigns:report:read"),
route="/campaigns/{campaign_id}/report",
screen="Campaign Report",
help_contexts=("campaign.report",),
prerequisites=("You may read the selected campaign and its report.",),
steps=(
"Open the campaign and select Report.",
"Review totals for queued, accepted, failed, cancelled, unattempted, and outcome-unknown jobs.",
"Inspect recipient-level rows and attempt history only when those details are available to your role.",
"Treat outcome-unknown jobs as unresolved and hand them to an authorized operator for evidence-backed reconciliation.",
),
outcome="A role-appropriate view of delivery progress and outcomes without exposing system internals.",
verification="The report totals match the selected campaign version, and recipient or diagnostic details are absent unless separately authorized.",
related_topic_ids=("campaigns.workflow.retry-and-reconcile", "campaigns.workflow.export-delivery-report"),
),
_workflow_topic(
topic_id="campaigns.workflow.export-delivery-report",
title="Export recipient delivery results",
summary="Download an authorized CSV snapshot of recipient-level campaign delivery results for controlled downstream use.",
body="A report export contains personal and delivery evidence. Store, transmit, retain, and delete it according to the campaign's purpose and the applicable export and retention policy.",
order=38,
audience=("campaign_report_exporter", "campaign_auditor"),
required_scopes=(
"campaigns:campaign:read",
"campaigns:report:export",
"campaigns:recipient:export",
),
route="/campaigns/{campaign_id}/report",
screen="Campaign Report",
help_contexts=("campaign.report", "campaign.audit"),
prerequisites=(
"You may export both campaign reports and recipient data.",
"The export has an approved purpose and destination.",
),
steps=(
"Open the campaign Report and select the intended version.",
"Confirm that recipient-level export is necessary for the task.",
"Select Download CSV and store the result only in the approved location.",
"Verify the selected version and row counts, then apply the required retention or deletion rule to the downloaded copy.",
),
outcome="A point-in-time CSV export of authorized campaign job results.",
verification="The downloaded file identifies the intended campaign/version and contains business evidence without credentials or ordinary-reader infrastructure details.",
related_topic_ids=("campaigns.workflow.view-delivery-report",),
),
_workflow_topic(
topic_id="campaigns.workflow.share-campaign",
title="Share a campaign",
summary="Grant a user or group explicit view or write access to one campaign without widening their platform permissions.",
body="A share can only narrow access to the selected campaign within the recipient's existing role. It never grants Mail profile use, Files authority, tenant-wide recipient access, or a missing Campaign action.",
order=39,
audience=("campaign_owner", "campaign_access_manager"),
required_scopes=("campaigns:campaign:read", "campaigns:campaign:share"),
route="/campaigns/{campaign_id}/global-settings",
screen="Ownership and sharing",
help_contexts=("campaign.overview", "campaign.global-settings"),
prerequisites=(
"You have write access to the selected campaign.",
"The target user or group already has an appropriate Campaign role for the intended actions.",
),
steps=(
"Open Global settings and find Ownership and sharing.",
"Select Share, choose a user or group, and choose Can view or Can edit and operate.",
"Save the share and verify the target appears in the sharing table with the intended level.",
"Use the row action to revoke the explicit share when it is no longer needed.",
),
outcome="Explicit campaign access for the selected subject, bounded by that subject's existing permissions.",
verification="The sharing table shows the active target and level; revocation removes its explicit access while preserving the audit record.",
related_topic_ids=("campaigns.reference.composition-assurance",),
),
_workflow_topic(
topic_id="campaigns.workflow.archive-campaign",
title="Archive a campaign",
summary="Remove a completed campaign from active work while preserving its versions, outcomes, and audit evidence.",
body="Archive only after queued, sending, and outcome-unknown work has been resolved. Archiving preserves evidence and is the correct lifecycle action for any campaign with build, lock, or delivery history.",
order=40,
audience=("campaign_owner", "campaign_records_manager"),
required_scopes=("campaigns:campaign:read", "campaigns:campaign:archive"),
route="/campaigns/{campaign_id}",
screen="Campaign lifecycle",
help_contexts=("campaign.overview", "campaign.report", "campaign.audit"),
prerequisites=(
"You have write access to the selected campaign.",
"No delivery job is queued, sending, or awaiting uncertain-outcome reconciliation.",
),
steps=(
"Open Report and resolve every active or outcome-unknown delivery state.",
"Confirm that the campaign should leave active work while its evidence remains retained.",
"Invoke the authorized Archive action from a supporting client.",
"Reopen or query the campaign and confirm its state is Archived.",
),
outcome="An archived campaign whose versions, reports, and audit evidence remain preserved.",
verification="The campaign state is Archived and its report and audit evidence remain available to authorized readers.",
related_topic_ids=("campaigns.workflow.view-delivery-report", "campaigns.workflow.delete-untouched-draft"),
limitations=("The current Campaign Web UI does not yet expose the archive action; use an authorized supporting client or API.",),
),
_workflow_topic(
topic_id="campaigns.workflow.delete-untouched-draft",
title="Delete an untouched campaign draft",
summary="Immediately remove a draft that has no protected build, lock, publication, snapshot, or delivery evidence.",
body="Deletion is deliberately narrower than archive. It marks an eligible draft deleted and emits an audit record; it cannot erase a campaign that already carries evidence that must be retained.",
order=41,
audience=("campaign_owner", "campaign_records_manager"),
required_scopes=("campaigns:campaign:read", "campaigns:campaign:delete"),
route="/campaigns/{campaign_id}",
screen="Campaign lifecycle",
help_contexts=("campaign.overview", "campaign.audit"),
prerequisites=(
"You have write access to the selected campaign.",
"The campaign is still a draft and has no jobs, locks, published version, or execution snapshot.",
),
steps=(
"Confirm that the draft is not needed and contains no evidence that should be retained.",
"Invoke the authorized Delete action from a supporting client and confirm the destructive action.",
"If deletion is refused because protected evidence exists, archive the campaign after resolving any active delivery state.",
"Verify that the deleted draft no longer appears in active Campaigns and that the audit event exists.",
),
outcome="An eligible untouched draft removed from active Campaigns with attributable deletion evidence.",
verification="The draft is no longer returned as an active campaign, while an authorized audit reader can verify who deleted it and when.",
related_topic_ids=("campaigns.workflow.archive-campaign",),
limitations=("The current Campaign Web UI does not yet expose the delete action; use an authorized supporting client or API.",),
),
)
def documentation_topics(context: DocumentationContext) -> tuple[DocumentationTopic, ...]: def documentation_topics(context: DocumentationContext) -> tuple[DocumentationTopic, ...]:
"""Describe the current Campaign composition without resolving module data. """Describe the current Campaign composition without resolving module data.

View File

@@ -28,7 +28,7 @@ from govoplan_core.core.modules import (
from govoplan_core.db.base import Base from govoplan_core.db.base import Base
from govoplan_campaign.backend.change_tracking import register_campaign_change_tracking from govoplan_campaign.backend.change_tracking import register_campaign_change_tracking
from govoplan_campaign.backend.db import models as campaign_models # noqa: F401 - populate Campaign ORM metadata from govoplan_campaign.backend.db import models as campaign_models # noqa: F401 - populate Campaign ORM metadata
from govoplan_campaign.backend.documentation import documentation_topics from govoplan_campaign.backend.documentation import CAMPAIGN_USER_DOCUMENTATION, documentation_topics
register_campaign_change_tracking() register_campaign_change_tracking()
@@ -263,6 +263,7 @@ manifest = ModuleManifest(
), ),
), ),
documentation=( documentation=(
*CAMPAIGN_USER_DOCUMENTATION,
DocumentationTopic( DocumentationTopic(
id="campaigns.mail-profile-user-journey", id="campaigns.mail-profile-user-journey",
title="Choose a Mail profile for campaign delivery", title="Choose a Mail profile for campaign delivery",
@@ -289,6 +290,7 @@ manifest = ModuleManifest(
"kind": "workflow", "kind": "workflow",
"route": "/campaigns/{campaign_id}/mail-settings", "route": "/campaigns/{campaign_id}/mail-settings",
"screen": "Campaign Mail settings", "screen": "Campaign Mail settings",
"help_contexts": ["campaign.server-settings"],
"prerequisites": [ "prerequisites": [
"Campaign and Mail are installed.", "Campaign and Mail are installed.",
"You may edit the current campaign version and use at least one authorized Mail profile.", "You may edit the current campaign version and use at least one authorized Mail profile.",
@@ -402,6 +404,19 @@ manifest = ModuleManifest(
"kind": "workflow", "kind": "workflow",
"route": "/campaigns/{campaign_id}/global-settings", "route": "/campaigns/{campaign_id}/global-settings",
"screen": "Campaign workspace", "screen": "Campaign workspace",
"help_contexts": [
"campaign.overview",
"campaign.settings",
"campaign.fields",
"campaign.template",
"campaign.attachments",
"campaign.recipients",
"campaign.recipient-data",
"campaign.server-settings",
"campaign.global-settings",
"campaign.review-send",
"campaign.json",
],
"prerequisites": [ "prerequisites": [
"The campaign has an owner and a clear communication purpose.", "The campaign has an owner and a clear communication purpose.",
"You may edit, validate, and build the selected campaign version.", "You may edit, validate, and build the selected campaign version.",
@@ -448,6 +463,7 @@ manifest = ModuleManifest(
"kind": "workflow", "kind": "workflow",
"route": "/campaigns/{campaign_id}/review", "route": "/campaigns/{campaign_id}/review",
"screen": "Review and send", "screen": "Review and send",
"help_contexts": ["campaign.review-send"],
"prerequisites": [ "prerequisites": [
"The selected campaign version is validated and built.", "The selected campaign version is validated and built.",
"You may read the campaign and complete its review.", "You may read the campaign and complete its review.",
@@ -491,6 +507,7 @@ manifest = ModuleManifest(
"kind": "workflow", "kind": "workflow",
"route": "/operator", "route": "/operator",
"screen": "Campaign operator queue", "screen": "Campaign operator queue",
"help_contexts": ["campaign.review-send", "campaign.report", "campaign.audit"],
"prerequisites": [ "prerequisites": [
"You may perform the selected retry or reconciliation action.", "You may perform the selected retry or reconciliation action.",
"Provider, mailbox, worker, and campaign evidence has been preserved.", "Provider, mailbox, worker, and campaign evidence has been preserved.",

View File

@@ -5,8 +5,7 @@ from types import SimpleNamespace
import pytest import pytest
from govoplan_campaign.backend.documentation import documentation_topics from govoplan_campaign.backend.documentation import CAMPAIGN_USER_DOCUMENTATION, documentation_topics
from govoplan_campaign.backend.manifest import get_manifest
from govoplan_core.core.modules import DocumentationContext from govoplan_core.core.modules import DocumentationContext
@@ -47,6 +46,8 @@ def _topics(scopes: set[str], integrations: set[str] | None = None, *, documenta
def test_campaign_runtime_documentation_provider_is_registered() -> None: def test_campaign_runtime_documentation_provider_is_registered() -> None:
from govoplan_campaign.backend.manifest import get_manifest
assert documentation_topics in get_manifest().documentation_providers assert documentation_topics in get_manifest().documentation_providers
@@ -150,9 +151,201 @@ def test_runtime_documentation_full_composition_uses_only_user_facing_names() ->
assert "Managed file versions" in rendered assert "Managed file versions" in rendered
assert "Address records" in rendered assert "Address records" in rendered
assert "In-app notifications" in rendered assert "In-app notifications" in rendered
assert topic.metadata["help_contexts"] == ["campaigns.list", "campaign.overview"]
for technical_name in integrations: for technical_name in integrations:
assert technical_name not in rendered assert technical_name not in rendered
assert "0.1." not in rendered assert "0.1." not in rendered
assert "0.2." not in rendered assert "0.2." not in rendered
assert "hostname" not in rendered.lower() assert "hostname" not in rendered.lower()
assert "secret" not in rendered.lower() assert "secret" not in rendered.lower()
def _visible_static_topics(
scopes: set[str],
*,
modules: set[str] | None = None,
capabilities: set[str] | None = None,
) -> set[str]:
installed = modules or {"campaigns"}
available_capabilities = capabilities or set()
principal = _Principal(frozenset(scopes))
visible: set[str] = set()
for topic in CAMPAIGN_USER_DOCUMENTATION:
condition = topic.conditions[0]
if not set(condition.required_modules).issubset(installed):
continue
if not set(condition.required_capabilities).issubset(available_capabilities):
continue
if not all(principal.has(scope) for scope in condition.required_scopes):
continue
visible.add(topic.id)
return visible
def test_campaign_manager_sees_only_authoring_tasks_from_the_static_handbook() -> None:
visible = _visible_static_topics(
{
"campaigns:campaign:read",
"campaigns:campaign:create",
"campaigns:campaign:update",
"campaigns:campaign:copy",
"campaigns:campaign:validate",
"campaigns:campaign:build",
"campaigns:recipient:read",
"campaigns:recipient:write",
"campaigns:recipient:import",
"campaigns:report:read",
}
)
assert {
"campaigns.workflow.create-campaign",
"campaigns.workflow.create-editable-successor",
"campaigns.workflow.import-recipients",
"campaigns.workflow.view-delivery-report",
}.issubset(visible)
assert "campaigns.workflow.queue-delivery" not in visible
assert "campaigns.workflow.send-small-controlled-run" not in visible
assert "campaigns.workflow.export-delivery-report" not in visible
assert "campaigns.workflow.share-campaign" not in visible
assert "campaigns.workflow.archive-campaign" not in visible
assert "campaigns.workflow.delete-untouched-draft" not in visible
def test_sender_sees_queue_and_send_only_with_the_mail_contract_and_profile_authority() -> None:
scopes = {
"campaigns:campaign:read",
"campaigns:campaign:queue",
"campaigns:campaign:send",
"campaigns:recipient:read",
"campaigns:report:read",
"mail:profile:use",
}
without_mail = _visible_static_topics(scopes)
with_mail = _visible_static_topics(
scopes,
modules={"campaigns", "mail"},
capabilities={"mail.campaign_delivery"},
)
assert "campaigns.workflow.queue-delivery" not in without_mail
assert "campaigns.workflow.send-small-controlled-run" not in without_mail
assert "campaigns.workflow.queue-delivery" in with_mail
assert "campaigns.workflow.send-small-controlled-run" in with_mail
def test_connected_authoring_tasks_require_their_declared_contracts_and_permissions() -> None:
attachment_scopes = {
"campaigns:campaign:read",
"campaigns:campaign:update",
"campaigns:campaign:validate",
"campaigns:recipient:read",
"files:file:read",
"files:file:share",
}
source_scopes = {
"campaigns:campaign:read",
"campaigns:campaign:update",
"campaigns:recipient:read",
"campaigns:recipient:write",
"campaigns:recipient:import",
}
files_visible = _visible_static_topics(
attachment_scopes,
modules={"campaigns", "files"},
capabilities={"files.campaign_attachments"},
)
addresses_visible = _visible_static_topics(
source_scopes,
modules={"campaigns", "addresses"},
capabilities={"addresses.recipient_source"},
)
assert "campaigns.workflow.use-managed-attachments" in files_visible
assert "campaigns.workflow.import-address-source" in addresses_visible
assert "campaigns.workflow.use-managed-attachments" not in _visible_static_topics(attachment_scopes)
assert "campaigns.workflow.import-address-source" not in _visible_static_topics(source_scopes)
def test_report_export_and_lifecycle_tasks_are_independently_permission_gated() -> None:
exporter = _visible_static_topics(
{
"campaigns:campaign:read",
"campaigns:report:export",
"campaigns:recipient:export",
}
)
custodian = _visible_static_topics(
{
"campaigns:campaign:read",
"campaigns:campaign:share",
"campaigns:campaign:archive",
"campaigns:campaign:delete",
}
)
assert "campaigns.workflow.export-delivery-report" in exporter
assert "campaigns.workflow.view-delivery-report" not in exporter
assert "campaigns.workflow.share-campaign" in custodian
assert "campaigns.workflow.archive-campaign" in custodian
assert "campaigns.workflow.delete-untouched-draft" in custodian
assert "campaigns.workflow.export-delivery-report" not in custodian
def test_static_campaign_handbook_has_unique_ids_help_contexts_and_no_planned_resend_claim() -> None:
from govoplan_campaign.backend.manifest import get_manifest
topics = get_manifest().documentation
ids = [topic.id for topic in topics]
rendered_static = "\n".join(
(topic.title + "\n" + topic.summary + "\n" + topic.body).lower()
for topic in CAMPAIGN_USER_DOCUMENTATION
)
known_help_contexts = {
"campaigns.list",
"campaign.overview",
"campaign.settings",
"campaign.fields",
"campaign.template",
"campaign.attachments",
"campaign.recipients",
"campaign.recipient-data",
"campaign.server-settings",
"campaign.global-settings",
"campaign.review-send",
"campaign.report",
"campaign.audit",
"campaign.json",
}
assert len(ids) == len(set(ids))
assert "single resend" not in rendered_static
for topic in CAMPAIGN_USER_DOCUMENTATION:
assert topic.metadata["kind"] == "workflow"
assert topic.metadata["prerequisites"]
assert topic.metadata["steps"]
assert topic.metadata["outcome"]
assert topic.metadata["verification"]
assert set(topic.metadata["help_contexts"]).issubset(known_help_contexts)
existing_user_workflows = {
topic.id: topic
for topic in topics
if topic.id
in {
"campaigns.mail-profile-user-journey",
"campaigns.workflow.prepare-validate-and-build",
"campaigns.workflow.complete-review",
"campaigns.workflow.retry-and-reconcile",
}
}
assert set(existing_user_workflows) == {
"campaigns.mail-profile-user-journey",
"campaigns.workflow.prepare-validate-and-build",
"campaigns.workflow.complete-review",
"campaigns.workflow.retry-and-reconcile",
}
for topic in existing_user_workflows.values():
assert topic.metadata["help_contexts"]