@@ -560,7 +560,7 @@ export const removeRouteFromEnvironment: ResolverFn = async (
560560 environment,
561561 }
562562 } ,
563- { sqlClientPool, hasPermission, userActivityLogger }
563+ { sqlClientPool, hasPermission, userActivityLogger, adminScopes }
564564) => {
565565 const projectId = await projectHelpers ( sqlClientPool ) . getProjectIdByName ( project )
566566 const projectData = await projectHelpers ( sqlClientPool ) . getProjectById ( projectId )
@@ -570,17 +570,28 @@ export const removeRouteFromEnvironment: ResolverFn = async (
570570 const env = await environmentHelpers ( sqlClientPool ) . getEnvironmentByNameAndProject ( environment , projectId )
571571 const environmentData = env [ 0 ]
572572
573+ const existsProject = await query (
574+ sqlClientPool ,
575+ Sql . selectRouteByDomainAndProjectID ( domain , projectId )
576+ )
577+ if ( existsProject . length == 0 ) {
578+ throw Error ( `Route doesn't exist on this project` )
579+ }
580+ const route = existsProject [ 0 ]
581+
582+ if ( ! adminScopes . platformOwner ) {
583+ if ( route . source . toLowerCase ( ) === RouteSource . YAML ) {
584+ throw Error ( `This route cannot be removed from the environment as it is managed by a lagoon.yml file` )
585+ }
586+ if ( route . source . toLowerCase ( ) === RouteSource . AUTOGENERATED ) {
587+ throw Error ( `Cannot remove autogenerated routes from an environment using this endpoint` )
588+ }
589+ }
590+
573591 const routeId = await Helpers ( sqlClientPool ) . removeRouteFromEnvironment ( domain , environmentData . id )
574592
575593 const ret = await query ( sqlClientPool , Sql . selectRouteByID ( routeId ) ) ;
576- const route = ret [ 0 ] ;
577-
578- if ( route . source . toLowerCase ( ) === RouteSource . YAML ) {
579- throw Error ( `This route cannot be removed from the environment as it is managed by a lagoon.yml file` )
580- }
581- if ( route . source . toLowerCase ( ) === RouteSource . AUTOGENERATED ) {
582- throw Error ( `Cannot remove autogenerated routes from an environment using this endpoint` )
583- }
594+ const returnRoute = ret [ 0 ] ;
584595
585596 const auditLog : AuditLog = {
586597 resource : {
@@ -599,18 +610,18 @@ export const removeRouteFromEnvironment: ResolverFn = async (
599610 if ( projectData . organization ) {
600611 auditLog . organizationId = projectData . organization ;
601612 }
602- userActivityLogger ( `User removed route '${ route . domain } ' from environment '${ environmentData . name } '` , {
613+ userActivityLogger ( `User removed route '${ returnRoute . domain } ' from environment '${ environmentData . name } '` , {
603614 project : '' ,
604615 event : 'api:removeRouteFromEnvironment' ,
605616 payload : {
606617 project : projectData . id ,
607618 environment : environmentData . id ,
608- route : route . id ,
619+ route : returnRoute . id ,
609620 ...auditLog
610621 }
611622 } ) ;
612623
613- return route ;
624+ return returnRoute ;
614625}
615626
616627/*
0 commit comments