diff --git a/internal/iam/repository/view/iam_member_view.go b/internal/iam/repository/view/iam_member_view.go index d0cd05f067..28eb03a8c6 100644 --- a/internal/iam/repository/view/iam_member_view.go +++ b/internal/iam/repository/view/iam_member_view.go @@ -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 } diff --git a/internal/org/repository/view/org_domain_view.go b/internal/org/repository/view/org_domain_view.go index 981b425cb8..03afef8f6e 100644 --- a/internal/org/repository/view/org_domain_view.go +++ b/internal/org/repository/view/org_domain_view.go @@ -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 } diff --git a/internal/org/repository/view/org_member_view.go b/internal/org/repository/view/org_member_view.go index 7265aec7c4..196dad4172 100644 --- a/internal/org/repository/view/org_member_view.go +++ b/internal/org/repository/view/org_member_view.go @@ -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 } diff --git a/internal/org/repository/view/org_view.go b/internal/org/repository/view/org_view.go index 9ed57cc899..2a5747e18c 100644 --- a/internal/org/repository/view/org_view.go +++ b/internal/org/repository/view/org_view.go @@ -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 } diff --git a/internal/project/repository/view/application_view.go b/internal/project/repository/view/application_view.go index 9e5ef09b1b..3154f82024 100644 --- a/internal/project/repository/view/application_view.go +++ b/internal/project/repository/view/application_view.go @@ -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 } diff --git a/internal/project/repository/view/project_grant_member_view.go b/internal/project/repository/view/project_grant_member_view.go index a1ce4170ec..07dc7621db 100644 --- a/internal/project/repository/view/project_grant_member_view.go +++ b/internal/project/repository/view/project_grant_member_view.go @@ -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 } diff --git a/internal/project/repository/view/project_grant_view.go b/internal/project/repository/view/project_grant_view.go index 6e637d1899..83d5b39d82 100644 --- a/internal/project/repository/view/project_grant_view.go +++ b/internal/project/repository/view/project_grant_view.go @@ -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 } diff --git a/internal/project/repository/view/project_member_view.go b/internal/project/repository/view/project_member_view.go index 7ca6f66f50..6596893322 100644 --- a/internal/project/repository/view/project_member_view.go +++ b/internal/project/repository/view/project_member_view.go @@ -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 } diff --git a/internal/project/repository/view/project_role_view.go b/internal/project/repository/view/project_role_view.go index 90443f002f..af7b2b8299 100644 --- a/internal/project/repository/view/project_role_view.go +++ b/internal/project/repository/view/project_role_view.go @@ -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 } diff --git a/internal/project/repository/view/project_view.go b/internal/project/repository/view/project_view.go index 6711d7a307..146ae14fd0 100644 --- a/internal/project/repository/view/project_view.go +++ b/internal/project/repository/view/project_view.go @@ -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 } diff --git a/internal/static/i18n/de.yaml b/internal/static/i18n/de.yaml index c3fc79e8b2..378abbd86a 100644 --- a/internal/static/i18n/de.yaml +++ b/internal/static/i18n/de.yaml @@ -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 \ No newline at end of file + NotFound: Es konnte kein Änderungsverlauf gefunden werden + Token: + NotFound: Token konnte nicht gefunden werden + UserSession: + NotFound: UserSession konnte nicht gefunden werden \ No newline at end of file diff --git a/internal/static/i18n/en.yaml b/internal/static/i18n/en.yaml index 303625f6e9..7d80fb1a67 100644 --- a/internal/static/i18n/en.yaml +++ b/internal/static/i18n/en.yaml @@ -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 \ No newline at end of file + NotFound: No history found + Token: + NotFound: Token not found + UserSession: + NotFound: UserSession not found \ No newline at end of file diff --git a/internal/token/repository/view/token.go b/internal/token/repository/view/token.go index c9fb4c7af0..ac985390a1 100644 --- a/internal/token/repository/view/token.go +++ b/internal/token/repository/view/token.go @@ -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 } diff --git a/internal/user/repository/view/notify_user.go b/internal/user/repository/view/notify_user.go index cd0be724bf..d94c152d3e 100644 --- a/internal/user/repository/view/notify_user.go +++ b/internal/user/repository/view/notify_user.go @@ -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 } diff --git a/internal/user/repository/view/user_session_view.go b/internal/user/repository/view/user_session_view.go index d6091cdf6a..7bed501ddd 100644 --- a/internal/user/repository/view/user_session_view.go +++ b/internal/user/repository/view/user_session_view.go @@ -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 } diff --git a/internal/user/repository/view/user_view.go b/internal/user/repository/view/user_view.go index f61af06a6b..9374375174 100644 --- a/internal/user/repository/view/user_view.go +++ b/internal/user/repository/view/user_view.go @@ -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 } diff --git a/internal/usergrant/repository/view/user_grant_view.go b/internal/usergrant/repository/view/user_grant_view.go index 19f5121426..b975f4ebc6 100644 --- a/internal/usergrant/repository/view/user_grant_view.go +++ b/internal/usergrant/repository/view/user_grant_view.go @@ -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 }