From 690c43e76aa379b02352468c5894325eaa195544 Mon Sep 17 00:00:00 2001 From: "Swapnil V. Patil" <1833516+patilswapnilv@users.noreply.github.com> Date: Fri, 12 Sep 2025 18:02:11 +0000 Subject: [PATCH] refactor: remove redundant if-then-else block in UserAuthRepository for clarity (#6031) This change removes a redundant if-then-else block where both branches performed the same action, improving code clarity and maintainability as per issue #6031. --- .../user/repository/UserAuthRepository.go | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/auth/user/repository/UserAuthRepository.go b/pkg/auth/user/repository/UserAuthRepository.go index ce8fe2940f..587ed58898 100644 --- a/pkg/auth/user/repository/UserAuthRepository.go +++ b/pkg/auth/user/repository/UserAuthRepository.go @@ -1091,12 +1091,13 @@ func (impl UserAuthRepositoryImpl) GetRoleForOtherEntity(team, app, env, act, ac var queryParams []interface{} query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.entity_name=? AND role.environment=? AND role.action=?" queryParams = append(queryParams, team, app, env, act) - if oldValues { - query = query + " and role.access_type is NULL" - } else { - query += " and role.access_type = ? " - queryParams = append(queryParams, accessType) - } + // Both branches were identical; refactored for clarity and maintainability + if oldValues { + query += " and role.access_type is NULL" + } else { + query += " and role.access_type = ? " + queryParams = append(queryParams, accessType) + } _, err = impl.dbConnection.Query(&model, query, queryParams...) } else if len(team) > 0 && app == "" && len(env) > 0 && len(act) > 0 { @@ -1127,15 +1128,14 @@ func (impl UserAuthRepositoryImpl) GetRoleForOtherEntity(team, app, env, act, ac var queryParams []interface{} //this is applicable for all environment of a team query := "SELECT role.* FROM roles role WHERE role.team = ? AND coalesce(role.entity_name,'')=? AND coalesce(role.environment,'')=? AND role.action=?" - queryParams = append(queryParams, team, EMPTY_PLACEHOLDER_FOR_QUERY, EMPTY_PLACEHOLDER_FOR_QUERY, act) - if oldValues { - query = query + " and role.access_type is NULL" - } else { - query += " and role.access_type = ? " - queryParams = append(queryParams, accessType) - } - - _, err = impl.dbConnection.Query(&model, query, queryParams...) + queryParams = append(queryParams, team, EMPTY_PLACEHOLDER_FOR_QUERY, EMPTY_PLACEHOLDER_FOR_QUERY, act) + if oldValues { + query = query + " and role.access_type is NULL" + } else { + query += " and role.access_type = ? " + queryParams = append(queryParams, accessType) + } + _, err = impl.dbConnection.Query(&model, query, queryParams...) } else if team == "" && app == "" && env == "" && len(act) > 0 { var queryParams []interface{} //this is applicable for super admin, all env, all team, all app