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:
Livio Amstutz 2020-07-06 13:18:10 +02:00 committed by GitHub
parent b7298bed1e
commit 26634505ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 90 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
iam_model "github.com/caos/zitadel/internal/iam/model" iam_model "github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/iam/repository/view/model" "github.com/caos/zitadel/internal/iam/repository/view/model"
global_model "github.com/caos/zitadel/internal/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} userIDQuery := &model.IamMemberSearchQuery{Key: iam_model.IamMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, orgIDQuery, userIDQuery) query := repository.PrepareGetByQuery(table, orgIDQuery, userIDQuery)
err := query(db, member) err := query(db, member)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Ahq2s", "Errors.Iam.MemberNotExisting")
}
return member, err return member, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
org_model "github.com/caos/zitadel/internal/org/model" org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/org/repository/view/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} domainQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyDomain, Value: domain, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, orgIDQuery, domainQuery) query := repository.PrepareGetByQuery(table, orgIDQuery, domainQuery)
err := query(db, domainView) err := query(db, domainView)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Gqwfq", "Errors.Org.DomainNotOnOrg")
}
return domainView, err 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} verifiedQuery := &model.OrgDomainSearchQuery{Key: org_model.OrgDomainSearchKeyVerified, Value: true, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, domainQuery, verifiedQuery) query := repository.PrepareGetByQuery(table, domainQuery, verifiedQuery)
err := query(db, domainView) err := query(db, domainView)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Tew2q", "Errors.Org.DomainNotFound")
}
return domainView, err return domainView, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
org_model "github.com/caos/zitadel/internal/org/model" org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/org/repository/view/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} userIDQuery := &model.OrgMemberSearchQuery{Key: org_model.OrgMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, orgIDQuery, userIDQuery) query := repository.PrepareGetByQuery(table, orgIDQuery, userIDQuery)
err := query(db, member) err := query(db, member)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-DG1qh", "Errors.Org.MemberNotFound")
}
return member, err return member, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
org_model "github.com/caos/zitadel/internal/org/model" org_model "github.com/caos/zitadel/internal/org/model"
"github.com/caos/zitadel/internal/org/repository/view/model" "github.com/caos/zitadel/internal/org/repository/view/model"
"github.com/caos/zitadel/internal/view/repository" "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) org := new(model.OrgView)
query := repository.PrepareGetByKey(table, model.OrgSearchKey(org_model.OrgSearchKeyOrgID), orgID) query := repository.PrepareGetByKey(table, model.OrgSearchKey(org_model.OrgSearchKeyOrgID), orgID)
err := query(db, org) err := query(db, org)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-GEwea", "Errors.Org.NotFound")
}
return org, err return org, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
proj_model "github.com/caos/zitadel/internal/project/model" proj_model "github.com/caos/zitadel/internal/project/model"
"github.com/caos/zitadel/internal/project/repository/view/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) app := new(model.ApplicationView)
query := repository.PrepareGetByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyAppID), appID) query := repository.PrepareGetByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyAppID), appID)
err := query(db, app) err := query(db, app)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-DGdfx", "Errors.Application.NotFound")
}
return app, err 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} clientIDQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyOIDCClientID, Value: clientID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, clientIDQuery) query := repository.PrepareGetByQuery(table, clientIDQuery)
err := query(db, app) err := query(db, app)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-DG1qh", "Errors.Project.AppNotFound")
}
return app, err 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} appNameQuery := model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyName, Value: appName, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, projectIDQuery, appNameQuery) query := repository.PrepareGetByQuery(table, projectIDQuery, appNameQuery)
err := query(db, app) err := query(db, app)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Jqw1z", "Errors.Project.AppNotFound")
}
return app, err return app, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
proj_model "github.com/caos/zitadel/internal/project/model" proj_model "github.com/caos/zitadel/internal/project/model"
"github.com/caos/zitadel/internal/project/repository/view/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} userIDQuery := model.ProjectGrantMemberSearchQuery{Key: proj_model.ProjectGrantMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, grantIDQuery, userIDQuery) query := repository.PrepareGetByQuery(table, grantIDQuery, userIDQuery)
err := query(db, role) err := query(db, role)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Sgr32", "Errors.Project.MemberNotExisting")
}
return role, err return role, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
proj_model "github.com/caos/zitadel/internal/project/model" proj_model "github.com/caos/zitadel/internal/project/model"
"github.com/caos/zitadel/internal/project/repository/view/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} orgIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyOrgID, Value: orgID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, projectIDQuery, orgIDQuery) query := repository.PrepareGetByQuery(table, projectIDQuery, orgIDQuery)
err := query(db, projectGrant) err := query(db, projectGrant)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-WR3z2", "Errors.Project.GrantNotExists")
}
return projectGrant, err 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} grantIDQuery := model.ProjectGrantSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Value: grantID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, grantIDQuery) query := repository.PrepareGetByQuery(table, grantIDQuery)
err := query(db, projectGrant) err := query(db, projectGrant)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-EGdh4", "Errors.Project.GrantNotFound")
}
return projectGrant, err return projectGrant, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
proj_model "github.com/caos/zitadel/internal/project/model" proj_model "github.com/caos/zitadel/internal/project/model"
"github.com/caos/zitadel/internal/project/repository/view/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} userIDQuery := model.ProjectMemberSearchQuery{Key: proj_model.ProjectMemberSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, projectIDQuery, userIDQuery) query := repository.PrepareGetByQuery(table, projectIDQuery, userIDQuery)
err := query(db, role) err := query(db, role)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-EgWQ2", "Errors.Project.MemberNotExisting")
}
return role, err return role, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
proj_model "github.com/caos/zitadel/internal/project/model" proj_model "github.com/caos/zitadel/internal/project/model"
"github.com/caos/zitadel/internal/project/repository/view/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} keyQuery := model.ProjectRoleSearchQuery{Key: proj_model.ProjectRoleSearchKeyKey, Value: key, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, projectIDQuery, grantIDQuery, keyQuery) query := repository.PrepareGetByQuery(table, projectIDQuery, grantIDQuery, keyQuery)
err := query(db, role) err := query(db, role)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Wtg72", "Errors.Project.RoleNotExisting")
}
return role, err return role, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
proj_model "github.com/caos/zitadel/internal/project/model" proj_model "github.com/caos/zitadel/internal/project/model"
"github.com/caos/zitadel/internal/project/repository/view/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} projectIDQuery := model.ProjectSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, projectIDQuery) query := repository.PrepareGetByQuery(table, projectIDQuery)
err := query(db, project) err := query(db, project)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-NEO7W", "Errors.Project.NotFound")
}
return project, err return project, err
} }

View File

@ -54,6 +54,7 @@ Errors:
InvalidDomain: Domäne ist ungültig InvalidDomain: Domäne ist ungültig
DomainMissing: Domäne fehlt DomainMissing: Domäne fehlt
DomainNotOnOrg: Domäne fehlt auf Organisation DomainNotOnOrg: Domäne fehlt auf Organisation
DomainNotFound: Domäne konnte nicht gefunden werden
MemberIDMissing: Member ID fehlt MemberIDMissing: Member ID fehlt
MemberNotFound: Organisations Member konnte nicht gefunden werden MemberNotFound: Organisations Member konnte nicht gefunden werden
InvalidMember: Organisations Member ist ungültig InvalidMember: Organisations Member ist ungültig
@ -69,6 +70,7 @@ Errors:
Invalid: Projekt ist ungültig Invalid: Projekt ist ungültig
NotActive: Projekt ist nicht aktiv NotActive: Projekt ist nicht aktiv
NotInactive: Projekt ist nicht deaktiviert NotInactive: Projekt ist nicht deaktiviert
NotFound: Project konnte nicht gefunden werden
UserIDMissing: User ID fehlt UserIDMissing: User ID fehlt
MemberNotFound: Member konnte nicht gefunden werden MemberNotFound: Member konnte nicht gefunden werden
MemberInvalid: Member ist ungültig MemberInvalid: Member ist ungültig
@ -107,4 +109,8 @@ Errors:
NotActive: Benutzer Berechtigung ist nicht aktiv NotActive: Benutzer Berechtigung ist nicht aktiv
NotInactive: Benutzer Berechtigung ist nicht deaktiviert NotInactive: Benutzer Berechtigung ist nicht deaktiviert
Changes: 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

View File

@ -54,6 +54,7 @@ Errors:
InvalidDomain: Invalid domain InvalidDomain: Invalid domain
DomainMissing: Domain missing DomainMissing: Domain missing
DomainNotOnOrg: Domain doesn't exist on organisation DomainNotOnOrg: Domain doesn't exist on organisation
DomainNotFound: Domain not found
MemberIDMissing: Member ID missing MemberIDMissing: Member ID missing
MemberNotFound: Organisations member not found MemberNotFound: Organisations member not found
InvalidMember: Organisation member is invalid InvalidMember: Organisation member is invalid
@ -68,12 +69,13 @@ Errors:
CouldNotGenerateClientSecret: Could not generate client secret CouldNotGenerateClientSecret: Could not generate client secret
Invalid: Project is invalid Invalid: Project is invalid
NotActive: Project is not active NotActive: Project is not active
NotInactive: Projekt is not deactivated NotInactive: Project is not deactivated
NotFound: Porject not found
UserIDMissing: User ID missing UserIDMissing: User ID missing
MemberNotFound: Project member not found MemberNotFound: Project member not found
MemberInvalid: Project member is invalid MemberInvalid: Project member is invalid
MemberAlreadyExists: Project member already exists 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 MinimumOneRoleNeeded: At least one role should be added
RoleAlreadyExists: Role already exists RoleAlreadyExists: Role already exists
RoleInvalid: Role is invalid RoleInvalid: Role is invalid
@ -107,4 +109,8 @@ Errors:
NotActive: User grant is not active NotActive: User grant is not active
NotInactive: User grant is not deactivated NotInactive: User grant is not deactivated
Changes: Changes:
NotFound: No history found NotFound: No history found
Token:
NotFound: Token not found
UserSession:
NotFound: UserSession not found

View File

@ -1,7 +1,6 @@
package view package view
import ( import (
"github.com/caos/zitadel/internal/view/repository"
"time" "time"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
@ -10,12 +9,16 @@ import (
"github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/errors"
token_model "github.com/caos/zitadel/internal/token/model" token_model "github.com/caos/zitadel/internal/token/model"
"github.com/caos/zitadel/internal/token/repository/view/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) { func TokenByID(db *gorm.DB, table, tokenID string) (*model.Token, error) {
token := new(model.Token) token := new(model.Token)
query := repository.PrepareGetByKey(table, model.TokenSearchKey(token_model.TokenSearchKeyTokenID), tokenID) query := repository.PrepareGetByKey(table, model.TokenSearchKey(token_model.TokenSearchKeyTokenID), tokenID)
err := query(db, token) err := query(db, token)
if errors.IsNotFound(err) {
return nil, errors.ThrowNotFound(nil, "VIEW-Nqwf1", "Errors.Token.NotFound")
}
return token, err return token, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
usr_model "github.com/caos/zitadel/internal/user/model" usr_model "github.com/caos/zitadel/internal/user/model"
"github.com/caos/zitadel/internal/user/repository/view/model" "github.com/caos/zitadel/internal/user/repository/view/model"
"github.com/caos/zitadel/internal/view/repository" "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) user := new(model.NotifyUser)
query := repository.PrepareGetByKey(table, model.UserSearchKey(usr_model.NotifyUserSearchKeyUserID), userID) query := repository.PrepareGetByKey(table, model.UserSearchKey(usr_model.NotifyUserSearchKeyUserID), userID)
err := query(db, user) err := query(db, user)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Gad31", "Errors.User.NotFound")
}
return user, err return user, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/view/repository" "github.com/caos/zitadel/internal/view/repository"
"github.com/jinzhu/gorm" "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) query := repository.PrepareGetByQuery(table, userAgentQuery, userQuery)
err := query(db, userSession) err := query(db, userSession)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-NGBs1", "Errors.UserSession.NotFound")
}
return userSession, err return userSession, err
} }

View File

@ -39,6 +39,9 @@ func UserByLoginName(db *gorm.DB, table, loginName string) (*model.UserView, err
} }
query := repository.PrepareGetByQuery(table, loginNameQuery) query := repository.PrepareGetByQuery(table, loginNameQuery)
err := query(db, user) err := query(db, user)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-AD4qs", "Errors.User.NotFound")
}
return user, err return user, err
} }

View File

@ -1,6 +1,7 @@
package view package view
import ( import (
caos_errs "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model" global_model "github.com/caos/zitadel/internal/model"
grant_model "github.com/caos/zitadel/internal/usergrant/model" grant_model "github.com/caos/zitadel/internal/usergrant/model"
"github.com/caos/zitadel/internal/usergrant/repository/view/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) user := new(model.UserGrantView)
query := repository.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID) query := repository.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID)
err := query(db, user) err := query(db, user)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Nqwf1", "Errors.Token.NotFound")
}
return user, err 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} userIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, resourceOwnerIDQuery, projectIDQuery, userIDQuery) query := repository.PrepareGetByQuery(table, resourceOwnerIDQuery, projectIDQuery, userIDQuery)
err := query(db, user) err := query(db, user)
if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Q1tq2", "Errors.UserGrant.NotFound")
}
return user, err return user, err
} }