Skip to content

feat(membership): accept PAT principals; add SetPATAllProjectsRole#1665

Open
AmanGIT07 wants to merge 5 commits into
mainfrom
feat/membership-accept-pat-principal
Open

feat(membership): accept PAT principals; add SetPATAllProjectsRole#1665
AmanGIT07 wants to merge 5 commits into
mainfrom
feat/membership-accept-pat-principal

Conversation

@AmanGIT07
Copy link
Copy Markdown
Contributor

Summary

Membership package now accepts app/pat principals across org/project member methods. Adds SetPATAllProjectsRole for the pat_granted (all-projects) write path.

Changes

  • validatePrincipal and validateOrgMembership accept app/pat — resolve via new UserPATService interface, check pat.OrgID == orgID and pat.ExpiresAt.After(time.Now())
  • AddOrganizationMember / SetOrganizationMemberRole skip org#member/org#owner relation writes for PAT (schema disallows app/pat there)
  • RemoveProjectMember allowlist now includes PAT
  • New SetPATAllProjectsRole(orgID, patID, roleID) writes one pat_granted policy on the org; idempotent; replaces prior all-projects role
  • SetUserPATService setter wired in cmd/serve.go
  • New error: ErrPrincipalExpired

Technical Details

  • pat_granted filter applied in Go after policyService.Listpolicy.Filter has no GrantRelation field
  • UserPATService unset → validatePrincipal returns ErrInvalidPrincipal for PAT
  • No userpat caller routes through these methods yet — that refactor lands in a follow-up stacked PR

Test Plan

  • TestService_AddOrganizationMember_PAT, TestService_SetOrganizationMemberRole_PAT, TestService_SetPATAllProjectsRole, PAT row in TestService_RemoveProjectMember
  • go test ./core/membership/... ./core/userpat/... ./internal/api/v1beta1connect/... passes
  • go build ./... passes

AddOrganizationMember, SetOrganizationMemberRole, and RemoveProjectMember
now accept app/pat principals — they skip the org#member/org#owner relation
writes since the schema disallows app/pat there. New SetPATAllProjectsRole
writes a pat_granted policy on the org for the all-projects cascade.
UserPATService is wired post-construction to break the userpat <-> membership
cycle.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 2, 2026

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

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Jun 2, 2026 4:01pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

Warning

Review limit reached

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

More reviews will be available in 12 minutes and 14 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ 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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9af6849f-7961-4a4b-82af-20bac8b165d4

📥 Commits

Reviewing files that changed from the base of the PR and between 94ca143 and 93f8b40.

📒 Files selected for processing (1)
  • core/membership/service_test.go
📝 Walkthrough

Walkthrough

Adds UserPATService wiring and mock, validates PAT principals (org match and expiry), special-cases org/project membership flows for PATs (audit-only for PATs), implements SetPATAllProjectsRole and RemoveAllPATPolicies, and adds tests for PAT behaviors.

Sequence Diagram(s)

sequenceDiagram
  participant MembershipService
  participant UserPATService
  participant PolicyService
  participant AuditService
  MembershipService->>UserPATService: GetByID(ctx, patID)
  MembershipService->>PolicyService: List(org, patID) / Delete(matching pat_granted) / Create(pat_granted)
  MembershipService->>AuditService: Audit(member/role change)
Loading

Possibly related issues

Suggested reviewers

  • whoAbhishekSah
  • rohilsurana
  • rsbh
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main changes: adding PAT principal support to membership and introducing the SetPATAllProjectsRole method.
Description check ✅ Passed The description is well-structured with all required template sections filled: Summary, Changes, Technical Details, and Test Plan with completed checkboxes.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coveralls
Copy link
Copy Markdown

coveralls commented Jun 2, 2026

Coverage Report for CI Build 26831985435

Coverage increased (+0.1%) to 43.184%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 31 uncovered changes across 2 files (110 of 141 lines covered, 78.01%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
core/membership/service.go 140 110 78.57%
cmd/serve.go 1 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 38021
Covered Lines: 16419
Line Coverage: 43.18%
Coverage Strength: 12.1 hits per line

💛 - Coveralls

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
core/membership/service_test.go (1)

1251-1266: ⚡ Quick win

Cover the plain org-membership policy collision here.

SetPATAllProjectsRole lists PAT policies by (orgID, principalID, principalType) and filters pat_granted in Go, while AddOrganizationMember also creates an org-scoped PAT policy with an empty GrantRelation. This test only proves we ignore granted; it won't catch a regression where a normal PAT org policy is mistaken for the all-projects grant and gets deleted or causes a false no-op. Please add a case with both a regular PAT org policy (GrantRelation == "") and a pat_granted policy in the returned list.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 43e5a05c-1ea2-4153-aa6a-d6e6d4424454

📥 Commits

Reviewing files that changed from the base of the PR and between 0e8b178 and 1646d86.

📒 Files selected for processing (5)
  • cmd/serve.go
  • core/membership/errors.go
  • core/membership/mocks/user_pat_service.go
  • core/membership/service.go
  • core/membership/service_test.go

Comment thread core/membership/service.go
Comment thread core/membership/service.go
- SetOrganizationMemberRole skips ErrNotMember for PAT so it acts as an
  upsert (PAT may not have a prior org policy).
- Gate validateMinOwnerConstraint to UserPrincipal in both
  SetOrganizationMemberRole and RemoveOrganizationMember — only humans
  can be the last owner.
- validateOrgMembership PAT branch returns ErrInvalidPrincipal (matching
  validatePrincipal) when userPATService is not wired.
- ListPrincipalsByResource filters out pat_granted policies for org
  listings via new excludePATAllProjects helper — that grant lives on
  the org but means project access, not org membership.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PATs are single-org and hold no SpiceDB owner/member relations, so their
teardown reduces to listing-and-deleting their policies. Adds:

- RemoveAllPATPolicies(ctx, patID) — public method for PAT teardown
- removePoliciesByFilter(ctx, filter) — private list-and-delete primitive

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…granted

Verifies that when a PAT has both a granted org policy and a pat_granted
all-projects policy, SetPATAllProjectsRole only replaces the pat_granted
one — the role-match no-op check operates on pat_granted policies only,
and the granted policy is not deleted.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

2 participants