2018-06-11 13:13:19 +00:00
|
|
|
package users
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-09-10 10:01:38 +00:00
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/libhttp/response"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer/http/security"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GET request on /api/users
|
|
|
|
func (handler *Handler) userList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
|
|
users, err := handler.UserService.Users()
|
|
|
|
if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve users from the database", err}
|
|
|
|
}
|
|
|
|
|
|
|
|
securityContext, err := security.RetrieveRestrictedRequestContext(r)
|
|
|
|
if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err}
|
|
|
|
}
|
|
|
|
|
|
|
|
filteredUsers := security.FilterUsers(users, securityContext)
|
|
|
|
|
2018-07-31 09:50:04 +00:00
|
|
|
for idx := range filteredUsers {
|
|
|
|
hideFields(&filteredUsers[idx])
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
2018-07-31 09:50:04 +00:00
|
|
|
|
2018-06-11 13:13:19 +00:00
|
|
|
return response.JSON(w, filteredUsers)
|
|
|
|
}
|