Skip to content

Commit 353cac8

Browse files
committed
oss sync with ent
1 parent d1aff8e commit 353cac8

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

api/restHandler/app/appList/AppListingRestHandler.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
util4 "github.com/devtron-labs/devtron/pkg/appStore/util"
3939
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
4040
"github.com/devtron-labs/devtron/pkg/auth/user"
41+
"github.com/devtron-labs/devtron/pkg/auth/user/bean"
4142
bean5 "github.com/devtron-labs/devtron/pkg/cluster/bean"
4243
bean2 "github.com/devtron-labs/devtron/pkg/cluster/environment/bean"
4344
common2 "github.com/devtron-labs/devtron/pkg/deployment/common"
@@ -49,6 +50,7 @@ import (
4950
k8sApplication "github.com/devtron-labs/devtron/pkg/k8s/application"
5051
"github.com/devtron-labs/devtron/pkg/pipeline"
5152
bean6 "github.com/devtron-labs/devtron/pkg/team/bean"
53+
util2 "github.com/devtron-labs/devtron/util"
5254
"github.com/devtron-labs/devtron/util/rbac"
5355
"github.com/go-pg/pg"
5456
"github.com/gorilla/mux"
@@ -469,6 +471,11 @@ func (handler AppListingRestHandlerImpl) FetchOverviewAppsByEnvironment(w http.R
469471
}
470472

471473
func (handler AppListingRestHandlerImpl) FetchAppDetailsV2(w http.ResponseWriter, r *http.Request) {
474+
userId, err := handler.userService.GetLoggedInUser(r)
475+
if userId == 0 || err != nil {
476+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
477+
return
478+
}
472479
vars := mux.Vars(r)
473480
token := r.Header.Get("token")
474481
appId, err := strconv.Atoi(vars["app-id"])
@@ -486,14 +493,21 @@ func (handler AppListingRestHandlerImpl) FetchAppDetailsV2(w http.ResponseWriter
486493
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
487494
return
488495
}
496+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
497+
userEmail := util2.GetEmailFromContext(r.Context())
498+
userMetadata := &bean.UserMetadata{
499+
UserEmailId: userEmail,
500+
IsUserSuperAdmin: isSuperAdmin,
501+
UserId: userId,
502+
}
489503
appDetail, err := handler.appListingService.FetchAppDetails(r.Context(), appId, envId)
490504
if err != nil {
491505
handler.logger.Errorw("service err, FetchAppDetailsV2", "err", err, "appId", appId, "envId", envId)
492506
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
493507
return
494508
}
495509

496-
appDetail, err = handler.updateApprovalConfigDataInAppDetailResp(appDetail, appId, envId)
510+
appDetail, err = handler.updateApprovalConfigDataInAppDetailResp(r.Context(), appDetail, appId, envId, userMetadata)
497511
if err != nil {
498512
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
499513
return

api/restHandler/app/appList/AppListingRestHandler_ent.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package appList
22

33
import (
4+
"context"
45
"github.com/devtron-labs/devtron/api/bean/AppView"
6+
userBean "github.com/devtron-labs/devtron/pkg/auth/user/bean"
57
"net/http"
68
)
79

@@ -14,6 +16,6 @@ func (handler AppListingRestHandlerImpl) FetchAutocompleteJobCiPipelines(w http.
1416
func (handler AppListingRestHandlerImpl) GetAllAppEnvsFromResourceNames(w http.ResponseWriter, r *http.Request) {
1517
}
1618

17-
func (handler AppListingRestHandlerImpl) updateApprovalConfigDataInAppDetailResp(appDetail AppView.AppDetailContainer, appId, envId int) (AppView.AppDetailContainer, error) {
19+
func (handler AppListingRestHandlerImpl) updateApprovalConfigDataInAppDetailResp(ctx context.Context, appDetail AppView.AppDetailContainer, appId, envId int, userMetadata *userBean.UserMetadata) (AppView.AppDetailContainer, error) {
1820
return appDetail, nil
1921
}

pkg/deployment/deployedApp/DeployedAppService.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (impl *DeployedAppServiceImpl) stopStartApp(ctx context.Context, stopReques
9999
impl.logger.Errorw("error in fetching latest release", "err", err)
100100
return 0, err
101101
}
102-
err = impl.checkForFeasibilityBeforeStartStop(stopRequest.AppId, stopRequest.EnvironmentId, userMetadata)
102+
err = impl.checkForFeasibilityBeforeStartStop(ctx, stopRequest.AppId, stopRequest.EnvironmentId, userMetadata)
103103
if err != nil {
104104
impl.logger.Errorw("error in checking for feasibility before hibernating and un hibernating", "stopRequest", stopRequest, "err", err)
105105
return 0, err
@@ -145,7 +145,7 @@ func (impl *DeployedAppServiceImpl) RotatePods(ctx context.Context, podRotateReq
145145
impl.logger.Errorw("error occurred while fetching env details", "envId", environmentId, "err", err)
146146
return nil, err
147147
}
148-
err = impl.checkForFeasibilityBeforeStartStop(podRotateRequest.AppId, podRotateRequest.EnvironmentId, userMetadata)
148+
err = impl.checkForFeasibilityBeforeStartStop(ctx, podRotateRequest.AppId, podRotateRequest.EnvironmentId, userMetadata)
149149
if err != nil {
150150
impl.logger.Errorw("error in checking for feasibility in Rotating pods", "podRotateRequest", podRotateRequest, "err", err)
151151
return nil, err

pkg/deployment/deployedApp/DeployedAppService_ent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func (impl *DeployedAppServiceImpl) getTemplate(stopRequest *bean.StopAppRequest) (string, error) {
1010
return "", nil
1111
}
12-
func (impl *DeployedAppServiceImpl) checkForFeasibilityBeforeStartStop(appId, envId int, userMetadata *bean6.UserMetadata) error {
12+
func (impl *DeployedAppServiceImpl) checkForFeasibilityBeforeStartStop(ctx context.Context, appId, envId int, userMetadata *bean6.UserMetadata) error {
1313
return nil
1414
}
1515

0 commit comments

Comments
 (0)