diff --git a/pkg/user/error.go b/pkg/user/error.go index 750a1bcc7..2903f193c 100644 --- a/pkg/user/error.go +++ b/pkg/user/error.go @@ -532,3 +532,30 @@ func (err *ErrUsernameMustNotContainSpaces) HTTPError() web.HTTPError { Message: "The username must not contain spaces.", } } + +// ErrMustNotBeLinkShare represents a "MustNotBeLinkShare" kind of error. +type ErrMustNotBeLinkShare struct { + Username string +} + +// IsErrMustNotBeLinkShare checks if an error is a ErrMustNotBeLinkShare. +func IsErrMustNotBeLinkShare(err error) bool { + _, ok := err.(*ErrMustNotBeLinkShare) + return ok +} + +func (err *ErrMustNotBeLinkShare) Error() string { + return "user must be a *User, not a *models.LinkSharing" +} + +// ErrCodeMustNotBeLinkShare holds the unique world-error code of this error +const ErrCodeMustNotBeLinkShare = 1023 + +// HTTPError holds the http error description +func (err *ErrMustNotBeLinkShare) HTTPError() web.HTTPError { + return web.HTTPError{ + HTTPCode: http.StatusForbidden, + Code: ErrCodeMustNotBeLinkShare, + Message: "You can't do that as a link share.", + } +} diff --git a/pkg/user/user.go b/pkg/user/user.go index e18558532..2c96dc42b 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -186,7 +186,11 @@ func (u *User) GetFailedPasswordAttemptsKey() string { func GetFromAuth(a web.Auth) (*User, error) { u, is := a.(*User) if !is { - return &User{}, fmt.Errorf("user is not user element, is %s", reflect.TypeOf(a)) + typ := reflect.TypeOf(a) + if typ.String() == "*models.LinkSharing" { + return nil, &ErrMustNotBeLinkShare{} + } + return &User{}, fmt.Errorf("user is not user element, is %s", typ) } return u, nil }