support getting photos for other users
Signed-off-by: Christian Richter <c.richter@opencloud.eu>
This commit is contained in:
committed by
Florian Schade
parent
e23b8f412b
commit
a24ead6d20
@@ -2,8 +2,10 @@ package svc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
"github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode"
|
||||
revactx "github.com/opencloud-eu/reva/v2/pkg/ctx"
|
||||
@@ -19,14 +21,28 @@ func (g Graph) GetMePhoto(w http.ResponseWriter, r *http.Request) {
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "user not in context")
|
||||
return
|
||||
}
|
||||
g.GetPhoto(w, r, u.GetId())
|
||||
g.getPhoto(w, r, u.GetId())
|
||||
}
|
||||
|
||||
// GetPhoto implements the Service interface
|
||||
func (g Graph) GetPhoto(w http.ResponseWriter, r *http.Request, u *userpb.UserId) {
|
||||
func (g Graph) GetPhoto(w http.ResponseWriter, r *http.Request) {
|
||||
logger := g.logger.SubloggerWithRequestID(r.Context())
|
||||
logger.Debug().Msg("GetPhoto called")
|
||||
|
||||
userID, err := url.PathUnescape(chi.URLParam(r, "userID"))
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Str("userID", chi.URLParam(r, "userID")).Msg("could not get drive: unescaping drive id failed")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "unescaping user id failed")
|
||||
return
|
||||
}
|
||||
g.getPhoto(w, r, &userpb.UserId{
|
||||
OpaqueId: userID,
|
||||
})
|
||||
}
|
||||
|
||||
func (g Graph) getPhoto(w http.ResponseWriter, r *http.Request, u *userpb.UserId) {
|
||||
logger := g.logger.SubloggerWithRequestID(r.Context())
|
||||
logger.Debug().Msg("GetPhoto called")
|
||||
|
||||
// TODO: use proper default return
|
||||
render.Status(r, http.StatusNotFound)
|
||||
render.JSON(w, r, nil)
|
||||
@@ -42,11 +58,25 @@ func (g Graph) UpdateMePhoto(w http.ResponseWriter, r *http.Request) {
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "user not in context")
|
||||
return
|
||||
}
|
||||
g.UpdatePhoto(w, r, u.GetId())
|
||||
g.updatePhoto(w, r, u.GetId())
|
||||
}
|
||||
|
||||
// UpdatePhoto implements the Service interface
|
||||
func (g Graph) UpdatePhoto(w http.ResponseWriter, r *http.Request, u *userpb.UserId) {
|
||||
func (g Graph) UpdatePhoto(w http.ResponseWriter, r *http.Request) {
|
||||
logger := g.logger.SubloggerWithRequestID(r.Context())
|
||||
logger.Debug().Msg("UpdatePhoto called")
|
||||
userID, err := url.PathUnescape(chi.URLParam(r, "userID"))
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Str("userID", chi.URLParam(r, "userID")).Msg("could not get drive: unescaping drive id failed")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "unescaping user id failed")
|
||||
return
|
||||
}
|
||||
g.updatePhoto(w, r, &userpb.UserId{
|
||||
OpaqueId: userID,
|
||||
})
|
||||
}
|
||||
|
||||
func (g Graph) updatePhoto(w http.ResponseWriter, r *http.Request, u *userpb.UserId) {
|
||||
logger := g.logger.SubloggerWithRequestID(r.Context())
|
||||
logger.Debug().Msg("UpdatePhoto called")
|
||||
|
||||
|
||||
@@ -312,6 +312,8 @@ func NewService(opts ...Option) (Graph, error) { //nolint:maintidx
|
||||
r.Delete("/{appRoleAssignmentID}", svc.DeleteAppRoleAssignment)
|
||||
})
|
||||
}
|
||||
r.Get("/photo", svc.GetPhoto)
|
||||
r.Put("/photo", svc.UpdatePhoto)
|
||||
})
|
||||
})
|
||||
r.Route("/groups", func(r chi.Router) {
|
||||
|
||||
Reference in New Issue
Block a user