Skip to content

table/server: soft-delete logic and guards for org-units (#181)#187

Merged
Prabhjot-Sethi merged 1 commit into
go-core-stack:mainfrom
dev-arya23:feat/ou-soft-delete-logic
Jun 27, 2026
Merged

table/server: soft-delete logic and guards for org-units (#181)#187
Prabhjot-Sethi merged 1 commit into
go-core-stack:mainfrom
dev-arya23:feat/ou-soft-delete-logic

Conversation

@dev-arya23

Copy link
Copy Markdown
Contributor

Summary

Implements the data model changes and API guards for org-unit soft-delete (issue #181).

Changes:

  • pkg/table/org-unit.go: Add Deleted int64 field to OrgUnitEntry with bson:"deleted,omitempty" — zero value (active) means the field is omitted from MongoDB documents
  • pkg/server/org-unit.go:
    • DeleteOrgUnit: when allow_ou_delete is enabled, sets deleted to current unix timestamp via update (not hard-delete). Returns 200 OK without changing the timestamp if OU is already deleted (idempotent). Returns Unimplemented when feature is disabled (preserves existing behavior)
    • UpdateOrgUnit: guard against updates on deleted OUs — returns codes.FailedPrecondition / 412 if deleted > 0
    • GetOrgUnit / ListOrgUnits: wire status and deleted fields into responses using the proto OrgUnitStatus enum
    • Thread ExperimentalConfig into OrgUnitServer for feature-gated delete
  • pkg/server/org-unit-user.go:
    • AddOrgUnitUser: guard against adding users to a deleted OU — returns codes.FailedPrecondition
    • Add ouTable to OrgUnitUserServer for OU lookup during the guard check
  • main.go: pass conf.GetExperimental() to NewOrgUnitServer

Design decisions:

  • Status is derived from the Deleted field (not stored separately) — single source of truth
  • NewOrgUnitUserServer signature unchanged (OU table fetched via existing GetOrgUnitTable() singleton) to minimize call-site changes
  • Cascading cleanup of org-unit-users is a separate concern per the issue

Closes #181

…e-stack#181)

Add data model changes and API guards for org-unit soft-delete:

- Add Deleted int64 field to OrgUnitEntry (bson:"deleted,omitempty")
- Implement DeleteOrgUnit: sets deleted timestamp when allow_ou_delete
  is enabled, idempotent for already-deleted OUs
- Guard UpdateOrgUnit: return FailedPrecondition if OU is deleted
- Guard AddOrgUnitUser: reject user additions to deleted OUs
- Wire status/deleted fields into GetOrgUnit and ListOrgUnits responses
- Thread ExperimentalConfig into OrgUnitServer and OrgUnitUserServer
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@dev-arya23, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 42 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3163c178-5d47-4088-973e-339b81d812b5

📥 Commits

Reviewing files that changed from the base of the PR and between 5dbf366 and 382c477.

📒 Files selected for processing (4)
  • main.go
  • pkg/server/org-unit-user.go
  • pkg/server/org-unit.go
  • pkg/table/org-unit.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Prabhjot-Sethi Prabhjot-Sethi merged commit 95ddf93 into go-core-stack:main Jun 27, 2026
1 of 2 checks passed
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.

Table/model: soft-delete logic and guards

2 participants