@@ -945,8 +945,9 @@ func (impl UserAuthRepositoryImpl) GetRolesForWorkflow(workflow, entityName stri
945
945
946
946
func (impl UserAuthRepositoryImpl ) GetRoleForClusterEntity (cluster , namespace , group , kind , resource , action string ) (RoleModel , error ) {
947
947
var model RoleModel
948
- query := "SELECT * FROM roles WHERE entity = ? "
949
948
var queryParams []string
949
+ query := "SELECT * FROM roles WHERE entity = ? "
950
+ queryParams = append (queryParams , bean .CLUSTER_ENTITIY )
950
951
var err error
951
952
952
953
if len (cluster ) > 0 {
@@ -985,7 +986,7 @@ func (impl UserAuthRepositoryImpl) GetRoleForClusterEntity(cluster, namespace, g
985
986
} else {
986
987
query += " and action IS NULL ;"
987
988
}
988
- _ , err = impl .dbConnection .Query (& model , query , bean . CLUSTER_ENTITIY , queryParams )
989
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
989
990
if err != nil {
990
991
impl .Logger .Errorw ("error in getting roles for clusterEntity" , "err" , err ,
991
992
bean2 .CLUSTER , cluster , "namespace" , namespace , "kind" , kind , "group" , group , "resource" , resource )
@@ -1000,6 +1001,7 @@ func (impl UserAuthRepositoryImpl) GetRoleForJobsEntity(entity, team, app, env,
1000
1001
var queryParams []string
1001
1002
if len (team ) > 0 && len (act ) > 0 {
1002
1003
query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.action=? AND role.entity=? "
1004
+ queryParams = append (queryParams , team , act , entity )
1003
1005
if len (env ) == 0 {
1004
1006
query = query + " AND role.environment is NULL"
1005
1007
} else {
@@ -1018,7 +1020,7 @@ func (impl UserAuthRepositoryImpl) GetRoleForJobsEntity(entity, team, app, env,
1018
1020
query += " AND role.workflow = ? ;"
1019
1021
queryParams = append (queryParams , workflow )
1020
1022
}
1021
- _ , err = impl .dbConnection .Query (& model , query , team , act , entity , queryParams )
1023
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
1022
1024
} else {
1023
1025
return model , nil
1024
1026
}
@@ -1034,23 +1036,25 @@ func (impl UserAuthRepositoryImpl) GetRoleForChartGroupEntity(entity, app, act,
1034
1036
if len (app ) > 0 && act == "update" {
1035
1037
var queryParams []string
1036
1038
query := "SELECT role.* FROM roles role WHERE role.entity = ? AND role.entity_name=? AND role.action=?"
1039
+ queryParams = append (queryParams , entity , app , act )
1037
1040
if len (accessType ) == 0 {
1038
1041
query = query + " and role.access_type is NULL"
1039
1042
} else {
1040
1043
query += " and role.access_type = ? "
1041
1044
queryParams = append (queryParams , accessType )
1042
1045
}
1043
- _ , err = impl .dbConnection .Query (& model , query , entity , app , act , queryParams )
1046
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
1044
1047
} else if app == "" {
1045
1048
var queryParams []string
1046
1049
query := "SELECT role.* FROM roles role WHERE role.entity = ? AND role.action=?"
1050
+ queryParams = append (queryParams , entity , act )
1047
1051
if len (accessType ) == 0 {
1048
1052
query = query + " and role.access_type is NULL"
1049
1053
} else {
1050
1054
query += " and role.access_type = ? "
1051
1055
queryParams = append (queryParams , accessType )
1052
1056
}
1053
- _ , err = impl .dbConnection .Query (& model , query , entity , act , queryParams )
1057
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
1054
1058
}
1055
1059
if err != nil {
1056
1060
impl .Logger .Errorw ("error in getting role for chart group entity" , "err" , err , "entity" , entity , "app" , app , "act" , act , "accessType" , accessType )
@@ -1064,60 +1068,65 @@ func (impl UserAuthRepositoryImpl) GetRoleForOtherEntity(team, app, env, act, ac
1064
1068
if len (team ) > 0 && len (app ) > 0 && len (env ) > 0 && len (act ) > 0 {
1065
1069
var queryParams []string
1066
1070
query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.entity_name=? AND role.environment=? AND role.action=?"
1071
+ queryParams = append (queryParams , team , app , env , act )
1067
1072
if oldValues {
1068
1073
query = query + " and role.access_type is NULL"
1069
1074
} else {
1070
1075
query += " and role.access_type = ? "
1071
1076
queryParams = append (queryParams , accessType )
1072
1077
}
1073
1078
1074
- _ , err = impl .dbConnection .Query (& model , query , team , app , env , act , queryParams )
1079
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
1075
1080
} else if len (team ) > 0 && app == "" && len (env ) > 0 && len (act ) > 0 {
1076
1081
var queryParams []string
1077
1082
query := "SELECT role.* FROM roles role WHERE role.team=? AND coalesce(role.entity_name,'')=? AND role.environment=? AND role.action=?"
1083
+ queryParams = append (queryParams , team , EMPTY_PLACEHOLDER_FOR_QUERY , env , act )
1078
1084
if oldValues {
1079
1085
query = query + " and role.access_type is NULL"
1080
1086
} else {
1081
1087
query += " and role.access_type = ? "
1082
1088
queryParams = append (queryParams , accessType )
1083
1089
}
1084
- _ , err = impl .dbConnection .Query (& model , query , team , EMPTY_PLACEHOLDER_FOR_QUERY , env , act , queryParams )
1090
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
1085
1091
} else if len (team ) > 0 && len (app ) > 0 && env == "" && len (act ) > 0 {
1086
1092
var queryParams []string
1087
1093
//this is applicable for all environment of a team
1088
1094
query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.entity_name=? AND coalesce(role.environment,'')=? AND role.action=?"
1095
+ queryParams = append (queryParams , team , app , EMPTY_PLACEHOLDER_FOR_QUERY , act )
1089
1096
if oldValues {
1090
1097
query = query + " and role.access_type is NULL"
1091
1098
} else {
1092
1099
query += " and role.access_type = ? "
1093
1100
queryParams = append (queryParams , accessType )
1094
1101
}
1095
1102
1096
- _ , err = impl .dbConnection .Query (& model , query , team , app , EMPTY_PLACEHOLDER_FOR_QUERY , act , queryParams )
1103
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
1097
1104
} else if len (team ) > 0 && app == "" && env == "" && len (act ) > 0 {
1098
1105
var queryParams []string
1099
1106
//this is applicable for all environment of a team
1100
1107
query := "SELECT role.* FROM roles role WHERE role.team = ? AND coalesce(role.entity_name,'')=? AND coalesce(role.environment,'')=? AND role.action=?"
1108
+ queryParams = append (queryParams , team , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , act )
1101
1109
if oldValues {
1102
1110
query = query + " and role.access_type is NULL"
1103
1111
} else {
1104
1112
query += " and role.access_type = ? "
1105
1113
queryParams = append (queryParams , accessType )
1106
1114
}
1107
1115
1108
- _ , err = impl .dbConnection .Query (& model , query , team , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , act , queryParams )
1116
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
1109
1117
} else if team == "" && app == "" && env == "" && len (act ) > 0 {
1110
1118
var queryParams []string
1111
1119
//this is applicable for super admin, all env, all team, all app
1112
1120
query := "SELECT role.* FROM roles role WHERE coalesce(role.team,'') = ? AND coalesce(role.entity_name,'')=? AND coalesce(role.environment,'')=? AND role.action=?"
1121
+ queryParams = append (queryParams , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , act )
1113
1122
if len (accessType ) == 0 {
1114
1123
query = query + " and role.access_type is NULL"
1115
1124
} else {
1116
1125
query += " and role.access_type = ? "
1117
1126
queryParams = append (queryParams , accessType )
1118
1127
1119
1128
}
1120
- _ , err = impl .dbConnection .Query (& model , query , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , act , queryParams )
1129
+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
1121
1130
} else if team == "" && app == "" && env == "" && act == "" {
1122
1131
return model , nil
1123
1132
} else {
0 commit comments