mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
fix: proper error message when user (and other objects) not found (#337)
* fix: proper error message when user not found by loginname * add more not found and fix some typos
This commit is contained in:
parent
b7298bed1e
commit
26634505ba
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
@ -15,6 +16,9 @@ func IamMemberByIDs(db *gorm.DB, table, orgID, userID string) (*model.IamMemberV
|
||||
userIDQuery := &model.IamMemberSearchQuery{Key: iam_model.IamMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, orgIDQuery, userIDQuery)
|
||||
err := query(db, member)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Ahq2s", "Errors.Iam.MemberNotExisting")
|
||||
}
|
||||
return member, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
org_model "github.com/caos/zitadel/internal/org/model"
|
||||
"github.com/caos/zitadel/internal/org/repository/view/model"
|
||||
@ -14,6 +15,9 @@ func OrgDomainByOrgIDAndDomain(db *gorm.DB, table, orgID, domain string) (*model
|
||||
domainQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyDomain, Value: domain, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, orgIDQuery, domainQuery)
|
||||
err := query(db, domainView)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Gqwfq", "Errors.Org.DomainNotOnOrg")
|
||||
}
|
||||
return domainView, err
|
||||
}
|
||||
|
||||
@ -23,6 +27,9 @@ func VerifiedOrgDomain(db *gorm.DB, table, domain string) (*model.OrgDomainView,
|
||||
verifiedQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyVerified, Value: true, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, domainQuery, verifiedQuery)
|
||||
err := query(db, domainView)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Tew2q", "Errors.Org.DomainNotFound")
|
||||
}
|
||||
return domainView, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
org_model "github.com/caos/zitadel/internal/org/model"
|
||||
"github.com/caos/zitadel/internal/org/repository/view/model"
|
||||
@ -15,6 +16,9 @@ func OrgMemberByIDs(db *gorm.DB, table, orgID, userID string) (*model.OrgMemberV
|
||||
userIDQuery := &model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, orgIDQuery, userIDQuery)
|
||||
err := query(db, member)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-DG1qh", "Errors.Org.MemberNotFound")
|
||||
}
|
||||
return member, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
org_model "github.com/caos/zitadel/internal/org/model"
|
||||
"github.com/caos/zitadel/internal/org/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
@ -11,6 +12,9 @@ func OrgByID(db *gorm.DB, table, orgID string) (*model.OrgView, error) {
|
||||
org := new(model.OrgView)
|
||||
query := repository.PrepareGetByKey(table, model.OrgSearchKey(org_model.OrgSearchKeyOrgID), orgID)
|
||||
err := query(db, org)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-GEwea", "Errors.Org.NotFound")
|
||||
}
|
||||
return org, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/caos/zitadel/internal/project/repository/view/model"
|
||||
@ -12,6 +13,9 @@ func ApplicationByID(db *gorm.DB, table, appID string) (*model.ApplicationView,
|
||||
app := new(model.ApplicationView)
|
||||
query := repository.PrepareGetByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyAppID), appID)
|
||||
err := query(db, app)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-DGdfx", "Errors.Application.NotFound")
|
||||
}
|
||||
return app, err
|
||||
}
|
||||
|
||||
@ -20,6 +24,9 @@ func ApplicationByOIDCClientID(db *gorm.DB, table, clientID string) (*model.Appl
|
||||
clientIDQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyOIDCClientID, Value: clientID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, clientIDQuery)
|
||||
err := query(db, app)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-DG1qh", "Errors.Project.AppNotFound")
|
||||
}
|
||||
return app, err
|
||||
}
|
||||
|
||||
@ -29,6 +36,9 @@ func ApplicationByProjectIDAndAppName(db *gorm.DB, table, projectID, appName str
|
||||
appNameQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyName, Value: appName, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, projectIDQuery, appNameQuery)
|
||||
err := query(db, app)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Jqw1z", "Errors.Project.AppNotFound")
|
||||
}
|
||||
return app, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/caos/zitadel/internal/project/repository/view/model"
|
||||
@ -15,6 +16,9 @@ func ProjectGrantMemberByIDs(db *gorm.DB, table, grantID, userID string) (*model
|
||||
userIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, grantIDQuery, userIDQuery)
|
||||
err := query(db, role)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Sgr32", "Errors.Project.MemberNotExisting")
|
||||
}
|
||||
return role, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/caos/zitadel/internal/project/repository/view/model"
|
||||
@ -15,6 +16,9 @@ func ProjectGrantByProjectAndOrg(db *gorm.DB, table, projectID, orgID string) (*
|
||||
orgIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyOrgID, Value: orgID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, projectIDQuery, orgIDQuery)
|
||||
err := query(db, projectGrant)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-WR3z2", "Errors.Project.GrantNotExists")
|
||||
}
|
||||
return projectGrant, err
|
||||
}
|
||||
|
||||
@ -23,6 +27,9 @@ func ProjectGrantByID(db *gorm.DB, table, grantID string) (*model.ProjectGrantVi
|
||||
grantIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Value: grantID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, grantIDQuery)
|
||||
err := query(db, projectGrant)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-EGdh4", "Errors.Project.GrantNotFound")
|
||||
}
|
||||
return projectGrant, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/caos/zitadel/internal/project/repository/view/model"
|
||||
@ -15,6 +16,9 @@ func ProjectMemberByIDs(db *gorm.DB, table, projectID, userID string) (*model.Pr
|
||||
userIDQuery := model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, projectIDQuery, userIDQuery)
|
||||
err := query(db, role)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-EgWQ2", "Errors.Project.MemberNotExisting")
|
||||
}
|
||||
return role, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/caos/zitadel/internal/project/repository/view/model"
|
||||
@ -16,6 +17,9 @@ func ProjectRoleByIDs(db *gorm.DB, table, projectID, orgID, key string) (*model.
|
||||
keyQuery := model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyKey, Value: key, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, projectIDQuery, grantIDQuery, keyQuery)
|
||||
err := query(db, role)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Wtg72", "Errors.Project.RoleNotExisting")
|
||||
}
|
||||
return role, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/caos/zitadel/internal/project/repository/view/model"
|
||||
@ -14,6 +15,9 @@ func ProjectByID(db *gorm.DB, table, projectID string) (*model.ProjectView, erro
|
||||
projectIDQuery := model.ProjectSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, projectIDQuery)
|
||||
err := query(db, project)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-NEO7W", "Errors.Project.NotFound")
|
||||
}
|
||||
return project, err
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ Errors:
|
||||
InvalidDomain: Domäne ist ungültig
|
||||
DomainMissing: Domäne fehlt
|
||||
DomainNotOnOrg: Domäne fehlt auf Organisation
|
||||
DomainNotFound: Domäne konnte nicht gefunden werden
|
||||
MemberIDMissing: Member ID fehlt
|
||||
MemberNotFound: Organisations Member konnte nicht gefunden werden
|
||||
InvalidMember: Organisations Member ist ungültig
|
||||
@ -69,6 +70,7 @@ Errors:
|
||||
Invalid: Projekt ist ungültig
|
||||
NotActive: Projekt ist nicht aktiv
|
||||
NotInactive: Projekt ist nicht deaktiviert
|
||||
NotFound: Project konnte nicht gefunden werden
|
||||
UserIDMissing: User ID fehlt
|
||||
MemberNotFound: Member konnte nicht gefunden werden
|
||||
MemberInvalid: Member ist ungültig
|
||||
@ -107,4 +109,8 @@ Errors:
|
||||
NotActive: Benutzer Berechtigung ist nicht aktiv
|
||||
NotInactive: Benutzer Berechtigung ist nicht deaktiviert
|
||||
Changes:
|
||||
NotFound: Es konnte kein Änderungsverlauf gefunden werden
|
||||
NotFound: Es konnte kein Änderungsverlauf gefunden werden
|
||||
Token:
|
||||
NotFound: Token konnte nicht gefunden werden
|
||||
UserSession:
|
||||
NotFound: UserSession konnte nicht gefunden werden
|
@ -54,6 +54,7 @@ Errors:
|
||||
InvalidDomain: Invalid domain
|
||||
DomainMissing: Domain missing
|
||||
DomainNotOnOrg: Domain doesn't exist on organisation
|
||||
DomainNotFound: Domain not found
|
||||
MemberIDMissing: Member ID missing
|
||||
MemberNotFound: Organisations member not found
|
||||
InvalidMember: Organisation member is invalid
|
||||
@ -68,12 +69,13 @@ Errors:
|
||||
CouldNotGenerateClientSecret: Could not generate client secret
|
||||
Invalid: Project is invalid
|
||||
NotActive: Project is not active
|
||||
NotInactive: Projekt is not deactivated
|
||||
NotInactive: Project is not deactivated
|
||||
NotFound: Porject not found
|
||||
UserIDMissing: User ID missing
|
||||
MemberNotFound: Project member not found
|
||||
MemberInvalid: Project member is invalid
|
||||
MemberAlreadyExists: Project member already exists
|
||||
MemberNotExisting: Projekt member doesn't exist
|
||||
MemberNotExisting: Project member doesn't exist
|
||||
MinimumOneRoleNeeded: At least one role should be added
|
||||
RoleAlreadyExists: Role already exists
|
||||
RoleInvalid: Role is invalid
|
||||
@ -107,4 +109,8 @@ Errors:
|
||||
NotActive: User grant is not active
|
||||
NotInactive: User grant is not deactivated
|
||||
Changes:
|
||||
NotFound: No history found
|
||||
NotFound: No history found
|
||||
Token:
|
||||
NotFound: Token not found
|
||||
UserSession:
|
||||
NotFound: UserSession not found
|
@ -1,7 +1,6 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
@ -10,12 +9,16 @@ import (
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
token_model "github.com/caos/zitadel/internal/token/model"
|
||||
"github.com/caos/zitadel/internal/token/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
func TokenByID(db *gorm.DB, table, tokenID string) (*model.Token, error) {
|
||||
token := new(model.Token)
|
||||
query := repository.PrepareGetByKey(table, model.TokenSearchKey(token_model.TokenSearchKeyTokenID), tokenID)
|
||||
err := query(db, token)
|
||||
if errors.IsNotFound(err) {
|
||||
return nil, errors.ThrowNotFound(nil, "VIEW-Nqwf1", "Errors.Token.NotFound")
|
||||
}
|
||||
return token, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
usr_model "github.com/caos/zitadel/internal/user/model"
|
||||
"github.com/caos/zitadel/internal/user/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
@ -11,6 +12,9 @@ func NotifyUserByID(db *gorm.DB, table, userID string) (*model.NotifyUser, error
|
||||
user := new(model.NotifyUser)
|
||||
query := repository.PrepareGetByKey(table, model.UserSearchKey(usr_model.NotifyUserSearchKeyUserID), userID)
|
||||
err := query(db, user)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Gad31", "Errors.User.NotFound")
|
||||
}
|
||||
return user, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
@ -23,6 +24,9 @@ func UserSessionByIDs(db *gorm.DB, table, agentID, userID string) (*model.UserSe
|
||||
}
|
||||
query := repository.PrepareGetByQuery(table, userAgentQuery, userQuery)
|
||||
err := query(db, userSession)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-NGBs1", "Errors.UserSession.NotFound")
|
||||
}
|
||||
return userSession, err
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,9 @@ func UserByLoginName(db *gorm.DB, table, loginName string) (*model.UserView, err
|
||||
}
|
||||
query := repository.PrepareGetByQuery(table, loginNameQuery)
|
||||
err := query(db, user)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-AD4qs", "Errors.User.NotFound")
|
||||
}
|
||||
return user, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
global_model "github.com/caos/zitadel/internal/model"
|
||||
grant_model "github.com/caos/zitadel/internal/usergrant/model"
|
||||
"github.com/caos/zitadel/internal/usergrant/repository/view/model"
|
||||
@ -12,6 +13,9 @@ func UserGrantByID(db *gorm.DB, table, grantID string) (*model.UserGrantView, er
|
||||
user := new(model.UserGrantView)
|
||||
query := repository.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID)
|
||||
err := query(db, user)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Nqwf1", "Errors.Token.NotFound")
|
||||
}
|
||||
return user, err
|
||||
}
|
||||
|
||||
@ -23,6 +27,9 @@ func UserGrantByIDs(db *gorm.DB, table, resourceOwnerID, projectID, userID strin
|
||||
userIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, resourceOwnerIDQuery, projectIDQuery, userIDQuery)
|
||||
err := query(db, user)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Q1tq2", "Errors.UserGrant.NotFound")
|
||||
}
|
||||
return user, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user