feat: validate user project access during PAT Create and Update#1487
feat: validate user project access during PAT Create and Update#1487
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 32 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds project-access validation to the user personal access token service. It introduces a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b764f742-bcd9-4b1b-af7c-0cd84ad30de2
📒 Files selected for processing (5)
cmd/serve.gocore/userpat/errors/errors.gocore/userpat/service.gocore/userpat/service_test.gointernal/api/v1beta1connect/user_pat.go
Pull Request Test Coverage Report for Build 23733767561Details
💛 - Coveralls |
Description:
Summary
LookupResourcesviaprojectService.ListByUserfor authoritative access checkHow it works
During Create/Update, after scope-role validation and before any mutations,
validateProjectAccessis called:projectService.ListByUser(principal, Filter{OrgID})which:LookupResourcesfor projects the user hasmemberpermission onErrProjectForbidden(generic message to user, specific project IDs logged server-side)This aligns with the UI which uses
ListProjectsByCurrentUserto populate the project dropdown — users can only select projects they have access to. The backend validation prevents direct API callers from bypassing this.Changes
ProjectServiceinterface (ListByUser),validateProjectAccessmethod, called in Create and Update flowsErrProjectForbidden— "user does not have access to one or more specified projects"ErrProjectForbiddentoCodeInvalidArgumentin Create and Update error switchescmd/serve.go— passesprojectServicetouserpat.NewService(moved creation order afterprojectService)core/userpatto.mockery.yaml, regeneratedProjectServicemockNewServicecallsTest plan
go test ./core/userpat/...— all pass including 3 new validation testsgo test ./internal/api/v1beta1connect/...— all passgo build ./...— cleaninvalid_argumentinvalid_argument