Skip to content

feat(ct-05): Define workspace deactivation with active bookings policy - #831

Merged
Qoder-Voidd merged 1 commit into
Akazajan:mainfrom
rindicomfort:feat/ct05-workspace-deactivation-policy
Oct 23, 2026
Merged

Qoder-Voidd merged 1 commit into
Akazajan:mainfrom
rindicomfort:feat/ct05-workspace-deactivation-policy

Conversation

@rindicomfort

Copy link
Copy Markdown
Contributor

Summary

Implements issue #709 (CT-05) — defines and enforces an explicit workspace deactivation policy in the workspace_booking Soroban contract.

Policy

An admin cannot deactivate a workspace while it has one or more active bookings. The set_workspace_availability function returns the stable error WorkspaceHasActiveBookings (code 203) so the caller can retry after the bookings end, are cancelled, or expire.

Reactivation (setting is_available = true) is always allowed, regardless of active bookings.

Existing bookings are never modified or removed — deactivation only prevents new bookings from being created.

Changes

contracts/workspace_booking/src/lib.rs

  • Added private workspace_has_active_bookings helper — iterates the active-bookings index (same pattern as is_slot_available / booked_seats_in_window).
  • Modified set_workspace_availability to check for active bookings before deactivating. Returns Error::WorkspaceHasActiveBookings (203) when blocked.
  • Added public workspace_has_active_bookings_query for off-chain callers to check whether a workspace has active bookings before attempting deactivation.

contracts/workspace_booking/src/errors.rs

  • No changes needed — WorkspaceHasActiveBookings = 203 was already defined but unused. Now it is returned by the deactivation guard.

contracts/workspace_booking/src/test.rs

  • test_ct05_deactivate_no_active_bookings_succeeds — deactivation with no bookings succeeds.
  • test_ct05_deactivate_with_active_booking_blocked — deactivation with an active booking returns Error 203, workspace stays Available, booking preserved.
  • test_ct05_deactivate_after_cancel_succeeds — blocked while active, succeeds after cancellation.
  • test_ct05_reactivate_with_active_bookings_allowed — reactivation always permitted.
  • test_ct05_deactivate_multiple_active_bookings_blocked — multiple active bookings block deactivation.
  • test_ct05_deactivate_non_admin_fails — non-admin gets Unauthorized.
  • test_ct05_deactivate_nonexistent_workspace_fails — returns WorkspaceNotFound.
  • test_ct05_active_bookings_query — public query returns correct state before booking, during active booking, and after cancellation.

Acceptance Criteria

  • The chosen policy is explicit (block deactivation when active bookings exist)
  • Returns a stable error when blocked (WorkspaceHasActiveBookings = 203)
  • Preserves existing bookings (function never touches booking records)

Closes #709

Define and enforce an explicit deactivation policy in the
workspace_booking Soroban contract:

- Admin cannot deactivate a workspace (set_workspace_availability with
  is_available=false) while it has one or more active bookings.
  The function returns the stable error WorkspaceHasActiveBookings (203)
  so callers can retry after bookings end, are cancelled, or expire.
- Reactivation (is_available=true) is always allowed, regardless of
  whether active bookings exist.
- Existing bookings are never modified or removed by this function —
  deactivation only prevents new bookings from being created.
- Added a private workspace_has_active_bookings helper that iterates
  the active-bookings index (same pattern as is_slot_available).
- Added a public workspace_has_active_bookings_query for off-chain
  callers to check whether a workspace has active bookings before
  attempting deactivation.

Tests added (test.rs):
- Deactivate with no bookings succeeds.
- Deactivate with an active booking is blocked (Error 203).
- Deactivate after cancelling all bookings succeeds.
- Reactivate with active bookings is always allowed.
- Deactivate with multiple active bookings is blocked.
- Non-admin deactivation is Unauthorized.
- Deactivate non-existent workspace is WorkspaceNotFound.
- Public query returns correct active-bookings state.

Closes Akazajan#709

@Qoder-Voidd Qoder-Voidd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Qoder-Voidd
Qoder-Voidd merged commit ec1e651 into Akazajan:main Oct 23, 2026
1 of 7 checks passed
harmondconsultant-png pushed a commit to harmondconsultant-png/Oraculum that referenced this pull request Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CT-05 — Define workspace deactivation with active bookings

2 participants