mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-31 01:10:20 -06:00
make list group users work with uuid and usernames
This commit is contained in:
@@ -46,12 +46,12 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
userIDEinstein string = "einstein"
|
||||
userIDMarie string = "marie"
|
||||
userIDFeynman string = "richard"
|
||||
userIDKonnectd string = "konnectd"
|
||||
userIDReva string = "reva"
|
||||
userIDMoss string = "moss"
|
||||
userIDEinstein string = "4c510ada-c86b-4815-8820-42cdf82c3d51"
|
||||
userIDMarie string = "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"
|
||||
userIDFeynman string = "932b4540-8d16-481e-8ef4-588e4b6b151c"
|
||||
userIDKonnectd string = "820ba2a1-3f54-4538-80a4-2d73007e30bf"
|
||||
userIDReva string = "bc596f3c-c955-4328-80a0-60d018b4ad57"
|
||||
userIDMoss string = "058bff95-6708-4fe5-91e4-9ea3d377588b"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,6 +3,7 @@ package svc
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/render"
|
||||
@@ -16,16 +17,26 @@ import (
|
||||
// ListUserGroups lists a users groups
|
||||
func (o Ocs) ListUserGroups(w http.ResponseWriter, r *http.Request) {
|
||||
userid := chi.URLParam(r, "userid")
|
||||
account, err := o.fetchAccountByUsername(r.Context(), userid)
|
||||
if err != nil {
|
||||
merr := merrors.FromError(err)
|
||||
if merr.Code == http.StatusNotFound {
|
||||
render.Render(w, r, response.ErrRender(data.MetaNotFound.StatusCode, "The requested user could not be found"))
|
||||
} else {
|
||||
render.Render(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
|
||||
var account *accounts.Account
|
||||
var err error
|
||||
|
||||
if isValidUUID(userid) {
|
||||
account, err = o.getAccountService().GetAccount(r.Context(), &accounts.GetAccountRequest{
|
||||
Id: userid,
|
||||
})
|
||||
} else {
|
||||
// despite the confusion, if we make it here we got ourselves a username
|
||||
account, err = o.fetchAccountByUsername(r.Context(), userid)
|
||||
if err != nil {
|
||||
merr := merrors.FromError(err)
|
||||
if merr.Code == http.StatusNotFound {
|
||||
render.Render(w, r, response.ErrRender(data.MetaNotFound.StatusCode, "The requested user could not be found"))
|
||||
} else {
|
||||
render.Render(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
|
||||
}
|
||||
o.logger.Error().Err(err).Str("userid", userid).Msg("could not get list of user groups")
|
||||
return
|
||||
}
|
||||
o.logger.Error().Err(err).Str("userid", userid).Msg("could not get list of user groups")
|
||||
return
|
||||
}
|
||||
|
||||
groups := []string{}
|
||||
@@ -194,3 +205,8 @@ func (o Ocs) GetGroupMembers(w http.ResponseWriter, r *http.Request) {
|
||||
o.logger.Error().Err(err).Int("count", len(members)).Str("groupid", groupid).Msg("listing group members")
|
||||
render.Render(w, r, response.DataRender(&data.Users{Users: members}))
|
||||
}
|
||||
|
||||
func isValidUUID(uuid string) bool {
|
||||
r := regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")
|
||||
return r.MatchString(uuid)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user