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"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2018-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
2021-02-23 03:21:39 +00:00
|
|
|
// @id UserList
|
|
|
|
// @summary List users
|
|
|
|
// @description List Portainer users.
|
|
|
|
// @description Non-administrator users will only be able to list other non-administrator user accounts.
|
2021-09-27 04:00:04 +00:00
|
|
|
// @description User passwords are filtered out, and should never be accessible.
|
2021-02-23 03:21:39 +00:00
|
|
|
// @description **Access policy**: restricted
|
|
|
|
// @tags users
|
2021-11-30 02:31:16 +00:00
|
|
|
// @security ApiKeyAuth
|
2021-02-23 03:21:39 +00:00
|
|
|
// @security jwt
|
|
|
|
// @produce json
|
|
|
|
// @success 200 {array} portainer.User "Success"
|
|
|
|
// @failure 400 "Invalid request"
|
|
|
|
// @failure 500 "Server error"
|
|
|
|
// @router /users [get]
|
2018-06-11 13:13:19 +00:00
|
|
|
func (handler *Handler) userList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
2020-05-20 05:23:15 +00:00
|
|
|
users, err := handler.DataStore.User().Users()
|
2018-06-11 13:13:19 +00:00
|
|
|
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)
|
|
|
|
}
|