Skip to content

Commit

Permalink
fix sae env auth bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zhao <[email protected]>
  • Loading branch information
PetrusZ committed Dec 3, 2024
1 parent 9e3ea14 commit 165e3ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions pkg/microservice/aslan/core/environment/handler/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2934,13 +2934,13 @@ func DeleteSAEEnv(c *gin.Context) {

if production {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.EditConfig {
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.Delete {
ctx.UnAuthorized = true
return
}
} else {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].Env.EditConfig {
!ctx.Resources.ProjectAuthInfo[projectKey].Env.Delete {
ctx.UnAuthorized = true
return
}
Expand Down Expand Up @@ -3330,17 +3330,17 @@ func RollbackSAEApp(c *gin.Context) {

if production {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.EditConfig {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionEditConfig)
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
} else {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].Env.EditConfig {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionEditConfig)
!ctx.Resources.ProjectAuthInfo[projectKey].Env.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
Expand Down Expand Up @@ -3713,17 +3713,17 @@ func AbortSAEChangeOrder(c *gin.Context) {

if production {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.EditConfig {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionEditConfig)
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
} else {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].Env.EditConfig {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionEditConfig)
!ctx.Resources.ProjectAuthInfo[projectKey].Env.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
Expand Down Expand Up @@ -3769,17 +3769,17 @@ func RollbackSAEChangeOrder(c *gin.Context) {

if production {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.EditConfig {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionEditConfig)
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
} else {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].Env.EditConfig {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionEditConfig)
!ctx.Resources.ProjectAuthInfo[projectKey].Env.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
Expand Down Expand Up @@ -3825,17 +3825,17 @@ func ConfirmSAEPipelineBatch(c *gin.Context) {

if production {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.EditConfig {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionEditConfig)
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
} else {
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].Env.EditConfig {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionEditConfig)
!ctx.Resources.ProjectAuthInfo[projectKey].Env.ManagePods {
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionManagePod)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/microservice/aslan/core/environment/handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ func (*Router) Inject(router *gin.RouterGroup) {
environments.GET("sae/namespace", ListSAENamespaces)
environments.POST("sae/:name/app", AddSAEServiceToEnv)
environments.PUT("sae/:name/app", DeleteSAEServiceFromEnv)
environments.POST("sae/:name/app/:appID/serviceBind", BindSAEAppToService)
environments.GET("sae/:name/app/:appID/versions", ListSAEAppVersion)
environments.POST("sae/:name/app/:appID/restart", RestartSAEApp)
environments.POST("sae/:name/app/:appID/serviceBind", BindSAEAppToService)
environments.POST("sae/:name/app/:appID/rescale", RescaleSAEApp)
environments.POST("sae/:name/app/:appID/rollback", RollbackSAEApp)
environments.GET("sae/:name/app/:appID/instance", ListSAEAppInstances)
Expand Down

0 comments on commit 165e3ac

Please sign in to comment.