Use the stored guest id when returning an invite permission

The share provider now stores the guest's mail address in its canonical
form, so build the returned identity from the created share instead of
the request.
This commit is contained in:
André Duffeck committed 2026-10-07 12:45:13 +02:00
1 parent 3134526824
commit 08edebc66c
2 files changed
+30 -2

No files matched your search

@@ -182,7 +182,8 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId *sto
cTime = createShareResponse.GetShare().GetCtime()
expiration = createShareResponse.GetShare().GetExpiration()
guestIdentity, err := cs3UserIdToIdentity(ctx, s.identityCache, createShareRequest.GetGrant().GetGrantee().GetUserId())
// the share provider stores the guest's mail address in its canonical form
guestIdentity, err := cs3UserIdToIdentity(ctx, s.identityCache, createShareResponse.GetShare().GetGrantee().GetUserId())
if err != nil {
s.logger.Debug().Err(err).Msg("failed to convert guest user id to identity")
return libregraph.Permission{}, err
@@ -176,7 +176,8 @@ var _ = Describe("DriveItemPermissionsService", func() {
{Email: libregraph.PtrString("guest@example.com")},
}
createShareResponse.Share = &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: "guest123"},
Id: &collaboration.ShareId{OpaqueId: "guest123"},
Grantee: guestGrantee("guest@example.com"),
}
permission, err := driveItemPermissionsService.Invite(ctx, driveItemId, driveItemInvite)
@@ -187,6 +188,23 @@ var _ = Describe("DriveItemPermissionsService", func() {
Expect(permission.GrantedToV2.User.GetLibreGraphUserType()).To(Equal("Guest"))
})
It("returns the guest id as stored by the share provider", func() {
cfg.Commons = &shared.Commons{EnableGuestLinks: true}
gatewayClient.On("GetUser", mock.Anything, mock.Anything).Return(getUserResponse, nil)
gatewayClient.On("CreateShare", mock.Anything, mock.Anything).Return(createShareResponse, nil)
driveItemInvite.Recipients = []libregraph.DriveRecipient{
{Email: libregraph.PtrString("Guest@\u0130nfocorp.com")},
}
createShareResponse.Share = &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: "guest123"},
Grantee: guestGrantee("guest@xn--infocorp-o0e.com"),
}
permission, err := driveItemPermissionsService.Invite(ctx, driveItemId, driveItemInvite)
Expect(err).ToNot(HaveOccurred())
Expect(permission.GrantedToV2.User.GetId()).To(Equal("guest@xn--infocorp-o0e.com"))
})
It("rejects guest shares when guest invites are disabled by default", func() {
driveItemInvite.Recipients = []libregraph.DriveRecipient{
{Email: libregraph.PtrString("guest@example.com")},
@@ -1477,3 +1495,12 @@ var _ = Describe("DriveItemPermissionsApi", func() {
})
})
})
func guestGrantee(mail string) *provider.Grantee {
return &provider.Grantee{
Type: provider.GranteeType_GRANTEE_TYPE_USER,
Id: &provider.Grantee_UserId{
UserId: &userpb.UserId{Type: userpb.UserType_USER_TYPE_GUEST, OpaqueId: mail},
},
}
}