fix: User grant id key (#731)

* fix: log id and error message

* fix: user grant by id correct search field
This commit is contained in:
Silvan 2020-09-11 14:51:50 +02:00 committed by GitHub
parent 4926509de0
commit c37d55b069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 10 deletions

View File

@ -1,16 +1,15 @@
package view package view
import ( import (
global_model "github.com/caos/zitadel/internal/model"
"time" "time"
"github.com/jinzhu/gorm"
"github.com/lib/pq"
"github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/errors"
global_model "github.com/caos/zitadel/internal/model"
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" "github.com/caos/zitadel/internal/view/repository"
"github.com/jinzhu/gorm"
"github.com/lib/pq"
) )
func TokenByID(db *gorm.DB, table, tokenID string) (*model.Token, error) { func TokenByID(db *gorm.DB, table, tokenID string) (*model.Token, error) {
@ -18,7 +17,7 @@ func TokenByID(db *gorm.DB, table, tokenID string) (*model.Token, error) {
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) { if errors.IsNotFound(err) {
return nil, errors.ThrowNotFound(nil, "VIEW-Nqwf1", "Errors.Token.NotFound") return nil, errors.ThrowNotFound(nil, "VIEW-6ub3p", "Errors.Token.NotFound")
} }
return token, err return token, err
} }

View File

@ -48,6 +48,7 @@ const (
UserGrantSearchKeyGrantID UserGrantSearchKeyGrantID
UserGrantSearchKeyOrgName UserGrantSearchKeyOrgName
UserGrantSearchKeyRoleKey UserGrantSearchKeyRoleKey
UserGrantSearchKeyID
) )
type UserGrantSearchQuery struct { type UserGrantSearchQuery struct {

View File

@ -65,6 +65,8 @@ func (key UserGrantSearchKey) ToColumnName() string {
return UserGrantKeyOrgName return UserGrantKeyOrgName
case grant_model.UserGrantSearchKeyRoleKey: case grant_model.UserGrantSearchKeyRoleKey:
return UserGrantKeyRole return UserGrantKeyRole
case grant_model.UserGrantSearchKeyID:
return UserGrantKeyID
default: default:
return "" return ""
} }

View File

@ -10,13 +10,13 @@ import (
) )
func UserGrantByID(db *gorm.DB, table, grantID string) (*model.UserGrantView, error) { func UserGrantByID(db *gorm.DB, table, grantID string) (*model.UserGrantView, error) {
user := new(model.UserGrantView) grant := new(model.UserGrantView)
query := repository.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID) query := repository.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyID), grantID)
err := query(db, user) err := query(db, grant)
if caos_errs.IsNotFound(err) { if caos_errs.IsNotFound(err) {
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Nqwf1", "Errors.Token.NotFound") return nil, caos_errs.ThrowNotFound(nil, "VIEW-Nqwf1", "Errors.UserGrant.NotFound")
} }
return user, err return grant, err
} }
func UserGrantByIDs(db *gorm.DB, table, resourceOwnerID, projectID, userID string) (*model.UserGrantView, error) { func UserGrantByIDs(db *gorm.DB, table, resourceOwnerID, projectID, userID string) (*model.UserGrantView, error) {