@@ -172,11 +172,11 @@ func (handler *DeploymentConfigurationRestHandlerImpl) CompareCategoryWiseConfig
172
172
}
173
173
174
174
comparisonRequestDto .UpdateUserIdInComparisonItems (userId )
175
- comparisonRequestDto . UpdateAppAndEnvNameInComparisonItems ( comparisonRequestDto . AppName , comparisonRequestDto .EnvName )
175
+ appName := comparisonRequestDto .GetAppName ( )
176
176
177
177
//RBAC START
178
178
token := r .Header .Get (common .TokenHeaderKey )
179
- object := handler .enforcerUtil .GetAppRBACName (comparisonRequestDto . AppName )
179
+ object := handler .enforcerUtil .GetAppRBACName (appName )
180
180
181
181
ok := handler .enforcerUtil .CheckAppRbacForAppOrJob (token , object , casbin .ActionGet )
182
182
if ! ok {
@@ -188,7 +188,7 @@ func (handler *DeploymentConfigurationRestHandlerImpl) CompareCategoryWiseConfig
188
188
//or not while resolving scope variable.
189
189
isSuperAdmin := handler .enforcer .Enforce (token , casbin .ResourceGlobal , casbin .ActionGet , "*" )
190
190
//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 )
192
192
193
193
ctx := util2 .SetSuperAdminInContext (r .Context (), isSuperAdmin )
194
194
res , err := handler .deploymentConfigurationService .CompareCategoryWiseConfigData (ctx , comparisonRequestDto , userHasAdminAccess )
@@ -201,3 +201,15 @@ func (handler *DeploymentConfigurationRestHandlerImpl) CompareCategoryWiseConfig
201
201
202
202
common .WriteJsonResp (w , nil , res , http .StatusOK )
203
203
}
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
+ }
0 commit comments