Try to find users by username or id, just like the ldap backend does

This commit is contained in:
André Duffeck
2025-07-28 09:24:19 +02:00
committed by Christian Richter
parent 926a2c2080
commit b9f48edd87

View File

@@ -44,7 +44,7 @@ func (i *CS3) UpdateUser(ctx context.Context, nameOrID string, user libregraph.U
}
// GetUser implements the Backend Interface.
func (i *CS3) GetUser(ctx context.Context, userID string, _ *godata.GoDataRequest) (*libregraph.User, error) {
func (i *CS3) GetUser(ctx context.Context, nameOrId string, _ *godata.GoDataRequest) (*libregraph.User, error) {
logger := i.Logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "cs3").Msg("GetUser")
gatewayClient, err := i.GatewaySelector.Next()
@@ -53,22 +53,43 @@ func (i *CS3) GetUser(ctx context.Context, userID string, _ *godata.GoDataReques
return nil, errorcode.New(errorcode.ServiceNotAvailable, err.Error())
}
// Try to get the user by username first
res, err := gatewayClient.GetUserByClaim(ctx, &cs3user.GetUserByClaimRequest{
Claim: "userid", // FIXME add consts to reva
Value: userID,
Claim: "username", // FIXME add consts to reva
Value: nameOrId,
})
switch {
case err != nil:
logger.Error().Str("backend", "cs3").Err(err).Str("userid", userID).Msg("error sending get user by claim id grpc request: transport error")
logger.Error().Str("backend", "cs3").Err(err).Str("nameOrId", nameOrId).Msg("error sending get user by claim id grpc request: transport error")
return nil, errorcode.New(errorcode.ServiceNotAvailable, err.Error())
case res.GetStatus().GetCode() == cs3rpc.Code_CODE_OK:
return CreateUserModelFromCS3(res.GetUser()), nil
case res.GetStatus().GetCode() == cs3rpc.Code_CODE_NOT_FOUND:
// If the user was not found by username, try to get it by user ID
default:
logger.Debug().Str("backend", "cs3").Err(err).Str("nameOrId", nameOrId).Msg("error sending get user by claim id grpc request")
return nil, errorcode.New(errorcode.GeneralException, res.GetStatus().GetMessage())
}
// If the user was not found by username, try to get it by user ID
res, err = gatewayClient.GetUserByClaim(ctx, &cs3user.GetUserByClaimRequest{
Claim: "userid", // FIXME add consts to reva
Value: nameOrId,
})
switch {
case err != nil:
logger.Error().Str("backend", "cs3").Err(err).Str("nameOrId", nameOrId).Msg("error sending get user by claim id grpc request: transport error")
return nil, errorcode.New(errorcode.ServiceNotAvailable, err.Error())
case res.GetStatus().GetCode() != cs3rpc.Code_CODE_OK:
if res.GetStatus().GetCode() == cs3rpc.Code_CODE_NOT_FOUND {
return nil, errorcode.New(errorcode.ItemNotFound, res.GetStatus().GetMessage())
}
logger.Debug().Str("backend", "cs3").Err(err).Str("userid", userID).Msg("error sending get user by claim id grpc request")
logger.Debug().Str("backend", "cs3").Err(err).Str("nameOrId", nameOrId).Msg("error sending get user by claim id grpc request")
return nil, errorcode.New(errorcode.GeneralException, res.GetStatus().GetMessage())
}
return CreateUserModelFromCS3(res.GetUser()), nil
}