Refresh invite operations workspace
This commit is contained in:
@@ -1695,9 +1695,34 @@ async def get_invites() -> Dict[str, Any]:
|
||||
results = []
|
||||
for invite in invites:
|
||||
profile = profiles.get(invite.get("profile_id"))
|
||||
if not invite.get("enabled"):
|
||||
operational_state = "disabled"
|
||||
state_label = "Disabled"
|
||||
attention_reason = "This invite has been switched off."
|
||||
elif invite.get("is_expired"):
|
||||
operational_state = "expired"
|
||||
state_label = "Expired"
|
||||
attention_reason = "The invite has passed its expiry date."
|
||||
elif invite.get("remaining_uses") == 0:
|
||||
operational_state = "exhausted"
|
||||
state_label = "Fully used"
|
||||
attention_reason = "Every permitted sign-up has been used."
|
||||
elif invite.get("profile_id") is not None and (
|
||||
profile is None or profile.get("is_active") is False
|
||||
):
|
||||
operational_state = "profile_unavailable"
|
||||
state_label = "Profile unavailable"
|
||||
attention_reason = "The assigned profile is missing or disabled."
|
||||
else:
|
||||
operational_state = "ready"
|
||||
state_label = "Ready to use"
|
||||
attention_reason = None
|
||||
results.append(
|
||||
{
|
||||
**invite,
|
||||
"operational_state": operational_state,
|
||||
"state_label": state_label,
|
||||
"attention_reason": attention_reason,
|
||||
"profile": (
|
||||
{
|
||||
"id": profile.get("id"),
|
||||
@@ -1708,7 +1733,16 @@ async def get_invites() -> Dict[str, Any]:
|
||||
),
|
||||
}
|
||||
)
|
||||
return {"invites": results}
|
||||
return {
|
||||
"invites": results,
|
||||
"summary": {
|
||||
"total": len(results),
|
||||
"ready": sum(1 for invite in results if invite["operational_state"] == "ready"),
|
||||
"attention": sum(1 for invite in results if invite["operational_state"] != "ready"),
|
||||
"used_signups": sum(int(invite.get("use_count") or 0) for invite in results),
|
||||
"with_recipient": sum(1 for invite in results if invite.get("recipient_email")),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@router.get("/invites/policy")
|
||||
|
||||
@@ -17,6 +17,7 @@ from backend.app.config import settings
|
||||
from backend.app.network_security import request_trusts_forwarded_headers, validate_notification_target_url
|
||||
from backend.app.models import ActionOption, NormalizedState, RequestType, Snapshot, TimelineHop
|
||||
from backend.app.routers import auth as auth_router
|
||||
from backend.app.routers import admin as admin_router
|
||||
from backend.app.routers import portal as portal_router
|
||||
from backend.app.routers import requests as requests_router
|
||||
from backend.app.routers import site as site_router
|
||||
@@ -1604,6 +1605,37 @@ class PortalMediaStatusTests(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertNotIn("secret upstream failure", str(result))
|
||||
|
||||
|
||||
class InviteOperationalStateTests(TempDatabaseMixin, unittest.IsolatedAsyncioTestCase):
|
||||
async def test_invite_list_reports_automatic_operational_states(self) -> None:
|
||||
ready = db.create_signup_invite(code="READY", recipient_email="ready@example.com")
|
||||
db.create_signup_invite(code="DISABLED", enabled=False, recipient_email="off@example.com")
|
||||
used = db.create_signup_invite(code="USED", max_uses=1, recipient_email="used@example.com")
|
||||
db.increment_signup_invite_use(int(used["id"]))
|
||||
db.create_signup_invite(
|
||||
code="EXPIRED",
|
||||
expires_at="2000-01-01T00:00:00+00:00",
|
||||
recipient_email="expired@example.com",
|
||||
)
|
||||
db.create_signup_invite(
|
||||
code="NO-PROFILE",
|
||||
profile_id=999,
|
||||
recipient_email="profile@example.com",
|
||||
)
|
||||
|
||||
payload = await admin_router.get_invites()
|
||||
states = {invite["code"]: invite["operational_state"] for invite in payload["invites"]}
|
||||
|
||||
self.assertEqual(states[ready["code"]], "ready")
|
||||
self.assertEqual(states["DISABLED"], "disabled")
|
||||
self.assertEqual(states["USED"], "exhausted")
|
||||
self.assertEqual(states["EXPIRED"], "expired")
|
||||
self.assertEqual(states["NO-PROFILE"], "profile_unavailable")
|
||||
self.assertEqual(payload["summary"]["total"], 5)
|
||||
self.assertEqual(payload["summary"]["ready"], 1)
|
||||
self.assertEqual(payload["summary"]["attention"], 4)
|
||||
self.assertEqual(payload["summary"]["used_signups"], 1)
|
||||
|
||||
|
||||
class PortalWorkflowTests(TempDatabaseMixin, unittest.TestCase):
|
||||
def test_legacy_request_status_maps_to_workflow(self) -> None:
|
||||
item = {"kind": "request", "status": "in_progress"}
|
||||
|
||||
Reference in New Issue
Block a user