@@ -945,8 +945,9 @@ func (impl UserAuthRepositoryImpl) GetRolesForWorkflow(workflow, entityName stri
945945
946946func (impl UserAuthRepositoryImpl ) GetRoleForClusterEntity (cluster , namespace , group , kind , resource , action string ) (RoleModel , error ) {
947947 var model RoleModel
948- query := "SELECT * FROM roles WHERE entity = ? "
949948 var queryParams []string
949+ query := "SELECT * FROM roles WHERE entity = ? "
950+ queryParams = append (queryParams , bean .CLUSTER_ENTITIY )
950951 var err error
951952
952953 if len (cluster ) > 0 {
@@ -985,7 +986,7 @@ func (impl UserAuthRepositoryImpl) GetRoleForClusterEntity(cluster, namespace, g
985986 } else {
986987 query += " and action IS NULL ;"
987988 }
988- _ , err = impl .dbConnection .Query (& model , query , bean . CLUSTER_ENTITIY , queryParams )
989+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
989990 if err != nil {
990991 impl .Logger .Errorw ("error in getting roles for clusterEntity" , "err" , err ,
991992 bean2 .CLUSTER , cluster , "namespace" , namespace , "kind" , kind , "group" , group , "resource" , resource )
@@ -1000,6 +1001,7 @@ func (impl UserAuthRepositoryImpl) GetRoleForJobsEntity(entity, team, app, env,
10001001 var queryParams []string
10011002 if len (team ) > 0 && len (act ) > 0 {
10021003 query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.action=? AND role.entity=? "
1004+ queryParams = append (queryParams , team , act , entity )
10031005 if len (env ) == 0 {
10041006 query = query + " AND role.environment is NULL"
10051007 } else {
@@ -1018,7 +1020,7 @@ func (impl UserAuthRepositoryImpl) GetRoleForJobsEntity(entity, team, app, env,
10181020 query += " AND role.workflow = ? ;"
10191021 queryParams = append (queryParams , workflow )
10201022 }
1021- _ , err = impl .dbConnection .Query (& model , query , team , act , entity , queryParams )
1023+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
10221024 } else {
10231025 return model , nil
10241026 }
@@ -1034,23 +1036,25 @@ func (impl UserAuthRepositoryImpl) GetRoleForChartGroupEntity(entity, app, act,
10341036 if len (app ) > 0 && act == "update" {
10351037 var queryParams []string
10361038 query := "SELECT role.* FROM roles role WHERE role.entity = ? AND role.entity_name=? AND role.action=?"
1039+ queryParams = append (queryParams , entity , app , act )
10371040 if len (accessType ) == 0 {
10381041 query = query + " and role.access_type is NULL"
10391042 } else {
10401043 query += " and role.access_type = ? "
10411044 queryParams = append (queryParams , accessType )
10421045 }
1043- _ , err = impl .dbConnection .Query (& model , query , entity , app , act , queryParams )
1046+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
10441047 } else if app == "" {
10451048 var queryParams []string
10461049 query := "SELECT role.* FROM roles role WHERE role.entity = ? AND role.action=?"
1050+ queryParams = append (queryParams , entity , act )
10471051 if len (accessType ) == 0 {
10481052 query = query + " and role.access_type is NULL"
10491053 } else {
10501054 query += " and role.access_type = ? "
10511055 queryParams = append (queryParams , accessType )
10521056 }
1053- _ , err = impl .dbConnection .Query (& model , query , entity , act , queryParams )
1057+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
10541058 }
10551059 if err != nil {
10561060 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
10641068 if len (team ) > 0 && len (app ) > 0 && len (env ) > 0 && len (act ) > 0 {
10651069 var queryParams []string
10661070 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 )
10671072 if oldValues {
10681073 query = query + " and role.access_type is NULL"
10691074 } else {
10701075 query += " and role.access_type = ? "
10711076 queryParams = append (queryParams , accessType )
10721077 }
10731078
1074- _ , err = impl .dbConnection .Query (& model , query , team , app , env , act , queryParams )
1079+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
10751080 } else if len (team ) > 0 && app == "" && len (env ) > 0 && len (act ) > 0 {
10761081 var queryParams []string
10771082 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 )
10781084 if oldValues {
10791085 query = query + " and role.access_type is NULL"
10801086 } else {
10811087 query += " and role.access_type = ? "
10821088 queryParams = append (queryParams , accessType )
10831089 }
1084- _ , err = impl .dbConnection .Query (& model , query , team , EMPTY_PLACEHOLDER_FOR_QUERY , env , act , queryParams )
1090+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
10851091 } else if len (team ) > 0 && len (app ) > 0 && env == "" && len (act ) > 0 {
10861092 var queryParams []string
10871093 //this is applicable for all environment of a team
10881094 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 )
10891096 if oldValues {
10901097 query = query + " and role.access_type is NULL"
10911098 } else {
10921099 query += " and role.access_type = ? "
10931100 queryParams = append (queryParams , accessType )
10941101 }
10951102
1096- _ , err = impl .dbConnection .Query (& model , query , team , app , EMPTY_PLACEHOLDER_FOR_QUERY , act , queryParams )
1103+ _ , err = impl .dbConnection .Query (& model , query , queryParams )
10971104 } else if len (team ) > 0 && app == "" && env == "" && len (act ) > 0 {
10981105 var queryParams []string
10991106 //this is applicable for all environment of a team
11001107 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 )
11011109 if oldValues {
11021110 query = query + " and role.access_type is NULL"
11031111 } else {
11041112 query += " and role.access_type = ? "
11051113 queryParams = append (queryParams , accessType )
11061114 }
11071115
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 )
11091117 } else if team == "" && app == "" && env == "" && len (act ) > 0 {
11101118 var queryParams []string
11111119 //this is applicable for super admin, all env, all team, all app
11121120 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 )
11131122 if len (accessType ) == 0 {
11141123 query = query + " and role.access_type is NULL"
11151124 } else {
11161125 query += " and role.access_type = ? "
11171126 queryParams = append (queryParams , accessType )
11181127
11191128 }
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 )
11211130 } else if team == "" && app == "" && env == "" && act == "" {
11221131 return model , nil
11231132 } else {
0 commit comments