@@ -192,45 +192,37 @@ class RoleBaseAccessFallbackController implements RoleBaseAccessController {
192192 return { ok : false , status : 401 , error : "Invalid API key" } ;
193193 }
194194
195- // PREVIEW env requires a branch header; pivot to the child env so
196- // downstream code operates on the branch (its own id, but the
197- // parent's apiKey/orgMember/organization/project — exactly what
198- // findEnvironmentByApiKey does for the legacy auth path).
199195 if ( env . type === "PREVIEW" && ! branchName ) {
200196 return {
201197 ok : false ,
202198 status : 401 ,
203199 error : "x-trigger-branch header required for preview env" ,
204200 } ;
205201 }
206- // The "default" sentinel is DEVELOPMENT-only: it maps to the dev root env
207- // (which carries no branch), so we skip the pivot there. For PREVIEW,
208- // "default" is an ordinary branch name and must still pivot to its child.
209- const isDevRootSentinel = env . type === "DEVELOPMENT" && isDefaultDevBranch ( branchName ) ;
210- if ( branchName !== null && ! isDevRootSentinel ) {
211- if ( env . type !== "PREVIEW" && env . type !== "DEVELOPMENT" ) {
212- return {
213- ok : false ,
214- status : 401 ,
215- error : "x-trigger-branch header can only be used with preview and dev envs" ,
202+
203+ if ( env . type === "PREVIEW" || env . type === "DEVELOPMENT" ) {
204+ // The "default" sentinel is DEVELOPMENT-only: it maps to the dev root env
205+ // (which carries no branch), so we skip the pivot there. For PREVIEW,
206+ // "default" is an ordinary branch name and must still pivot to its child.
207+ const isDevRootSentinel = env . type === "DEVELOPMENT" && isDefaultDevBranch ( branchName ) ;
208+ if ( branchName !== null && ! isDevRootSentinel ) {
209+ const child = env . childEnvironments ?. [ 0 ] ;
210+ if ( ! child ) {
211+ return { ok : false , status : 401 , error : "No matching branch env" } ;
212+ }
213+ // Pivot to the child env: child's id/type/branchName, parent's
214+ // apiKey/orgMember/organization/project. parentEnvironment is set
215+ // explicitly here so the slim shape stays internally consistent.
216+ env = {
217+ ...child ,
218+ apiKey : env . apiKey ,
219+ orgMember : env . orgMember ,
220+ organization : env . organization ,
221+ project : env . project ,
222+ parentEnvironment : { id : env . id , apiKey : env . apiKey } ,
223+ childEnvironments : [ ] ,
216224 } ;
217225 }
218- const child = env . childEnvironments ?. [ 0 ] ;
219- if ( ! child ) {
220- return { ok : false , status : 401 , error : "No matching branch env" } ;
221- }
222- // Pivot to the child env: child's id/type/branchName, parent's
223- // apiKey/orgMember/organization/project. parentEnvironment is set
224- // explicitly here so the slim shape stays internally consistent.
225- env = {
226- ...child ,
227- apiKey : env . apiKey ,
228- orgMember : env . orgMember ,
229- organization : env . organization ,
230- project : env . project ,
231- parentEnvironment : { id : env . id , apiKey : env . apiKey } ,
232- childEnvironments : [ ] ,
233- } ;
234226 }
235227
236228 const subject : RbacSubject = {
0 commit comments