Skip to content

Commit

Permalink
Cherrypick #2936 #2957 (#2958)
Browse files Browse the repository at this point in the history
* fix panic bug & minor permission problem

Signed-off-by: Min Min <[email protected]>

* users api debug and edge case fix

Signed-off-by: Min Min <[email protected]>

---------

Signed-off-by: Min Min <[email protected]>
Co-authored-by: Min Min <[email protected]>
  • Loading branch information
jamsman94 and Min Min authored Aug 11, 2023
1 parent a30a6d6 commit a454c3c
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 72 deletions.
12 changes: 3 additions & 9 deletions pkg/microservice/aslan/core/build/handler/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ func ListBuildModules(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
// first check if the user is projectAdmin
if projectAuthInfo.IsProjectAdmin {
permitted = true
Expand Down Expand Up @@ -130,14 +128,10 @@ func ListBuildModulesByServiceModule(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if ctx.Resources.SystemActions.Template.Create ||
} else if ctx.Resources.SystemActions.Template.Create ||
ctx.Resources.SystemActions.Template.Edit {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
// first check if the user is projectAdmin
if projectAuthInfo.IsProjectAdmin {
permitted = true
Expand Down
8 changes: 2 additions & 6 deletions pkg/microservice/aslan/core/build/handler/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ func ListDeployTarget(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
// first check if the user is projectAdmin
if projectAuthInfo.IsProjectAdmin {
permitted = true
Expand Down Expand Up @@ -94,9 +92,7 @@ func ListBuildModulesForProduct(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
if projectedAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/microservice/aslan/core/environment/handler/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ func ListProductionConfigMaps(c *gin.Context) {
}
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.View {
ctx.UnAuthorized = true
return
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionView)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
}

Expand Down
24 changes: 9 additions & 15 deletions pkg/microservice/aslan/core/environment/handler/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ func ListProducts(c *gin.Context) {
projectInfo.Env.View {
hasPermission = true
}
} else {
permittedEnv, _ := internalhandler.ListCollaborationEnvironmentsPermission(ctx.UserID, projectName)
if permittedEnv != nil && len(permittedEnv.ReadEnvList) > 0 {
hasPermission = true
envFilter = permittedEnv.ReadEnvList
}
}

permittedEnv, _ := internalhandler.ListCollaborationEnvironmentsPermission(ctx.UserID, projectName)
if !hasPermission && permittedEnv != nil && len(permittedEnv.ReadEnvList) > 0 {
hasPermission = true
envFilter = permittedEnv.ReadEnvList
}

if !hasPermission {
Expand Down Expand Up @@ -1511,9 +1511,7 @@ func updateMultiK8sEnv(c *gin.Context, request *service.UpdateEnvRequest, produc

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[request.ProjectName]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[request.ProjectName]; ok {
if projectAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down Expand Up @@ -1567,9 +1565,7 @@ func updateMultiHelmEnv(c *gin.Context, request *service.UpdateEnvRequest, produ

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[request.ProjectName]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[request.ProjectName]; ok {
if projectAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down Expand Up @@ -1625,9 +1621,7 @@ func updateMultiHelmChartEnv(c *gin.Context, request *service.UpdateEnvRequest,

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[request.ProjectName]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[request.ProjectName]; ok {
if projectAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/microservice/aslan/core/environment/handler/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ func UpdateDeploymentContainerImage(c *gin.Context) {
permitted := false
if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[args.ProductName]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[args.ProductName]; ok {
if projectAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down Expand Up @@ -189,9 +187,7 @@ func UpdateProductionDeploymentContainerImage(c *gin.Context) {
permitted := false
if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[args.ProductName]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[args.ProductName]; ok {
if projectAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/microservice/aslan/core/environment/handler/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ func ListProductionIngresses(c *gin.Context) {
}
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.View {
ctx.UnAuthorized = true
return
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionView)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/microservice/aslan/core/environment/handler/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ func ListProductionPvcs(c *gin.Context) {
}
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.View {
ctx.UnAuthorized = true
return
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.EnvActionView)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/microservice/aslan/core/environment/handler/renderset.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ func GetGlobalVariables(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
if projectedAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/microservice/aslan/core/environment/handler/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ func ListProductionSecrets(c *gin.Context) {
}
if !ctx.Resources.ProjectAuthInfo[projectKey].IsProjectAdmin &&
!ctx.Resources.ProjectAuthInfo[projectKey].ProductionEnv.View {
ctx.UnAuthorized = true
return
permitted, err := internalhandler.GetCollaborationModePermission(ctx.UserID, projectKey, types.ResourceTypeEnvironment, envName, types.ProductionEnvActionView)
if err != nil || !permitted {
ctx.UnAuthorized = true
return
}
}
}

Expand Down
8 changes: 2 additions & 6 deletions pkg/microservice/aslan/core/environment/handler/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ func ListSvcsInEnv(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
if projectedAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down Expand Up @@ -160,9 +158,7 @@ func GetProductionService(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
if projectedAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/microservice/aslan/core/project/handler/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,7 @@ func GetGlobalVariables(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectedAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
if projectedAuthInfo.IsProjectAdmin {
permitted = true
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/microservice/aslan/core/service/handler/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ func GetServiceTemplateOption(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectName]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectName]; ok {
// first check if the user is projectAdmin
if projectAuthInfo.IsProjectAdmin {
permitted = true
Expand Down
4 changes: 1 addition & 3 deletions pkg/microservice/aslan/core/workflow/handler/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ func AutoCreateWorkflow(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
// first check if the user is projectAdmin
if projectAuthInfo.IsProjectAdmin {
permitted = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ func ListScanningModule(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
// first check if the user is projectAdmin
if projectAuthInfo.IsProjectAdmin {
permitted = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ func GetTestModule(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
} else if projectAuthInfo, ok := ctx.Resources.ProjectAuthInfo[projectKey]; ok {
// first check if the user is projectAdmin
if projectAuthInfo.IsProjectAdmin {
permitted = true
Expand Down
4 changes: 1 addition & 3 deletions pkg/microservice/picket/core/filter/handler/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ func CreateProject(c *gin.Context) {

if ctx.Resources.IsSystemAdmin {
permitted = true
}

if ctx.Resources.SystemActions.Project.Create {
} else if ctx.Resources.SystemActions.Project.Create {
permitted = true
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/shared/client/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ type usersResp struct {
}

type SearchArgs struct {
UIDs []string `json:"uids"`
UIDs []string `json:"uids"`
PerPage int `json:"per_page,omitempty"`
Page int `json:"page,omitempty"`
}

func (c *Client) ListUsers(args *SearchArgs) ([]*User, error) {
Expand Down

0 comments on commit a454c3c

Please sign in to comment.