Skip to content

Commit 2bd837b

Browse files
committed
added superadmin check before enforcing in batch
1 parent 5020267 commit 2bd837b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

api/cluster/EnvironmentRestHandler.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ func (impl EnvironmentRestHandlerImpl) GetAll(w http.ResponseWriter, r *http.Req
155155
return
156156
}
157157

158+
userId, err := impl.userService.GetLoggedInUser(r)
159+
if userId == 0 || err != nil {
160+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
161+
return
162+
}
163+
isSuperAdmin, err := impl.userService.IsSuperAdmin(int(userId))
164+
if err != nil {
165+
impl.logger.Errorw("request err, GetAll", "err", err, "userId", userId)
166+
common.WriteJsonResp(w, err, "Failed to check is super admin", http.StatusInternalServerError)
167+
return
168+
}
169+
if isSuperAdmin {
170+
common.WriteJsonResp(w, err, environments, http.StatusOK)
171+
return
172+
}
173+
158174
token := r.Header.Get("token")
159175
emailId, err := impl.userService.GetEmailFromToken(token)
160176
if err != nil {

0 commit comments

Comments
 (0)