Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
d00b60a
api spec update
gireesh-naidu Nov 1, 2022
29de140
repository update for monitoring tool
gireesh-naidu Nov 2, 2022
5e6eee0
added external_link_identifier _mapping repository
gireesh-naidu Nov 2, 2022
0007b1b
updated external_link repository
gireesh-naidu Nov 2, 2022
0905cf2
removed external_link_cluster_mapping repository file
gireesh-naidu Nov 2, 2022
e555159
api spec update
gireesh-naidu Nov 2, 2022
427a537
updated create external link method
gireesh-naidu Nov 2, 2022
cc89dee
struct change and identifier passed by pointer
gireesh-naidu Nov 2, 2022
7fc247f
updated fetch api
gireesh-naidu Nov 2, 2022
8a90b3e
query updates
gireesh-naidu Nov 2, 2022
097bf66
fetching cluster level links for a particular app and wrote code for …
gireesh-naidu Nov 2, 2022
361f908
delete api code update
gireesh-naidu Nov 2, 2022
d5042a5
unwanted comments deleted
gireesh-naidu Nov 2, 2022
b528d9d
implemented get links rest handler
gireesh-naidu Nov 3, 2022
5e34927
added edit access check for delete operation
gireesh-naidu Nov 3, 2022
40f2851
modified update,delete and create handlers
gireesh-naidu Nov 3, 2022
f5ba9b4
wire
gireesh-naidu Nov 3, 2022
d62cf85
struct update
gireesh-naidu Nov 3, 2022
8d404a6
fix err check condition
gireesh-naidu Nov 3, 2022
31e2ace
fixed returning
gireesh-naidu Nov 3, 2022
b38547c
testing roles code
gireesh-naidu Nov 4, 2022
0f9bf85
wire
gireesh-naidu Nov 4, 2022
aa1f1ff
removed commented code
gireesh-naidu Nov 4, 2022
06b84b0
sending action as argument to roleChecker
gireesh-naidu Nov 4, 2022
3301613
rbac by appname and envid
gireesh-naidu Nov 4, 2022
d3efce5
appListing api to fetch all the active installed apps and devtron apps
gireesh-naidu Nov 5, 2022
b5e2d07
query fix
gireesh-naidu Nov 5, 2022
fb4afdf
comments fix
gireesh-naidu Nov 5, 2022
1a26de3
redundant check removed
gireesh-naidu Nov 5, 2022
aba0866
removed commented code
gireesh-naidu Nov 5, 2022
1ae280f
fix
gireesh-naidu Nov 5, 2022
d1660e3
sql migration script added for external links feat
gireesh-naidu Nov 7, 2022
acf7991
added env_id and changed the enforcing to app-level
gireesh-naidu Nov 7, 2022
108eda8
code review changes
gireesh-naidu Nov 8, 2022
671388f
appid passing
gireesh-naidu Nov 8, 2022
8c81f31
rolecheck api at handler level
gireesh-naidu Nov 8, 2022
2fb96c5
check roles api enhanced
gireesh-naidu Nov 8, 2022
90c1f12
scripts updated
gireesh-naidu Nov 8, 2022
552d2ec
script number update
gireesh-naidu Nov 8, 2022
5ceb5c2
added last deployedAt field in other env api
gireesh-naidu Nov 8, 2022
77b1730
code refactor
gireesh-naidu Nov 8, 2022
7f6077a
commented commands removed
gireesh-naidu Nov 8, 2022
e71e1a1
fix
gireesh-naidu Nov 9, 2022
72c89f2
fix
gireesh-naidu Nov 9, 2022
1183853
merge main
gireesh-naidu Nov 9, 2022
e297ec5
Merge remote-tracking branch 'origin/external_links_extention' into e…
gireesh-naidu Nov 9, 2022
57d63de
query indentation fix
gireesh-naidu Nov 9, 2022
0832b4d
query indentation fix
gireesh-naidu Nov 9, 2022
cd2eb53
last deployed time query
gireesh-naidu Nov 9, 2022
f6d50be
fix
gireesh-naidu Nov 9, 2022
e233dfe
fix
gireesh-naidu Nov 9, 2022
b371437
query added for last deployed time
gireesh-naidu Nov 9, 2022
fc0ee4e
query update
gireesh-naidu Nov 9, 2022
fb9794d
response fix
gireesh-naidu Nov 9, 2022
0aa077f
error messages corrected
gireesh-naidu Nov 9, 2022
d0bcf9a
removed unused code
gireesh-naidu Nov 9, 2022
2450cb7
unit tests added
gireesh-naidu Nov 9, 2022
345d8e0
unit tests added for fetch api
gireesh-naidu Nov 9, 2022
645d20d
unit tests done for fetch api
gireesh-naidu Nov 10, 2022
eeffd6b
unit tests done for update api
gireesh-naidu Nov 10, 2022
23deee2
tests updated
gireesh-naidu Nov 10, 2022
9501174
condition fix
gireesh-naidu Nov 10, 2022
cc168d2
param check updated
gireesh-naidu Nov 10, 2022
a043664
removed unused code
gireesh-naidu Nov 10, 2022
4e64588
removed unused code
gireesh-naidu Nov 10, 2022
7874d66
checks for global level links
gireesh-naidu Nov 12, 2022
03fc102
added new tools and category field
gireesh-naidu Nov 12, 2022
76e8d3c
delete fix
gireesh-naidu Nov 14, 2022
8a64728
delete api fix
gireesh-naidu Nov 14, 2022
7e5d9b0
test cmt
gireesh-naidu Nov 14, 2022
ebabada
wire
gireesh-naidu Nov 14, 2022
6bfb9f0
code review changes
gireesh-naidu Nov 15, 2022
cc9a920
error fix
gireesh-naidu Nov 15, 2022
0d60a1a
code review changes
gireesh-naidu Nov 15, 2022
71265cc
api error messages updated
gireesh-naidu Nov 15, 2022
78cb8f2
api error messages updated
gireesh-naidu Nov 15, 2022
cb7d9d2
global link type switching fix
gireesh-naidu Nov 16, 2022
353c01a
fix
gireesh-naidu Nov 16, 2022
2547b99
other env query fix
gireesh-naidu Nov 16, 2022
04fe5fc
query fix
gireesh-naidu Nov 16, 2022
5b10a01
merge main
gireesh-naidu Nov 16, 2022
a049c68
script number updated
gireesh-naidu Nov 16, 2022
2e67f60
code review changes
gireesh-naidu Nov 16, 2022
0c5cd43
removed extra auth check in service layer
gireesh-naidu Nov 16, 2022
4790b50
test
gireesh-naidu Nov 17, 2022
b4482ea
test
gireesh-naidu Nov 17, 2022
bc447cd
check role API fix
kripanshdevtron Nov 17, 2022
bffb5ce
qa bug fix(some active links not showing)
gireesh-naidu Nov 21, 2022
13d4910
Merge branch 'main' into external_links_extention
gireesh-naidu Nov 21, 2022
6b6a63f
unit testcases modified
gireesh-naidu Nov 23, 2022
a015c17
unit testcases modified with max coverage
gireesh-naidu Nov 23, 2022
d1b80e9
integration test cases added
gireesh-naidu Nov 23, 2022
5bfa3ce
integration test cases added for update api
gireesh-naidu Nov 23, 2022
1bfefc8
integration test cases added for delete api
gireesh-naidu Nov 23, 2022
8d832fb
fixed cleandb func
gireesh-naidu Nov 23, 2022
ff4a9e7
invalid input tests added
gireesh-naidu Nov 24, 2022
d16439a
added admin edit test
gireesh-naidu Nov 24, 2022
3f38613
config changes
gireesh-naidu Nov 24, 2022
d01618d
cleaning un-used methods
gireesh-naidu Nov 24, 2022
4a608c5
default config vals added
gireesh-naidu Nov 24, 2022
104ee79
querying based on app type condition
gireesh-naidu Nov 24, 2022
db5c64f
removed unused functions
gireesh-naidu Nov 24, 2022
75bb60f
tests added for monitoring tools repo
gireesh-naidu Nov 24, 2022
f72f98a
test cases added for fetch active external links by identifier
gireesh-naidu Nov 24, 2022
f0b532a
integration test added for apps to apps update link case
gireesh-naidu Nov 24, 2022
16d9ed9
removed un used code
gireesh-naidu Nov 24, 2022
15de03f
removed un used code
gireesh-naidu Nov 24, 2022
cc087f7
fix
gireesh-naidu Nov 24, 2022
b1f10f2
script number updated
gireesh-naidu Nov 24, 2022
2693b86
Merge branch 'main' into external_links_extention
gireesh-naidu Nov 24, 2022
c6befb9
removed un-necessary logic
gireesh-naidu Nov 25, 2022
60e0b52
changed native query to orm queries
gireesh-naidu Nov 25, 2022
8f50031
no rows handling
gireesh-naidu Nov 25, 2022
2f6ee03
code review changes
gireesh-naidu Nov 25, 2022
2807cda
test skips added
gireesh-naidu Nov 25, 2022
11ebdcd
no rows error logic removed from resthandler layer
gireesh-naidu Nov 25, 2022
8a5c89d
native query to orm query
gireesh-naidu Nov 25, 2022
4ff56b6
code review changes
gireesh-naidu Nov 25, 2022
ef2e5f8
script number updated
gireesh-naidu Nov 26, 2022
f73cac3
merge main
gireesh-naidu Nov 26, 2022
1672261
vendor files update
gireesh-naidu Nov 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/bean/AppView.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type Environment struct {
InfraMetrics *bool `json:"infraMetrics"`
Prod bool `json:"prod"`
ChartRefId int `json:"chartRefId"`
LastDeployed string `json:"lastDeployed"`
}

type InstanceDetail struct {
Expand Down
153 changes: 98 additions & 55 deletions api/externalLink/ExternalLinkRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ package externalLink

import (
"encoding/json"
"fmt"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/externalLink"
"github.com/devtron-labs/devtron/pkg/user"
"github.com/devtron-labs/devtron/pkg/user/casbin"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/go-pg/pg"
"github.com/gorilla/mux"
"github.com/juju/errors"
"go.uber.org/zap"
Expand All @@ -42,24 +45,61 @@ type ExternalLinkRestHandlerImpl struct {
externalLinkService externalLink.ExternalLinkService
userService user.UserService
enforcer casbin.Enforcer
enforcerUtil rbac.EnforcerUtil
}

func NewExternalLinkRestHandlerImpl(logger *zap.SugaredLogger,
externalLinkService externalLink.ExternalLinkService,
userService user.UserService,
enforcer casbin.Enforcer,
enforcerUtil rbac.EnforcerUtil,
) *ExternalLinkRestHandlerImpl {
return &ExternalLinkRestHandlerImpl{
logger: logger,
externalLinkService: externalLinkService,
userService: userService,
enforcer: enforcer,
enforcerUtil: enforcerUtil,
}
}
func (impl ExternalLinkRestHandlerImpl) CreateExternalLinks(w http.ResponseWriter, r *http.Request) {

func (impl ExternalLinkRestHandlerImpl) roleCheckHelper(w http.ResponseWriter, r *http.Request, action string) (int32, string, error) {
userId, err := impl.userService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return userId, "", fmt.Errorf("unauthorized error")
}
userRole := ""
v := r.URL.Query()
//put this check from identifiers itself,don't get this appname from query params
appId := v.Get("appId")
token := r.Header.Get("token")
if v.Has("appId") {
id, err := strconv.Atoi(appId)
if err != nil {
Copy link
Contributor

@kripanshdevtron kripanshdevtron Nov 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err is not logged

impl.logger.Errorw("error occurred while converting appId to integer", "err", err, "appId", appId)
common.WriteJsonResp(w, errors.New("Invalid request"), nil, http.StatusBadRequest)
return userId, "", fmt.Errorf("invalid request query param appId = %s", appId)
}
object := impl.enforcerUtil.GetAppRBACNameByAppId(id)
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, action, object); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return userId, "", fmt.Errorf("unauthorized error")
}
userRole = externalLink.ADMIN_ROLE
} else {
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, action, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return userId, "", fmt.Errorf("unauthorized error")
}
userRole = externalLink.SUPER_ADMIN_ROLE
}
return userId, userRole, nil
}
func (impl ExternalLinkRestHandlerImpl) CreateExternalLinks(w http.ResponseWriter, r *http.Request) {
userId, userRole, err := impl.roleCheckHelper(w, r, casbin.ActionCreate)
if err != nil {
impl.logger.Errorw("error in CreateExternalLinks ", "err", err)
return
}
decoder := json.NewDecoder(r.Body)
Expand All @@ -70,15 +110,8 @@ func (impl ExternalLinkRestHandlerImpl) CreateExternalLinks(w http.ResponseWrite
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

token := r.Header.Get("token")
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}

res, err := impl.externalLinkService.Create(beans, userId)
if err != nil {
res, err := impl.externalLinkService.Create(beans, userId, userRole)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("service err, SaveLink", "err", err, "payload", beans)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand All @@ -92,10 +125,9 @@ func (impl ExternalLinkRestHandlerImpl) GetExternalLinkMonitoringTools(w http.Re
return
}

// auth free api as we using this for multiple places

// auth free api as we are using this for multiple places
res, err := impl.externalLinkService.GetAllActiveTools()
if err != nil {
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("service err, GetAllActiveTools", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
Expand All @@ -108,38 +140,62 @@ func (impl ExternalLinkRestHandlerImpl) GetExternalLinks(w http.ResponseWriter,
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}

v := r.URL.Query()
id := v.Get("clusterId")
clusterId := 0
if len(id) > 0 {
clusterId, err = strconv.Atoi(id)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}
clusterId := v.Get("clusterId")
linkType := v.Get("type")
identifier := v.Get("identifier")

//apply auth only in case when requested for all links
if clusterId == 0 {
token := r.Header.Get("token")
token := r.Header.Get("token")
if len(identifier) == 0 && len(linkType) == 0 && len(clusterId) == 0 {
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}
}
clusterIdNumber := 0
res, err := impl.externalLinkService.FetchAllActiveLinksByLinkIdentifier(nil, clusterIdNumber)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error is not logged and handled properly

impl.logger.Errorw("service err, FetchAllActive", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
return

res, err := impl.externalLinkService.FetchAllActiveLinks(clusterId)
if err != nil {
impl.logger.Errorw("service err, FetchAllActive", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
} else if len(identifier) != 0 && len(linkType) != 0 { //api to get external links from app-level external links tab and from app-details page
clusterIdNumber := 0
if len(clusterId) != 0 { //api call from app-detail page
clusterIdNumber, err = strconv.Atoi(clusterId)
if err != nil {
impl.logger.Errorw("error occurred while parsing cluster_id", "clusterId", clusterId, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}
linkIdentifier := &externalLink.LinkIdentifier{
Type: linkType,
Identifier: identifier,
ClusterId: 0,
}
res, err := impl.externalLinkService.FetchAllActiveLinksByLinkIdentifier(linkIdentifier, clusterIdNumber)
if err != nil {
impl.logger.Errorw("service err, FetchAllActive", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)

impl.logger.Errorw("invalid request, FetchAllActive external links", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return

}

func (impl ExternalLinkRestHandlerImpl) UpdateExternalLink(w http.ResponseWriter, r *http.Request) {
userId, err := impl.userService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
userId, userRole, err := impl.roleCheckHelper(w, r, casbin.ActionUpdate)
if err != nil {
return
}
decoder := json.NewDecoder(r.Body)
Expand All @@ -152,45 +208,32 @@ func (impl ExternalLinkRestHandlerImpl) UpdateExternalLink(w http.ResponseWriter
}
bean.UserId = userId

token := r.Header.Get("token")
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}

impl.logger.Infow("request payload, UpdateLink", "err", err, "bean", bean)
res, err := impl.externalLinkService.Update(&bean)
res, err := impl.externalLinkService.Update(&bean, userRole)
if err != nil {
impl.logger.Errorw("service err, Update Links", "err", err, "bean", bean)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
}

func (impl ExternalLinkRestHandlerImpl) DeleteExternalLink(w http.ResponseWriter, r *http.Request) {
userId, err := impl.userService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
userId, userRole, err := impl.roleCheckHelper(w, r, casbin.ActionDelete)
if err != nil {
return
}
params := mux.Vars(r)
id := params["id"]
idi, err := strconv.Atoi(id)
linkId, err := strconv.Atoi(id)
if err != nil {
impl.logger.Errorw("request err, DeleteExternalLink", "err", err, "id", id)
impl.logger.Errorw("request err, DeleteExternalLink", "id", id, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

token := r.Header.Get("token")
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionDelete, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}

res, err := impl.externalLinkService.DeleteLink(idi, userId)
res, err := impl.externalLinkService.DeleteLink(linkId, userId, userRole)
if err != nil {
impl.logger.Errorw("service err, delete Links", "err", err, "id", idi)
impl.logger.Errorw("service err, delete Links", "err", err, "linkId", linkId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
Expand Down
5 changes: 2 additions & 3 deletions api/externalLink/wire_externalLinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
var ExternalLinkWireSet = wire.NewSet(
externalLink.NewExternalLinkMonitoringToolRepositoryImpl,
wire.Bind(new(externalLink.ExternalLinkMonitoringToolRepository), new(*externalLink.ExternalLinkMonitoringToolRepositoryImpl)),
externalLink.NewExternalLinkClusterMappingRepositoryImpl,
wire.Bind(new(externalLink.ExternalLinkClusterMappingRepository), new(*externalLink.ExternalLinkClusterMappingRepositoryImpl)),
externalLink.NewExternalLinkIdentifierMappingRepositoryImpl,
wire.Bind(new(externalLink.ExternalLinkIdentifierMappingRepository), new(*externalLink.ExternalLinkIdentifierMappingRepositoryImpl)),
externalLink.NewExternalLinkRepositoryImpl,
wire.Bind(new(externalLink.ExternalLinkRepository), new(*externalLink.ExternalLinkRepositoryImpl)),


externalLink.NewExternalLinkServiceImpl,
wire.Bind(new(externalLink.ExternalLinkService), new(*externalLink.ExternalLinkServiceImpl)),
NewExternalLinkRestHandlerImpl,
Expand Down
21 changes: 19 additions & 2 deletions api/restHandler/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import (
type AppListingRestHandler interface {
FetchAppsByEnvironment(w http.ResponseWriter, r *http.Request)
FetchAppDetails(w http.ResponseWriter, r *http.Request)

FetchAllDevtronManagedApps(w http.ResponseWriter, r *http.Request)
FetchAppTriggerView(w http.ResponseWriter, r *http.Request)
FetchAppStageStatus(w http.ResponseWriter, r *http.Request)

Expand Down Expand Up @@ -127,7 +127,24 @@ func setupResponse(w *http.ResponseWriter, req *http.Request) {
(*w).Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
(*w).Header().Set("Content-Type", "text/html; charset=utf-8")
}

func (handler AppListingRestHandlerImpl) FetchAllDevtronManagedApps(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
userId, err := handler.userService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
handler.logger.Infow("got request to fetch all devtron managed apps ", "userId", userId)
//RBAC starts
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
handler.logger.Infow("user forbidden to fetch all devtron managed apps", "userId", userId)
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
}
//RBAC ends
res, err := handler.appListingService.FetchAllDevtronManagedApps()
common.WriteJsonResp(w, err, res, http.StatusOK)
}
func (handler AppListingRestHandlerImpl) FetchAppsByEnvironment(w http.ResponseWriter, r *http.Request) {
//Allow CORS here By * or specific origin
setupResponse(&w, r)
Expand Down
1 change: 0 additions & 1 deletion api/restHandler/app/BuildPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ func (handler PipelineConfigRestHandlerImpl) GetExternalCi(w http.ResponseWriter
common.WriteJsonResp(w, err, ciConf, http.StatusOK)
}


func (handler PipelineConfigRestHandlerImpl) GetExternalCiById(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
appId, err := strconv.Atoi(vars["appId"])
Expand Down
2 changes: 2 additions & 0 deletions api/router/AppListingRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func NewAppListingRouterImpl(appListingRestHandler restHandler.AppListingRestHan
}

func (router AppListingRouterImpl) initAppListingRouter(appListingRouter *mux.Router) {
appListingRouter.Path("/allApps").HandlerFunc(router.appListingRestHandler.FetchAllDevtronManagedApps).
Methods("GET")

appListingRouter.Path("/resource/urls").Queries("envId", "{envId}").
HandlerFunc(router.appListingRestHandler.GetHostUrlsByBatch).Methods("GET")
Expand Down
36 changes: 36 additions & 0 deletions api/user/UserRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,42 @@ func (handler UserRestHandlerImpl) CheckUserRoles(w http.ResponseWriter, r *http
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

v := r.URL.Query()

if v.Has("appName") {
appName := v.Get("appName")
result := make(map[string]interface{})
var isSuperAdmin, isAdmin, isManager, isTrigger bool
for _, role := range roles {
if role == bean.SUPERADMIN {
isSuperAdmin = true
break
}
frags := strings.Split(role, "_")
n := len(frags)
if n >= 2 && (frags[n-1] == appName || frags[n-1] == "") {
isManager = strings.Contains(frags[0], "manager")
isAdmin = strings.Contains(frags[0], "admin")
isTrigger = strings.Contains(frags[0], "trigger")
}
}
if isSuperAdmin {
result["role"] = "SuperAdmin"
} else if isManager {
result["role"] = "Manager"
} else if isAdmin {
result["role"] = "Admin"
} else if isTrigger {
result["role"] = "Trigger"
} else {
result["role"] = "View"
}
result["roles"] = roles

common.WriteJsonResp(w, err, result, http.StatusOK)
return
}
result := make(map[string]interface{})
result["roles"] = roles
result["superAdmin"] = false
Expand Down
11 changes: 6 additions & 5 deletions cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading