fix: provide a proper error message when viewing a link share with an invalid token
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
10f71c29b2
commit
aa43127e52
|
@ -163,6 +163,7 @@ This document describes the different errors Vikunja can return.
|
||||||
## Link Shares
|
## Link Shares
|
||||||
|
|
||||||
| ErrorCode | HTTP Status Code | Description |
|
| ErrorCode | HTTP Status Code | Description |
|
||||||
|-----------|------------------|-------------|
|
|-----------|------------------|--------------------------------------------------------------------------------|
|
||||||
| 13001 | 412 | This link share requires a password for authentication, but none was provided. |
|
| 13001 | 412 | This link share requires a password for authentication, but none was provided. |
|
||||||
| 13002 | 403 | The provided link share password was invalid. |
|
| 13002 | 403 | The provided link share password is invalid. |
|
||||||
|
| 13003 | 400 | The provided link share token is invalid. |
|
||||||
|
|
|
@ -1709,3 +1709,29 @@ func (err ErrLinkSharePasswordInvalid) HTTPError() web.HTTPError {
|
||||||
Message: "The provided link share password is invalid.",
|
Message: "The provided link share password is invalid.",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrLinkShareTokenInvalid represents an error where a link share token is invalid
|
||||||
|
type ErrLinkShareTokenInvalid struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsErrLinkShareTokenInvalid checks if an error is ErrLinkShareTokenInvalid.
|
||||||
|
func IsErrLinkShareTokenInvalid(err error) bool {
|
||||||
|
_, ok := err.(*ErrLinkShareTokenInvalid)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err *ErrLinkShareTokenInvalid) Error() string {
|
||||||
|
return "Provided Link Share Token is invalid"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrCodeLinkShareTokenInvalid holds the unique world-error code of this error
|
||||||
|
const ErrCodeLinkShareTokenInvalid = 13003
|
||||||
|
|
||||||
|
// HTTPError holds the http error description
|
||||||
|
func (err ErrLinkShareTokenInvalid) HTTPError() web.HTTPError {
|
||||||
|
return web.HTTPError{
|
||||||
|
HTTPCode: http.StatusBadRequest,
|
||||||
|
Code: ErrCodeLinkShareTokenInvalid,
|
||||||
|
Message: "The provided link share token is invalid.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -86,10 +86,15 @@ func (share *LinkSharing) GetID() int64 {
|
||||||
|
|
||||||
// GetLinkShareFromClaims builds a link sharing object from jwt claims
|
// GetLinkShareFromClaims builds a link sharing object from jwt claims
|
||||||
func GetLinkShareFromClaims(claims jwt.MapClaims) (share *LinkSharing, err error) {
|
func GetLinkShareFromClaims(claims jwt.MapClaims) (share *LinkSharing, err error) {
|
||||||
|
projectID, is := claims["project_id"].(float64)
|
||||||
|
if !is {
|
||||||
|
return nil, &ErrLinkShareTokenInvalid{}
|
||||||
|
}
|
||||||
|
|
||||||
share = &LinkSharing{}
|
share = &LinkSharing{}
|
||||||
share.ID = int64(claims["id"].(float64))
|
share.ID = int64(claims["id"].(float64))
|
||||||
share.Hash = claims["hash"].(string)
|
share.Hash = claims["hash"].(string)
|
||||||
share.ProjectID = int64(claims["project_id"].(float64))
|
share.ProjectID = int64(projectID)
|
||||||
share.Right = Right(claims["right"].(float64))
|
share.Right = Right(claims["right"].(float64))
|
||||||
share.SharedByID = int64(claims["sharedByID"].(float64))
|
share.SharedByID = int64(claims["sharedByID"].(float64))
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user