mirror of https://github.com/portainer/portainer
30 lines
1.0 KiB
Go
30 lines
1.0 KiB
Go
package teammemberships
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
"github.com/portainer/libhttp/response"
|
|
"github.com/portainer/portainer"
|
|
"github.com/portainer/portainer/http/security"
|
|
)
|
|
|
|
// GET request on /api/team_memberships
|
|
func (handler *Handler) teamMembershipList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
securityContext, err := security.RetrieveRestrictedRequestContext(r)
|
|
if err != nil {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err}
|
|
}
|
|
|
|
if !securityContext.IsAdmin && !securityContext.IsTeamLeader {
|
|
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to list team memberships", portainer.ErrResourceAccessDenied}
|
|
}
|
|
|
|
memberships, err := handler.TeamMembershipService.TeamMemberships()
|
|
if err != nil {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve team memberships from the database", err}
|
|
}
|
|
|
|
return response.JSON(w, memberships)
|
|
}
|