diff --git a/services/graph/pkg/identity/cs3.go b/services/graph/pkg/identity/cs3.go index 039edbfb8..a42bbdbc4 100644 --- a/services/graph/pkg/identity/cs3.go +++ b/services/graph/pkg/identity/cs3.go @@ -203,7 +203,6 @@ func createGroupModelFromCS3(g *cs3group.Group) *libregraph.Group { OnPremisesDomainName: &g.Id.Idp, OnPremisesSamAccountName: &g.GroupName, DisplayName: &g.DisplayName, - Mail: &g.Mail, // TODO when to fetch and expand memberof, usernames or ids? } } diff --git a/services/graph/pkg/service/v0/drives.go b/services/graph/pkg/service/v0/drives.go index 9ec9984db..fd8c25709 100644 --- a/services/graph/pkg/service/v0/drives.go +++ b/services/graph/pkg/service/v0/drives.go @@ -733,6 +733,17 @@ func listStorageSpacesIDFilter(id string) *storageprovider.ListStorageSpacesRequ } } +func listStorageSpacesUserFilter(id string) *storageprovider.ListStorageSpacesRequest_Filter { + return &storageprovider.ListStorageSpacesRequest_Filter{ + Type: storageprovider.ListStorageSpacesRequest_Filter_TYPE_USER, + Term: &storageprovider.ListStorageSpacesRequest_Filter_User{ + User: &userv1beta1.UserId{ + OpaqueId: id, + }, + }, + } +} + func listStorageSpacesTypeFilter(spaceType string) *storageprovider.ListStorageSpacesRequest_Filter { return &storageprovider.ListStorageSpacesRequest_Filter{ Type: storageprovider.ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE, diff --git a/services/graph/pkg/service/v0/users.go b/services/graph/pkg/service/v0/users.go index 96f8e9cc7..d5b845bef 100644 --- a/services/graph/pkg/service/v0/users.go +++ b/services/graph/pkg/service/v0/users.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/CiscoM31/godata" + storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/events" @@ -21,6 +22,7 @@ import ( "github.com/owncloud/ocis/v2/services/graph/pkg/identity" "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode" settingssvc "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0" + "golang.org/x/exp/slices" ) // GetMe implements the Service interface. @@ -171,6 +173,35 @@ func (g Graph) GetUser(w http.ResponseWriter, r *http.Request) { errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) } } + sel := strings.Split(r.URL.Query().Get("$select"), ",") + exp := strings.Split(r.URL.Query().Get("$expand"), ",") + if slices.Contains(sel, "drive") || slices.Contains(sel, "drives") || slices.Contains(exp, "drive") || slices.Contains(exp, "drives") { + wdu, err := url.Parse(g.config.Spaces.WebDavBase + g.config.Spaces.WebDavPath) + // TODO: filter this request for the user + f := listStorageSpacesUserFilter(user.GetId()) + lspr, err := g.gatewayClient.ListStorageSpaces(r.Context(), &storageprovider.ListStorageSpacesRequest{ + Opaque: nil, + Filters: []*storageprovider.ListStorageSpacesRequest_Filter{f}, + }) + if err != nil { + g.logger.Err(err).Interface("query", r.URL.Query()).Msg("error getting storages") + } + drives := []libregraph.Drive{} + for _, sp := range lspr.GetStorageSpaces() { + d, err := g.cs3StorageSpaceToDrive(r.Context(), wdu, sp) + if err != nil { + g.logger.Err(err).Interface("query", r.URL.Query()).Msg("error converting space to drive") + } + if slices.Contains(sel, "drive") || slices.Contains(exp, "drive") { + if *d.DriveType == "personal" { + drives = append(drives, *d) + } + } else { + drives = append(drives, *d) + } + } + user.Drives = drives + } render.Status(r, http.StatusOK) render.JSON(w, r, user)