Skip to content

Commit

Permalink
feat(auth): always indicate public link user
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Sep 19, 2024
1 parent d445295 commit b3e9bd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-publiclink-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Populate public link user correctly

When authenticating via public link, always add the `public` user instead of the link owner

https://github.com/cs3org/reva/pull/4852
42 changes: 22 additions & 20 deletions pkg/auth/manager/publicshares/publicshares.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

authpb "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1"
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
userprovider "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
Expand Down Expand Up @@ -127,26 +126,29 @@ func (m *manager) Authenticate(ctx context.Context, token, secret string) (*user
return nil, nil, errtypes.InternalError(publicShareResponse.Status.Message)
}

var owner *user.User
// FIXME use new user type SPACE_OWNER
if publicShareResponse.GetShare().GetOwner().GetType() == 8 {
owner = &user.User{Id: publicShareResponse.GetShare().GetOwner(), DisplayName: "Public", Username: "public"}
} else {
getUserResponse, err := gwConn.GetUser(ctx, &userprovider.GetUserRequest{
UserId: publicShareResponse.GetShare().GetCreator(),
})
switch {
case err != nil:
return nil, nil, err
case getUserResponse.GetStatus().GetCode() == rpcv1beta1.Code_CODE_NOT_FOUND:
return nil, nil, errtypes.NotFound(getUserResponse.GetStatus().GetMessage())
case getUserResponse.GetStatus().GetCode() == rpcv1beta1.Code_CODE_PERMISSION_DENIED:
return nil, nil, errtypes.InvalidCredentials(getUserResponse.GetStatus().GetMessage())
case getUserResponse.GetStatus().GetCode() != rpcv1beta1.Code_CODE_OK:
return nil, nil, errtypes.InternalError(getUserResponse.GetStatus().GetMessage())
owner := &user.User{Id: publicShareResponse.GetShare().GetOwner(), DisplayName: "Public", Username: "public"}
/*
var owner *user.User
// FIXME use new user type SPACE_OWNER
if publicShareResponse.GetShare().GetOwner().GetType() == 8 {
owner = &user.User{Id: publicShareResponse.GetShare().GetOwner(), DisplayName: "Public", Username: "public"}
} else {
getUserResponse, err := gwConn.GetUser(ctx, &userprovider.GetUserRequest{
UserId: publicShareResponse.GetShare().GetCreator(),
})
switch {
case err != nil:
return nil, nil, err
case getUserResponse.GetStatus().GetCode() == rpcv1beta1.Code_CODE_NOT_FOUND:
return nil, nil, errtypes.NotFound(getUserResponse.GetStatus().GetMessage())
case getUserResponse.GetStatus().GetCode() == rpcv1beta1.Code_CODE_PERMISSION_DENIED:
return nil, nil, errtypes.InvalidCredentials(getUserResponse.GetStatus().GetMessage())
case getUserResponse.GetStatus().GetCode() != rpcv1beta1.Code_CODE_OK:
return nil, nil, errtypes.InternalError(getUserResponse.GetStatus().GetMessage())
}
owner = getUserResponse.GetUser()
}
owner = getUserResponse.GetUser()
}
*/

share := publicShareResponse.GetShare()
role := authpb.Role_ROLE_VIEWER
Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/utils/decomposedfs/upload/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func (s *OcisSession) executantUser() *userpb.User {
Idp: s.info.Storage["Idp"],
OpaqueId: s.info.Storage["UserId"],
},
Username: s.info.Storage["UserName"],
Username: s.info.Storage["UserName"],
DisplayName: s.info.Storage["UserDisplayName"],
}
}

Expand Down Expand Up @@ -263,6 +264,7 @@ func (s *OcisSession) SetExecutant(u *userpb.User) {
s.info.Storage["UserId"] = u.GetId().GetOpaqueId()
s.info.Storage["UserType"] = utils.UserTypeToString(u.GetId().Type)
s.info.Storage["UserName"] = u.GetUsername()
s.info.Storage["UserDisplayName"] = u.GetDisplayName()
}

// Offset returns the current upload offset
Expand Down

0 comments on commit b3e9bd6

Please sign in to comment.