Skip to content

Commit 740c3ae

Browse files
committed
envName and appName in comparisonItems
1 parent 7a2ca72 commit 740c3ae

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

api/restHandler/app/configDiff/DeploymentConfigurationRestHandler.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ func (handler *DeploymentConfigurationRestHandlerImpl) CompareCategoryWiseConfig
172172
}
173173

174174
comparisonRequestDto.UpdateUserIdInComparisonItems(userId)
175-
comparisonRequestDto.UpdateAppAndEnvNameInComparisonItems(comparisonRequestDto.AppName, comparisonRequestDto.EnvName)
175+
appName := comparisonRequestDto.GetAppName()
176176

177177
//RBAC START
178178
token := r.Header.Get(common.TokenHeaderKey)
179-
object := handler.enforcerUtil.GetAppRBACName(comparisonRequestDto.AppName)
179+
object := handler.enforcerUtil.GetAppRBACName(appName)
180180

181181
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
182182
if !ok {
@@ -188,7 +188,7 @@ func (handler *DeploymentConfigurationRestHandlerImpl) CompareCategoryWiseConfig
188188
//or not while resolving scope variable.
189189
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*")
190190
//userHasAdminAccess is required to mask secrets in the response after scope resolution.
191-
userHasAdminAccess := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, object)
191+
userHasAdminAccess := handler.checkIfUserHasAdminAccessForLeastPrivilegeEnv(token, comparisonRequestDto)
192192

193193
ctx := util2.SetSuperAdminInContext(r.Context(), isSuperAdmin)
194194
res, err := handler.deploymentConfigurationService.CompareCategoryWiseConfigData(ctx, comparisonRequestDto, userHasAdminAccess)
@@ -201,3 +201,15 @@ func (handler *DeploymentConfigurationRestHandlerImpl) CompareCategoryWiseConfig
201201

202202
common.WriteJsonResp(w, nil, res, http.StatusOK)
203203
}
204+
205+
// checkIfUserHasAdminAccessForLeastPrivilegeEnv computes if a user has admin access or not for all env,
206+
// if a user is non admin for at least one env then return false.
207+
func (handler *DeploymentConfigurationRestHandlerImpl) checkIfUserHasAdminAccessForLeastPrivilegeEnv(token string, comparisonRequestDto bean.ComparisonRequestDto) bool {
208+
for _, item := range comparisonRequestDto.ComparisonItems {
209+
userHadAdminAccess := handler.enforcer.Enforce(token, casbin.ResourceEnvironment, casbin.ActionGet, item.EnvName)
210+
if !userHadAdminAccess {
211+
return false
212+
}
213+
}
214+
return true
215+
}

pkg/configDiff/bean/bean.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ type ComparisonItemRequestDto struct {
246246
}
247247

248248
type ComparisonRequestDto struct {
249-
AppName string `json:"appName"`
250-
EnvName string `json:"envName"`
251249
ComparisonItems []*ComparisonItemRequestDto `json:"comparisonItems"` // comparisonItems contains array of objects that a user wants to compare
252250
}
253251

@@ -258,12 +256,11 @@ func (r *ComparisonRequestDto) UpdateUserIdInComparisonItems(userId int32) {
258256
}
259257
}
260258

261-
func (r *ComparisonRequestDto) UpdateAppAndEnvNameInComparisonItems(appName, envName string) {
259+
func (r *ComparisonRequestDto) GetAppName() string {
262260
for _, item := range r.ComparisonItems {
263-
item.EnvName = envName
264-
item.AppName = appName
265-
261+
return item.AppName
266262
}
263+
return ""
267264
}
268265

269266
type ComparisonResponseDto struct {

0 commit comments

Comments
 (0)