Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of /me/drives/sharedByMe endpoint #7239

Merged
merged 6 commits into from Nov 6, 2023

Conversation

rhafer
Copy link
Contributor

@rhafer rhafer commented Sep 6, 2023

This adds a (still incomplete) implementation of the new /me/drives/sharedByMe endpoint.

Still missing / clarifications needed:

  • Populating the 'roles' property of the permissions
  • Clarify 'roles' vs. 'types'. add Sharing NG endpoints libre-graph-api#112 isn't exactly clear about this. The examples contains 'roles' for links instead or 'type' as defined for MS graph.
  • Populating the 'displayName' property of the users/groups in the permission.
  • Are reshares supposed to be exposed for the original share creator? Probably not. According to add Sharing NG endpoints libre-graph-api#112 /me/drive/sharedByMe only includes shares created by the current user.
  • Optimization: Add concurrency to the Stat() calls and User lookups.
  • more ...

IMO the open items should be tackled in follow-up pull-request. To keep this PR from growing to big.

@rhafer rhafer requested a review from butonic September 6, 2023 12:50
@rhafer rhafer self-assigned this Sep 6, 2023
@update-docs
Copy link

update-docs bot commented Sep 6, 2023

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@sonarcloud
Copy link

sonarcloud bot commented Sep 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@rhafer
Copy link
Contributor Author

rhafer commented Sep 6, 2023

converting to draft, as we need to finish the spec PR first.

@rhafer rhafer marked this pull request as draft September 6, 2023 12:55
@rhafer rhafer force-pushed the graph-sharedbyme branch 9 times, most recently from 086b7b4 to edc885f Compare October 24, 2023 11:47
@rhafer rhafer marked this pull request as ready for review October 24, 2023 14:39
@rhafer rhafer requested review from micbar and kobergj October 24, 2023 14:42
Copy link
Collaborator

@kobergj kobergj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a very heretic question: Could we use generics to make listUserShares and listPublicShares (or cs3UserSharesToDriveItem and cs3UserSharesToDriveItem) more DRY? (not saying that we should just asking if we could 😉 )

services/graph/pkg/service/v0/sharedbyme.go Show resolved Hide resolved
services/graph/pkg/service/v0/sharedbyme.go Outdated Show resolved Hide resolved
}

render.Status(r, http.StatusOK)
render.JSON(w, r, &ListResponse{Value: res})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we sort the response list so we have reproducible return values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. Should we? I don't think we're doing that elsewhere. Somehow I think we shouldn't. It would only result in clients expecting the results to be returned in a specific order.

if err != nil {
return driveItems, errorcode.New(errorcode.GeneralException, err.Error())
}
if lsUserSharesResponse.Status.Code != rpc.Code_CODE_OK {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if lsUserSharesResponse.Status.Code != rpc.Code_CODE_OK {
if lsUserSharesResponse.GetStatus().GetCode() != rpc.Code_CODE_OK {

use getters to avoid panics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return driveItems, errorcode.New(errorcode.GeneralException, err.Error())
}
if lsUserSharesResponse.Status.Code != rpc.Code_CODE_OK {
return driveItems, errorcode.New(errorcode.GeneralException, lsUserSharesResponse.Status.Message)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convert lsUserSharesResponse.GetStatus().GetCode() to a http status code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

services/graph/pkg/service/v0/sharedbyme.go Outdated Show resolved Hide resolved
services/graph/pkg/service/v0/sharedbyme.go Outdated Show resolved Hide resolved
Comment on lines 146 to 139
case rpc.Code_CODE_NOT_FOUND:
g.logger.Warn().Str("userid", s.Grantee.GetUserId().GetOpaqueId()).Msg("User not found by id")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return an error? Avoid calling grantedTo.SetUser(*user)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 returning an error is probably not right. That would result in the GetSharedByMe to error out just because a single grantee does not exist anymore.

IMO we should just log a warning (like a do now). Though it is debatable if we should return a permission with just the userid (and no displayname) or if we should skip grantees in this case.

services/graph/pkg/service/v0/sharedbyme.go Show resolved Hide resolved
services/graph/pkg/service/v0/sharedbyme.go Outdated Show resolved Hide resolved
@rhafer rhafer force-pushed the graph-sharedbyme branch 4 times, most recently from 708c78b to 51e173d Compare November 3, 2023 10:03
This adds a still incomplete implementation of the new /me/drives/sharedByMe
endpoint. For now it only sets the driveItem Id property. The 'permissions' relation
is not supported yet.

This endpoint is added to the /v1beta1 route, to indicate that it is
still imcomplete and might require changes.
getDriveItem does a Stat() call on the resource and sets the
corresponding DriveItem properties.
Set the exipration date, grantedToV2 and link attributes on the
permissions.

The displayName for users and groups isn't expanded yet (only the "id" is set)
Also, the "roles" attribute cannot be populated yet.
Copy link

sonarcloud bot commented Nov 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

76.1% 76.1% Coverage
3.9% 3.9% Duplication

@micbar micbar mentioned this pull request Nov 6, 2023
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants