From bc1550938feafbe94430e30219e7ba2e2e9820a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Wed, 29 Dec 2021 13:35:04 +0100 Subject: [PATCH] Prevent compose-system import cycles --- app/boot_levels.go | 9 +++++++-- compose/rest/record.go | 5 ----- compose/service/notification.go | 7 +++---- compose/service/service.go | 17 +++++++++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/boot_levels.go b/app/boot_levels.go index ca26a4029..10b00c5e3 100644 --- a/app/boot_levels.go +++ b/app/boot_levels.go @@ -475,8 +475,9 @@ func (app *CortezaApp) InitServices(ctx context.Context) (err error) { // Note: this is a legacy approach, all services from all 3 apps // will most likely be merged in the future err = cmpService.Initialize(ctx, app.Log, app.Store, cmpService.Config{ - ActionLog: app.Opt.ActionLog, - Storage: app.Opt.ObjStore, + ActionLog: app.Opt.ActionLog, + Storage: app.Opt.ObjStore, + UserFinder: sysService.DefaultUser, }) if err != nil { @@ -507,6 +508,10 @@ func (app *CortezaApp) InitServices(ctx context.Context) (err error) { } } + // Register reporters + // @todo additional datasource providers; generate? + sysService.DefaultReport.RegisterReporter("composeRecords", cmpService.DefaultRecord) + // Initializing seeder _ = seeder.Seeder(ctx, app.Store, seeder.Faker()) diff --git a/compose/rest/record.go b/compose/rest/record.go index edd91f967..e77a25663 100644 --- a/compose/rest/record.go +++ b/compose/rest/record.go @@ -23,7 +23,6 @@ import ( "github.com/cortezaproject/corteza-server/pkg/filter" "github.com/cortezaproject/corteza-server/pkg/payload" "github.com/cortezaproject/corteza-server/store" - systemService "github.com/cortezaproject/corteza-server/system/service" ) type ( @@ -50,7 +49,6 @@ type ( namespace service.NamespaceService attachment service.AttachmentService ac recordAccessController - userFinder systemService.UserService } recordAccessController interface { @@ -70,9 +68,6 @@ func (Record) New() *Record { namespace: service.DefaultNamespace, attachment: service.DefaultAttachment, ac: service.DefaultAccessControl, - - // See comment at DefaultSystemUser definition - userFinder: systemService.DefaultUser, } } diff --git a/compose/service/notification.go b/compose/service/notification.go index 9c4e81ba2..00a229c33 100644 --- a/compose/service/notification.go +++ b/compose/service/notification.go @@ -15,7 +15,6 @@ import ( "github.com/cortezaproject/corteza-server/pkg/actionlog" httpClient "github.com/cortezaproject/corteza-server/pkg/http" "github.com/cortezaproject/corteza-server/pkg/mail" - systemService "github.com/cortezaproject/corteza-server/system/service" systemTypes "github.com/cortezaproject/corteza-server/system/types" ) @@ -28,7 +27,7 @@ type ( // Warning: API endpoints on compose should be kept so that we do not break backward compatibility) notification struct { actionlog actionlog.Recorder - users systemService.UserService + users userFinder } notificationUserFinder interface { @@ -36,10 +35,10 @@ type ( } ) -func Notification() *notification { +func Notification(uf userFinder) *notification { return ¬ification{ actionlog: DefaultActionlog, - users: systemService.DefaultUser, + users: uf, } } diff --git a/compose/service/service.go b/compose/service/service.go index 2a67fdc8b..a2909dabe 100644 --- a/compose/service/service.go +++ b/compose/service/service.go @@ -22,14 +22,19 @@ import ( "github.com/cortezaproject/corteza-server/pkg/objstore/plain" "github.com/cortezaproject/corteza-server/pkg/options" "github.com/cortezaproject/corteza-server/store" - systemService "github.com/cortezaproject/corteza-server/system/service" + systemTypes "github.com/cortezaproject/corteza-server/system/types" "go.uber.org/zap" ) type ( + userFinder interface { + FindByID(context.Context, uint64) (*systemTypes.User, error) + } + Config struct { - ActionLog options.ActionLogOpt - Storage options.ObjectStoreOpt + ActionLog options.ActionLogOpt + Storage options.ObjectStoreOpt + UserFinder userFinder } eventDispatcher interface { @@ -148,7 +153,7 @@ func Initialize(_ context.Context, log *zap.Logger, s store.Storer, c Config) (e DefaultRecord = Record() DefaultPage = Page() DefaultChart = Chart() - DefaultNotification = Notification() + DefaultNotification = Notification(c.UserFinder) DefaultAttachment = Attachment(DefaultObjectStore) RegisterIteratorProviders() @@ -184,10 +189,6 @@ func Initialize(_ context.Context, log *zap.Logger, s store.Storer, c Config) (e DefaultAttachment, ) - // Register reporters - // @todo additional datasource providers; generate? - systemService.DefaultReport.RegisterReporter("composeRecords", DefaultRecord) - return nil }