feat: administrator (#271)

* feat: get views and failed events

* feat: get views and failed events

* feat: get views and failed events

* Update internal/view/repository/sequence.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/view/repository/general_query.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
Fabi
2020-06-25 08:01:13 +02:00
committed by GitHub
parent b88f200434
commit 8bfa1a083c
90 changed files with 3555 additions and 1661 deletions

View File

@@ -3,7 +3,7 @@ package model
import (
global_model "github.com/caos/zitadel/internal/model"
grant_model "github.com/caos/zitadel/internal/usergrant/model"
"github.com/caos/zitadel/internal/view"
"github.com/caos/zitadel/internal/view/repository"
)
type UserGrantSearchRequest grant_model.UserGrantSearchRequest
@@ -18,7 +18,7 @@ func (req UserGrantSearchRequest) GetOffset() uint64 {
return req.Offset
}
func (req UserGrantSearchRequest) GetSortingColumn() view.ColumnKey {
func (req UserGrantSearchRequest) GetSortingColumn() repository.ColumnKey {
if req.SortingColumn == grant_model.UserGrantSearchKeyUnspecified {
return nil
}
@@ -29,15 +29,15 @@ func (req UserGrantSearchRequest) GetAsc() bool {
return req.Asc
}
func (req UserGrantSearchRequest) GetQueries() []view.SearchQuery {
result := make([]view.SearchQuery, len(req.Queries))
func (req UserGrantSearchRequest) GetQueries() []repository.SearchQuery {
result := make([]repository.SearchQuery, len(req.Queries))
for i, q := range req.Queries {
result[i] = UserGrantSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
}
return result
}
func (req UserGrantSearchQuery) GetKey() view.ColumnKey {
func (req UserGrantSearchQuery) GetKey() repository.ColumnKey {
return UserGrantSearchKey(req.Key)
}

View File

@@ -4,13 +4,13 @@ import (
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"
"github.com/caos/zitadel/internal/view"
"github.com/caos/zitadel/internal/view/repository"
"github.com/jinzhu/gorm"
)
func UserGrantByID(db *gorm.DB, table, grantID string) (*model.UserGrantView, error) {
user := new(model.UserGrantView)
query := view.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID)
query := repository.PrepareGetByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID)
err := query(db, user)
return user, err
}
@@ -21,14 +21,14 @@ func UserGrantByIDs(db *gorm.DB, table, resourceOwnerID, projectID, userID strin
resourceOwnerIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyResourceOwner, Value: resourceOwnerID, Method: global_model.SearchMethodEquals}
projectIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}
userIDQuery := model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals}
query := view.PrepareGetByQuery(table, resourceOwnerIDQuery, projectIDQuery, userIDQuery)
query := repository.PrepareGetByQuery(table, resourceOwnerIDQuery, projectIDQuery, userIDQuery)
err := query(db, user)
return user, err
}
func SearchUserGrants(db *gorm.DB, table string, req *grant_model.UserGrantSearchRequest) ([]*model.UserGrantView, int, error) {
users := make([]*model.UserGrantView, 0)
query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
count, err := query(db, &users)
if err != nil {
return nil, 0, err
@@ -41,7 +41,7 @@ func UserGrantsByUserID(db *gorm.DB, table, userID string) ([]*model.UserGrantVi
queries := []*grant_model.UserGrantSearchQuery{
&grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyUserID, Value: userID, Method: global_model.SearchMethodEquals},
}
query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
_, err := query(db, &users)
if err != nil {
return nil, err
@@ -54,7 +54,7 @@ func UserGrantsByProjectID(db *gorm.DB, table, projectID string) ([]*model.UserG
queries := []*grant_model.UserGrantSearchQuery{
&grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
}
query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
_, err := query(db, &users)
if err != nil {
return nil, err
@@ -68,7 +68,7 @@ func UserGrantsByProjectIDAndRole(db *gorm.DB, table, projectID, roleKey string)
&grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
&grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyRoleKey, Value: roleKey, Method: global_model.SearchMethodListContains},
}
query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
_, err := query(db, &users)
if err != nil {
return nil, err
@@ -82,7 +82,7 @@ func UserGrantsByOrgIDAndProjectID(db *gorm.DB, table, orgID, projectID string)
&grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals},
&grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals},
}
query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
_, err := query(db, &users)
if err != nil {
return nil, err
@@ -95,7 +95,7 @@ func UserGrantsByOrgID(db *gorm.DB, table, orgID string) ([]*model.UserGrantView
queries := []*grant_model.UserGrantSearchQuery{
&grant_model.UserGrantSearchQuery{Key: grant_model.UserGrantSearchKeyResourceOwner, Value: orgID, Method: global_model.SearchMethodEquals},
}
query := view.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
query := repository.PrepareSearchQuery(table, model.UserGrantSearchRequest{Queries: queries})
_, err := query(db, &users)
if err != nil {
return nil, err
@@ -104,11 +104,11 @@ func UserGrantsByOrgID(db *gorm.DB, table, orgID string) ([]*model.UserGrantView
}
func PutUserGrant(db *gorm.DB, table string, grant *model.UserGrantView) error {
save := view.PrepareSave(table)
save := repository.PrepareSave(table)
return save(db, grant)
}
func DeleteUserGrant(db *gorm.DB, table, grantID string) error {
delete := view.PrepareDeleteByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID)
delete := repository.PrepareDeleteByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID)
return delete(db)
}