Skip to content

Commit 690c43e

Browse files
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.
1 parent e95b7a4 commit 690c43e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

pkg/auth/user/repository/UserAuthRepository.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,12 +1091,13 @@ func (impl UserAuthRepositoryImpl) GetRoleForOtherEntity(team, app, env, act, ac
10911091
var queryParams []interface{}
10921092
query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.entity_name=? AND role.environment=? AND role.action=?"
10931093
queryParams = append(queryParams, team, app, env, act)
1094-
if oldValues {
1095-
query = query + " and role.access_type is NULL"
1096-
} else {
1097-
query += " and role.access_type = ? "
1098-
queryParams = append(queryParams, accessType)
1099-
}
1094+
// Both branches were identical; refactored for clarity and maintainability
1095+
if oldValues {
1096+
query += " and role.access_type is NULL"
1097+
} else {
1098+
query += " and role.access_type = ? "
1099+
queryParams = append(queryParams, accessType)
1100+
}
11001101

11011102
_, err = impl.dbConnection.Query(&model, query, queryParams...)
11021103
} 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
11271128
var queryParams []interface{}
11281129
//this is applicable for all environment of a team
11291130
query := "SELECT role.* FROM roles role WHERE role.team = ? AND coalesce(role.entity_name,'')=? AND coalesce(role.environment,'')=? AND role.action=?"
1130-
queryParams = append(queryParams, team, EMPTY_PLACEHOLDER_FOR_QUERY, EMPTY_PLACEHOLDER_FOR_QUERY, act)
1131-
if oldValues {
1132-
query = query + " and role.access_type is NULL"
1133-
} else {
1134-
query += " and role.access_type = ? "
1135-
queryParams = append(queryParams, accessType)
1136-
}
1137-
1138-
_, err = impl.dbConnection.Query(&model, query, queryParams...)
1131+
queryParams = append(queryParams, team, EMPTY_PLACEHOLDER_FOR_QUERY, EMPTY_PLACEHOLDER_FOR_QUERY, act)
1132+
if oldValues {
1133+
query = query + " and role.access_type is NULL"
1134+
} else {
1135+
query += " and role.access_type = ? "
1136+
queryParams = append(queryParams, accessType)
1137+
}
1138+
_, err = impl.dbConnection.Query(&model, query, queryParams...)
11391139
} else if team == "" && app == "" && env == "" && len(act) > 0 {
11401140
var queryParams []interface{}
11411141
//this is applicable for super admin, all env, all team, all app

0 commit comments

Comments
 (0)