mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-18 13:57:32 +00:00
6e105f662e
* init for views (spooler, handler) * init for views (spooler, handler) * start view in management * granted project * implement granted project view * search granted projects * fix search column * update all projects on project change * search roles * filter org * project members * project grant members * fix tests * application view * project grant search * mock * test appendevents * test appendevents * Update internal/view/query.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/eventstore/spooler/spooler.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/view/query.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * merge request changes * Update internal/project/repository/view/model/application.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * merge request changes * Project view sql (#92) * sql and configs * error handling * sql start in eventstore * on error handling, config * read user on members * Update internal/project/repository/view/application_view.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/granted_project.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * return caos errors * Update internal/project/repository/view/model/granted_project_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_grant_member.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_grant_member_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_member.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_member_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_role.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_role_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/application_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/application_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * converter fix Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Silvan <silvan.reusser@gmail.com>
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package view
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/model"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
const (
|
|
errViewNameKey = "view_name"
|
|
errFailedSeqKey = "failed_sequence"
|
|
)
|
|
|
|
type FailedEvent struct {
|
|
ViewName string `gorm:"column:view_name;primary_key"`
|
|
FailedSequence uint64 `gorm:"column:failed_sequence;primary_key`
|
|
FailureCount uint64 `gorm:"column:failure_count`
|
|
ErrMsg string `gorm:"column:err_msg`
|
|
}
|
|
|
|
type FailedEventSearchQuery struct {
|
|
Key FailedEventSearchKey
|
|
Method model.SearchMethod
|
|
Value interface{}
|
|
}
|
|
|
|
func (req FailedEventSearchQuery) GetKey() ColumnKey {
|
|
return failedEventSearchKey(req.Key)
|
|
}
|
|
|
|
func (req FailedEventSearchQuery) GetMethod() model.SearchMethod {
|
|
return req.Method
|
|
}
|
|
|
|
func (req FailedEventSearchQuery) GetValue() interface{} {
|
|
return req.Value
|
|
}
|
|
|
|
type FailedEventSearchKey int32
|
|
|
|
const (
|
|
FAILEDEVENTKEY_UNDEFINED FailedEventSearchKey = iota
|
|
FAILEDEVENTKEY_VIEW_NAME
|
|
FAILEDEVENTKEY_FAILED_SEQUENCE
|
|
)
|
|
|
|
type failedEventSearchKey FailedEventSearchKey
|
|
|
|
func (key failedEventSearchKey) ToColumnName() string {
|
|
switch FailedEventSearchKey(key) {
|
|
case FAILEDEVENTKEY_VIEW_NAME:
|
|
return "view_name"
|
|
case FAILEDEVENTKEY_FAILED_SEQUENCE:
|
|
return "failed_sequence"
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
func SaveFailedEvent(db *gorm.DB, table string, failedEvent *FailedEvent) error {
|
|
save := PrepareSave(table)
|
|
err := save(db, failedEvent)
|
|
|
|
if err != nil {
|
|
return errors.ThrowInternal(err, "VIEW-5kOhP", "unable to updated failed events")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func LatestFailedEvent(db *gorm.DB, table, viewName string, sequence uint64) (*FailedEvent, error) {
|
|
failedEvent := new(FailedEvent)
|
|
queries := []SearchQuery{
|
|
FailedEventSearchQuery{Key: FAILEDEVENTKEY_VIEW_NAME, Method: model.SEARCHMETHOD_EQUALS_IGNORE_CASE, Value: viewName},
|
|
FailedEventSearchQuery{Key: FAILEDEVENTKEY_FAILED_SEQUENCE, Method: model.SEARCHMETHOD_EQUALS, Value: sequence},
|
|
}
|
|
query := PrepareGetByQuery(table, queries...)
|
|
err := query(db, failedEvent)
|
|
|
|
if err == nil {
|
|
return failedEvent, nil
|
|
}
|
|
|
|
if errors.IsNotFound(err) {
|
|
failedEvent.ViewName = viewName
|
|
failedEvent.FailedSequence = sequence
|
|
failedEvent.FailureCount = 0
|
|
return failedEvent, nil
|
|
}
|
|
return nil, errors.ThrowInternalf(err, "VIEW-9LyCB", "unable to get failed events of %s", viewName)
|
|
|
|
}
|