@@ -18,6 +18,7 @@ package rbac
1818
1919import (
2020 "fmt"
21+ "github.com/devtron-labs/devtron/api/helm-app/service/bean"
2122 "github.com/devtron-labs/devtron/internal/sql/repository/app"
2223 repository2 "github.com/devtron-labs/devtron/pkg/appStore/installedApp/repository"
2324 "github.com/devtron-labs/devtron/pkg/cluster/repository"
@@ -78,8 +79,7 @@ func (impl EnforcerUtilHelmImpl) GetHelmObjectByTeamIdAndClusterId(teamId int, c
7879
7980func (impl EnforcerUtilHelmImpl ) GetHelmObjectByClusterIdNamespaceAndAppName (clusterId int , namespace string , appName string ) (string , string ) {
8081
81- installedApp , installedAppErr := impl .InstalledAppRepository .GetInstalledApplicationByClusterIdAndNamespaceAndAppName (clusterId , namespace , appName )
82-
82+ installedApp , installedAppErr := impl .getInstalledApp (clusterId , namespace , appName )
8383 if installedAppErr != nil && installedAppErr != pg .ErrNoRows {
8484 impl .logger .Errorw ("error on fetching data for rbac object from installed app repository" , "err" , installedAppErr )
8585 return "" , ""
@@ -93,19 +93,18 @@ func (impl EnforcerUtilHelmImpl) GetHelmObjectByClusterIdNamespaceAndAppName(clu
9393
9494 if installedApp == nil || installedAppErr == pg .ErrNoRows {
9595 // for cli apps which are not yet linked
96-
97- app , err := impl .appRepository .FindAppAndProjectByAppName (appName )
96+ app , err := impl .getAppObject (clusterId , namespace , appName )
9897 if err != nil && err != pg .ErrNoRows {
9998 impl .logger .Errorw ("error in fetching app details" , "err" , err )
10099 return "" , ""
101100 }
102101
103102 if app .TeamId == 0 {
104103 // case if project is not assigned to cli app
105- return fmt .Sprintf ("%s/%s__%s/%s" , team .UNASSIGNED_PROJECT , cluster .ClusterName , namespace , appName ), ""
104+ return fmt .Sprintf ("%s/%s__%s/%s" , team .UNASSIGNED_PROJECT , cluster .ClusterName , namespace , appName ), fmt . Sprintf ( "%s/%s/%s" , team . UNASSIGNED_PROJECT , namespace , appName )
106105 } else {
107106 // case if project is assigned
108- return fmt .Sprintf ("%s/%s__%s/%s" , app .Team .Name , cluster .ClusterName , namespace , appName ), ""
107+ return fmt .Sprintf ("%s/%s__%s/%s" , app .Team .Name , cluster .ClusterName , namespace , appName ), fmt . Sprintf ( "%s/%s/%s" , app . Team . Name , namespace , appName )
109108 }
110109
111110 }
@@ -118,7 +117,7 @@ func (impl EnforcerUtilHelmImpl) GetHelmObjectByClusterIdNamespaceAndAppName(clu
118117 } else {
119118 if installedApp .EnvironmentId == 0 {
120119 // for apps in EA mode, initally env can be 0.
121- return fmt .Sprintf ("%s/%s__%s/%s" , installedApp .App .Team .Name , cluster .ClusterName , namespace , appName ), ""
120+ return fmt .Sprintf ("%s/%s__%s/%s" , installedApp .App .Team .Name , cluster .ClusterName , namespace , appName ), fmt . Sprintf ( "%s/%s/%s" , installedApp . App . Team . Name , namespace , appName )
122121 }
123122 // for apps which are assigned to a project and have env ID
124123 rbacOne := fmt .Sprintf ("%s/%s/%s" , installedApp .App .Team .Name , installedApp .Environment .EnvironmentIdentifier , appName )
@@ -131,6 +130,37 @@ func (impl EnforcerUtilHelmImpl) GetHelmObjectByClusterIdNamespaceAndAppName(clu
131130
132131}
133132
133+ func (impl EnforcerUtilHelmImpl ) getAppObject (clusterId int , namespace string , appName string ) (* app.App , error ) {
134+ appIdentifier := & bean.AppIdentifier {
135+ ClusterId : clusterId ,
136+ Namespace : namespace ,
137+ ReleaseName : appName ,
138+ }
139+ appNameIdentifier := appIdentifier .GetUniqueAppNameIdentifier ()
140+ appObj , err := impl .appRepository .FindAppAndProjectByAppName (appNameIdentifier )
141+ if appObj == nil || err == pg .ErrNoRows {
142+ impl .logger .Warnw ("appObj not found, going to find app using display name " , "appIdentifier" , appNameIdentifier , "appName" , appName )
143+ appObj , err = impl .appRepository .FindAppAndProjectByAppName (appName )
144+ }
145+ return appObj , err
146+ }
147+
148+ func (impl EnforcerUtilHelmImpl ) getInstalledApp (clusterId int , namespace string , appName string ) (* repository2.InstalledApps , error ) {
149+ appIdentifier := & bean.AppIdentifier {
150+ ClusterId : clusterId ,
151+ Namespace : namespace ,
152+ ReleaseName : appName ,
153+ }
154+ appNameIdentifier := appIdentifier .GetUniqueAppNameIdentifier ()
155+ //installedApp, installedAppErr := impl.InstalledAppRepository.GetInstalledApplicationByClusterIdAndNamespaceAndAppName(clusterId, namespace, appNameIdentifier)
156+ //if installedApp == nil || installedAppErr == pg.ErrNoRows {
157+ // impl.logger.Warnw("installed app not found, going to find app using display name ", "appIdentifier", appNameIdentifier, "appName", appName)
158+ // installedApp, installedAppErr = impl.InstalledAppRepository.GetInstalledApplicationByClusterIdAndNamespaceAndAppName(clusterId, namespace, appName)
159+ //}
160+ return impl .InstalledAppRepository .GetInstalledApplicationByClusterIdAndNamespaceAndAppIdentifier (clusterId , namespace , appNameIdentifier , appName )
161+ //return installedApp, installedAppErr
162+ }
163+
134164func (impl EnforcerUtilHelmImpl ) GetAppRBACNameByInstalledAppId (installedAppVersionId int ) (string , string ) {
135165
136166 InstalledApp , err := impl .InstalledAppRepository .GetInstalledApp (installedAppVersionId )
0 commit comments