Skip to content

feat(store): project users search skips soft-deleted rows - #1946

Merged
AmanGIT07 merged 2 commits into
mainfrom
soft-delete-project-users-reads
Sep 25, 2026
Merged

AmanGIT07 merged 2 commits into
mainfrom
soft-delete-project-users-reads

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Fourth of the org view repositories. Follows #1943 and #1945.

Summary

The project users search leaves out soft-deleted policies, users, and roles. It also joins projects, so a soft-deleted project reports no members.

Changes

  • The base query starts from fromLive(policies) and adds live on the joined users and roles.
  • A new inner join on projects with live on it. Without this, a soft-deleted project still returns its members whenever their grants are untouched.
  • New docker-backed suite project_users_repository_pg_test.go: seeds a soft-deleted user, a soft-deleted grant, a member whose role is soft-deleted, and a soft-deleted project, then checks the member list, the reported roles, and the text search.

Technical Details

The project id arrives as a request parameter and the handler passes it straight through. Before this change the three possible ids answered three different ways: an unknown id returned an empty list, a soft-deleted project returned its members, and a malformed id returned an internal error. The new join makes the first two agree. The malformed id is unchanged here and is tracked separately, since ten aggregate searches share that gap.

The join is on the projects primary key, so it matches at most one row and cannot duplicate members or change the grouping.

Frontier does not set deleted_at on these tables yet, so the search returns the same rows as before.

Test Plan

  • go test -run 'TestProjectUsersRepository' ./internal/store/postgres/ passes (unit tests and the new suite)
  • The new suite fails on main
  • golangci-lint run ./internal/store/postgres/... reports no issues
  • End to end against a local server through AdminService/SearchProjectUsers. An org, two projects and four members were created through the public RPCs, then deleted_at was set by SQL. The same scenarios ran against main on the same database, with only the binary swapped.
# Scenario This branch main
1 Baseline before any soft delete: five members on the live project PASS PASS
2 The soft-deleted user is not listed PASS FAIL
3 The member whose grant is soft-deleted is not listed PASS FAIL
4 The member whose role is soft-deleted is not listed PASS FAIL
5 Only the live members are listed PASS FAIL
6 The live role is still reported PASS PASS
7 The soft-deleted project reports no members PASS FAIL
8 A project id nobody owns reports no members PASS PASS
9 Search matching a live member returns them PASS PASS
10 Search matching a soft-deleted member returns nothing PASS FAIL

SQL Safety

  • Values flow through ? placeholders, goqu.Ex{}, or goqu.Record{} — never fmt.Sprintf or + building a query that gets executed.
  • ToSQL() callers capture and forward params (query, params, err := stmt.ToSQL(); db.…Context(ctx, …, query, params...)). Never query, _, err := ….
  • No ? placeholders inside single-quoted SQL literals in goqu.L.
  • No new //nolint:forbidigo or // #nosec G20x annotations.

The search reads policies, users, and roles through the live-row helpers,
and joins projects so a soft-deleted project reports no members, the same
as a project id nobody owns.
…t-deleted rows

Seeds a soft-deleted user, grant, role, and project, then checks the
member list, the reported roles, and the text search.
@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
frontier Building Building Preview Sep 24, 2026 11:13am UTC

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: raystack/frontier/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 71c3e8a8-b603-4242-a1a3-65e1584d9f66

📥 Commits

Reviewing files that changed from the base of the PR and between 057a60c and 7bcf2ac.

📒 Files selected for processing (3)
  • internal/store/postgres/project_users_repository.go
  • internal/store/postgres/project_users_repository_pg_test.go
  • internal/store/postgres/project_users_repository_test.go

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Project member searches now exclude members associated with deleted projects, users, roles, or access grants.
    • Searches for deleted projects no longer return members, and keyword results include only active records.

Walkthrough

The project users query now filters soft-deleted policies, projects, users, and roles. SQL expectations and PostgreSQL integration tests cover the query and search results.

Changes

Project user search

Layer / File(s) Summary
Query live-row filtering
internal/store/postgres/project_users_repository.go, internal/store/postgres/project_users_repository_test.go
The base query uses live policies, joins projects by resource ID, and filters out soft-deleted projects, users, and roles. Expected SQL reflects the project join and live-project condition.
PostgreSQL search verification
internal/store/postgres/project_users_repository_pg_test.go
Integration tests seed live and soft-deleted records, then check project membership and keyword search results.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 7bcf2

No actionable issue is established in the project-user search change; it is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 35991795059

Coverage increased (+0.08%) to 51.838%

Details

  • Coverage increased (+0.08%) from the base build.
  • Patch coverage: 15 of 15 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 41142
Covered Lines: 21327
Line Coverage: 51.84%
Coverage Strength: 16.92 hits per line

💛 - Coveralls

@AmanGIT07
AmanGIT07 merged commit c9112ac into main Sep 25, 2026
8 checks passed
@AmanGIT07
AmanGIT07 deleted the soft-delete-project-users-reads branch September 25, 2026 08:19

This branch was successfully deployed

1 active deployment
Preview — 7bcf2ac4 Deployed Sep 24, 2026 by vercel[bot]
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.

3 participants