diff --git a/docs/content/doc/usage/errors.md b/docs/content/doc/usage/errors.md index faf4ef548..9dabb288c 100644 --- a/docs/content/doc/usage/errors.md +++ b/docs/content/doc/usage/errors.md @@ -111,6 +111,11 @@ This document describes the different errors Vikunja can return. | 6005 | 409 | The user is already a member of that team. | | 6006 | 400 | Cannot delete the last team member. | | 6007 | 403 | The team does not have access to the list to perform that action. | +| 6008 | 400 | There are no teams found with that team name | +| 6009 | 400 | There is no oidc team with that team name and oidcId | +| 6010 | 400 | There are no oidc teams found for the user | + + ## User List Access diff --git a/pkg/models/error.go b/pkg/models/error.go index c0d21de92..c343ad38c 100644 --- a/pkg/models/error.go +++ b/pkg/models/error.go @@ -1194,22 +1194,46 @@ type ErrTeamsDoNotExist struct { Name string } -// IsErrTeamDoNotExist checks if an error is ErrTeamDoesNotExist. +// IsErrTeamsDoNotExist checks if an error is ErrTeamsDoNotExist. func IsErrTeamsDoNotExist(err error) bool { _, ok := err.(ErrTeamsDoNotExist) return ok } func (err ErrTeamsDoNotExist) Error() string { - return fmt.Sprintf("Team does not exist [Team Name: %v]", err.Name) + return fmt.Sprintf("No teams with that name exist [Team Name: %v]", err.Name) } -// ErrCodeTeamDoesNotExist holds the unique world-error code of this error +// ErrCodeTeamsDoesNotExist holds the unique world-error code of this error const ErrCodeTeamsDoNotExist = 6008 // HTTPError holds the http error description func (err ErrTeamsDoNotExist) HTTPError() web.HTTPError { - return web.HTTPError{HTTPCode: http.StatusNotFound, Code: ErrCodeTeamDoesNotExist, Message: "No team with given name exists."} + return web.HTTPError{HTTPCode: http.StatusNotFound, Code: ErrCodeTeamDoesNotExist, Message: "No teams with that name exist"} +} + +// ErrOIDCTeamDoesNotExist represents an error where a team with specified name and specified oidcId property does not exist +type ErrOIDCTeamDoesNotExist struct { + OidcId string + Name string +} + +// IsErrOIDCTeamDoesNotExist checks if an error is ErrOIDCTeamDoesNotExist. +func IsErrOIDCTeamDoesNotExist(err error) bool { + _, ok := err.(ErrOIDCTeamDoesNotExist) + return ok +} + +func (err ErrOIDCTeamDoesNotExist) Error() string { + return fmt.Sprintf("No Team with that name and valid property oidcId could be found [Team Name: %v] [OidcId : %v] ", err.Name, err.OidcId) +} + +// ErrCodeTeamDoesNotExist holds the unique world-error code of this error +const ErrCodeOIDCTeamDoesNotExist = 6009 + +// HTTPError holds the http error description +func (err ErrOIDCTeamDoesNotExist) HTTPError() web.HTTPError { + return web.HTTPError{HTTPCode: http.StatusNotFound, Code: ErrCodeTeamDoesNotExist, Message: "No Team with that name and valid property oidcId could be found."} } // ErrOIDCTeamsDoNotExistForUser represents an error where an oidcTeam does not exist for the user @@ -1219,20 +1243,20 @@ type ErrOIDCTeamsDoNotExistForUser struct { // IsErrOIDCTeamsDoNotExistForUser checks if an error is ErrOIDCTeamsDoNotExistForUser. func IsErrOIDCTeamsDoNotExistForUser(err error) bool { - _, ok := err.(ErrTeamDoesNotExist) + _, ok := err.(ErrOIDCTeamsDoNotExistForUser) return ok } func (err ErrOIDCTeamsDoNotExistForUser) Error() string { - return fmt.Sprintf("No Oidc exists for User [User ID: %d]", err.UserID) + return fmt.Sprintf("No Teams with property oidcId could be found for User [User ID: %d]", err.UserID) } // ErrCodeTeamDoesNotExist holds the unique world-error code of this error -const ErrCodeOIDCTeamsDoNotExistForUser = 6009 +const ErrCodeOIDCTeamsDoNotExistForUser = 6010 // HTTPError holds the http error description func (err ErrOIDCTeamsDoNotExistForUser) HTTPError() web.HTTPError { - return web.HTTPError{HTTPCode: http.StatusNotFound, Code: ErrCodeTeamDoesNotExist, Message: "This team does not exist."} + return web.HTTPError{HTTPCode: http.StatusNotFound, Code: ErrCodeTeamDoesNotExist, Message: "No Teams with property oidcId could be found for User."} } // ==================== diff --git a/pkg/models/teams.go b/pkg/models/teams.go index 9becb12a6..37917d4e2 100644 --- a/pkg/models/teams.go +++ b/pkg/models/teams.go @@ -158,7 +158,7 @@ func GetTeamByOidcIDAndName(s *xorm.Session, oidcID string, teamName string) (te if exists && err == nil { return team, nil } - return team, ErrTeamsDoNotExist{oidcID} + return team, ErrOIDCTeamDoesNotExist{teamName, oidcID} } func FindAllOidcTeamIDsForUser(s *xorm.Session, userID int64) (ts []int64, err error) {