Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: add graph beta sharedWithMe API
- Loading branch information
Showing
8 changed files
with
389 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Enhancement: Add graph beta sharedWithMe API | ||
|
||
Add graph beta api implementation for the sharedWithMe endpoint. | ||
The implementation is a logical replication of the existing OCS API. | ||
|
||
https://github.com/owncloud/ocis/pull/7633 | ||
https://github.com/owncloud/ocis/issues/7436 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package svc | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"path" | ||
|
||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" | ||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" | ||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" | ||
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" | ||
"github.com/go-chi/render" | ||
libregraph "github.com/owncloud/libre-graph-api-go" | ||
|
||
"github.com/owncloud/ocis/v2/services/graph/pkg/identity" | ||
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode" | ||
) | ||
|
||
// ListSharedWithMe returns a list of all driveItems shared with the user | ||
// | ||
// urls: | ||
// - https://host.docker.internal:9200/ocs/v1.php/apps/files_sharing/api/v1/shares?include_tags=false&state=all&show_hidden=true&shared_with_me=true | ||
// | ||
// todo: | ||
// show-hidden or show_hidden | ||
// | ||
// ambiguity: | ||
// include_tags query param -> web uses it, but what is it for? | ||
// path query param -> web doesn't use it | ||
// share_ref query param -> web doesn't use it | ||
// share_types query param -> web doesn't use it | ||
func (g Graph) ListSharedWithMe(w http.ResponseWriter, r *http.Request) { | ||
showHidden := r.URL.Query().Get("show-hidden") == "true" | ||
ctx := r.Context() | ||
driveItems, err := g.listSharedWithMe(ctx, showHidden) | ||
if err != nil { | ||
errorcode.RenderError(w, r, err) | ||
return | ||
} | ||
|
||
render.Status(r, http.StatusOK) | ||
render.JSON(w, r, &ListResponse{Value: driveItems}) | ||
} | ||
func (g Graph) listSharedWithMe(ctx context.Context, showHidden bool) ([]libregraph.DriveItem, error) { | ||
gatewayClient, err := g.gatewaySelector.Next() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
listReceivedSharesResponse, err := gatewayClient.ListReceivedShares(ctx, &collaboration.ListReceivedSharesRequest{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch listReceivedSharesResponse.Status.Code { | ||
case rpc.Code_CODE_NOT_FOUND: | ||
return nil, identity.ErrNotFound | ||
} | ||
|
||
var driveItems []libregraph.DriveItem | ||
for _, share := range listReceivedSharesResponse.GetShares() { | ||
if share.Hidden && !showHidden { | ||
continue | ||
} | ||
|
||
stat, err := gatewayClient.Stat(ctx, &storageprovider.StatRequest{Ref: &storageprovider.Reference{ResourceId: share.Share.ResourceId}}) | ||
if err != nil { | ||
// fixMe: return err!? | ||
continue | ||
} | ||
if stat.Status.Code != rpc.Code_CODE_OK { | ||
// fixMe: return err!? | ||
continue | ||
} | ||
|
||
driveItem := &libregraph.DriveItem{ | ||
RemoteItem: &libregraph.RemoteItem{}, | ||
} | ||
|
||
// driveItem.remoteItem | ||
// ✅ createdBy IdentitySet Identity of the user, device, and application which created the item. Read-only. | ||
// ✅ createdDateTime Timestamp Date and time of item creation. Read-only. | ||
// ❌ file File Indicates that the remote item is a file. Read-only. | ||
// ❌ fileSystemInfo FileSystemInfo Information about the remote item from the local file system. Read-only. | ||
// ❌ folder Folder Indicates that the remote item is a folder. Read-only. | ||
// ✅ id String Unique identifier for the remote item in its drive. Read-only. | ||
// ❌ image Image Image metadata, if the item is an image. Read-only. | ||
// ❌ lastModifiedBy IdentitySet Identity of the user, device, and application which last modified the item. Read-only. | ||
// ✅ lastModifiedDateTime Timestamp Date and time the item was last modified. Read-only. | ||
// ✅ name String Optional. Filename of the remote item. Read-only. | ||
// ❌ package Package If present, indicates that this item is a package instead of a folder or file. Packages are treated like files in some contexts and folders in others. Read-only. | ||
// ❌ parentReference ItemReference Properties of the parent of the remote item. Read-only. | ||
// ❌ shared shared Indicates that the item has been shared with others and provides information about the shared state of the item. Read-only. | ||
// ❌ sharepointIds SharepointIds Provides interop between items in OneDrive for Business and SharePoint with the full set of item identifiers. Read-only. | ||
// ✅ size Int64 Size of the remote item. Read-only. | ||
// ❌ specialFolder specialFolder If the current item is also available as a special folder, this facet is returned. Read-only. | ||
// ❌ video Video Video metadata, if the item is a video. Read-only. | ||
// ❌ webDavUrl Url DAV compatible URL for the item. | ||
// ❌ webUrl Url URL that displays the resource in the browser. Read-only. | ||
|
||
if share.Share.Id != nil { | ||
driveItem.RemoteItem.Id = libregraph.PtrString(share.Share.Id.OpaqueId) | ||
} | ||
|
||
if share.Share.Creator != nil { | ||
if getUserResponse, err := gatewayClient.GetUser(ctx, &userpb.GetUserRequest{ | ||
UserId: &userpb.UserId{ | ||
OpaqueId: share.Share.Creator.OpaqueId, | ||
}, | ||
SkipFetchingUserGroups: true, | ||
}); err != nil { | ||
// fixMe: return err!? | ||
continue | ||
} else { | ||
user := libregraph.NewIdentityWithDefaults() | ||
user.SetId(getUserResponse.GetUser().GetId().GetOpaqueId()) | ||
user.SetDisplayName(getUserResponse.GetUser().GetDisplayName()) | ||
|
||
// fixMe: | ||
// - IdentitySet Application | ||
// - IdentitySet Device | ||
// - IdentitySet Group | ||
driveItem.RemoteItem.CreatedBy = &libregraph.IdentitySet{ | ||
User: user, | ||
} | ||
} | ||
} | ||
|
||
if share.Share.Ctime != nil { | ||
driveItem.RemoteItem.CreatedDateTime = libregraph.PtrTime(cs3TimestampToTime(share.Share.Ctime)) | ||
} | ||
|
||
if share.Share.Mtime != nil { | ||
driveItem.RemoteItem.LastModifiedDateTime = libregraph.PtrTime(cs3TimestampToTime(share.Share.Mtime)) | ||
} | ||
|
||
driveItem.RemoteItem.Size = libregraph.PtrInt64(int64(stat.Info.Size)) | ||
|
||
if name := path.Base(stat.Info.Path); name != "" { | ||
driveItem.RemoteItem.Name = libregraph.PtrString(name) | ||
} | ||
|
||
driveItems = append(driveItems, *driveItem) | ||
} | ||
|
||
return driveItems, nil | ||
} |
Oops, something went wrong.