fix sharing invite on virtual drive

This commit is contained in:
Roman Perekhod
2024-03-12 14:29:18 +01:00
committed by Ralf Haferkamp
parent 70fa8d96fe
commit e5ba9a630f
9 changed files with 33 additions and 34 deletions

View File

@@ -136,28 +136,16 @@ func (s *service) Authenticate(ctx context.Context, req *provider.AuthenticateRe
password := req.ClientSecret
u, scope, err := s.authmgr.Authenticate(ctx, username, password)
switch v := err.(type) {
case nil:
log.Info().Msgf("user %s authenticated", u.Id)
if err != nil {
log.Debug().Str("client_id", username).Err(err).Msg("authsvc: error in Authenticate")
return &provider.AuthenticateResponse{
Status: status.NewOK(ctx),
User: u,
TokenScope: scope,
}, nil
case errtypes.InvalidCredentials:
return &provider.AuthenticateResponse{
Status: status.NewPermissionDenied(ctx, v, "wrong password"),
}, nil
case errtypes.NotFound:
log.Debug().Str("client_id", username).Msg("unknown client id")
return &provider.AuthenticateResponse{
Status: status.NewNotFound(ctx, "unknown client id"),
}, nil
default:
err = errors.Wrap(err, "authsvc: error in Authenticate")
return &provider.AuthenticateResponse{
Status: status.NewUnauthenticated(ctx, err, "error authenticating user"),
Status: status.NewStatusFromErrType(ctx, "authsvc: error in Authenticate", err),
}, nil
}
log.Info().Msgf("user %s authenticated", u.Id)
return &provider.AuthenticateResponse{
Status: status.NewOK(ctx),
User: u,
TokenScope: scope,
}, nil
}

View File

@@ -38,6 +38,7 @@ import (
const (
_spaceTypePersonal = "personal"
_spaceTypeProject = "project"
_spaceTypeVirtual = "virtual"
)
func init() {

View File

@@ -583,8 +583,8 @@ func (s *svc) addShare(ctx context.Context, req *collaboration.CreateShareReques
func (s *svc) addSpaceShare(ctx context.Context, req *collaboration.CreateShareRequest) (*collaboration.CreateShareResponse, error) {
if refIsSpaceRoot(req.GetResourceInfo().GetId()) &&
req.GetResourceInfo().GetSpace().GetSpaceType() == _spaceTypePersonal {
return nil, errors.New("gateway: space type is not eligible for sharing")
(req.GetResourceInfo().GetSpace().GetSpaceType() == _spaceTypePersonal || req.GetResourceInfo().GetSpace().GetSpaceType() == _spaceTypeVirtual) {
return &collaboration.CreateShareResponse{Status: status.NewInvalid(ctx, "space type is not eligible for sharing")}, nil
}
// If the share is a denial we call denyGrant instead.
var st *rpc.Status

View File

@@ -144,7 +144,7 @@ func (e BadRequest) Error() string { return "error: bad request: " + string(e) }
// IsBadRequest implements the IsBadRequest interface.
func (e BadRequest) IsBadRequest() {}
// ChecksumMismatch is the error to use when the sent hash does not match the calculated hash.
// ChecksumMismatch is the error to use when the transmitted hash does not match the calculated hash.
type ChecksumMismatch string
func (e ChecksumMismatch) Error() string { return "error: checksum mismatch: " + string(e) }
@@ -178,7 +178,7 @@ type NotModified string
func (e NotModified) Error() string { return "error: not modified: " + string(e) }
// NotModified implements the IsNotModified interface.
// IsNotModified implements the IsNotModified interface.
func (e NotModified) IsNotModified() {}
// StatusCode returns StatusInsufficientStorage, this implementation is needed to allow TUS to cast the correct http errors.
@@ -196,7 +196,7 @@ func (e InsufficientStorage) Body() []byte {
const StatusInsufficientStorage = 507
// IsNotFound is the interface to implement
// to specify that an a resource is not found.
// to specify that a resource is not found.
type IsNotFound interface {
IsNotFound()
}
@@ -238,7 +238,7 @@ type IsPermissionDenied interface {
}
// IsLocked is the interface to implement
// to specify that an resource is locked.
// to specify that a resource is locked.
type IsLocked interface {
IsLocked()
}
@@ -279,7 +279,7 @@ type IsInsufficientStorage interface {
IsInsufficientStorage()
}
// NewErrtypeFromStatus maps an rpc status to an errtype
// NewErrtypeFromStatus maps a rpc status to an errtype
func NewErrtypeFromStatus(status *rpc.Status) error {
switch status.Code {
case rpc.Code_CODE_OK:
@@ -318,7 +318,7 @@ func NewErrtypeFromStatus(status *rpc.Status) error {
}
}
// NewErrtypeFromHTTPStatusCode maps an http status to an errtype
// NewErrtypeFromHTTPStatusCode maps a http status to an errtype
func NewErrtypeFromHTTPStatusCode(code int, message string) error {
switch code {
case http.StatusOK:
@@ -352,7 +352,7 @@ func NewErrtypeFromHTTPStatusCode(code int, message string) error {
}
}
// NewHTTPStatusCodeFromErrtype maps an errtype to an http status
// NewHTTPStatusCodeFromErrtype maps an errtype to a http status
func NewHTTPStatusCodeFromErrtype(err error) int {
switch err.(type) {
case NotFound:

View File

@@ -166,10 +166,14 @@ func NewStatusFromErrType(ctx context.Context, msg string, err error) *rpc.Statu
switch e := err.(type) {
case nil:
return NewOK(ctx)
case errtypes.NotFound:
return NewNotFound(ctx, msg+": "+err.Error())
case errtypes.IsNotFound:
return NewNotFound(ctx, msg+": "+err.Error())
case errtypes.AlreadyExists:
return NewAlreadyExists(ctx, err, msg+": "+err.Error())
case errtypes.InvalidCredentials:
return NewPermissionDenied(ctx, e, msg+": "+err.Error())
case errtypes.IsInvalidCredentials:
// TODO this maps badly
return NewUnauthenticated(ctx, err, msg+": "+err.Error())