Reroute user lookups for notifications and record export

Temporary disable gRPC comm between compose and system services
This commit is contained in:
Denis Arh
2020-06-02 14:37:34 +02:00
parent 36b40d9f3b
commit b46bc8c570
3 changed files with 46 additions and 34 deletions
+17 -13
View File
@@ -23,7 +23,8 @@ import (
"github.com/cortezaproject/corteza-server/pkg/mime"
"github.com/cortezaproject/corteza-server/pkg/payload"
"github.com/cortezaproject/corteza-server/pkg/rh"
stypes "github.com/cortezaproject/corteza-server/system/types"
systemService "github.com/cortezaproject/corteza-server/system/service"
systemTypes "github.com/cortezaproject/corteza-server/system/types"
)
type (
@@ -41,10 +42,6 @@ type (
Set []*recordPayload `json:"set"`
}
userFinder interface {
FindByID(context.Context, uint64) (*stypes.User, error)
}
Record struct {
importSession service.ImportSessionService
record service.RecordService
@@ -52,7 +49,7 @@ type (
namespace service.NamespaceService
attachment service.AttachmentService
ac recordAccessController
userFinder userFinder
userFinder systemService.UserService
}
recordAccessController interface {
@@ -69,7 +66,9 @@ func (Record) New() *Record {
namespace: service.DefaultNamespace,
attachment: service.DefaultAttachment,
ac: service.DefaultAccessControl,
userFinder: service.DefaultSystemUser,
// See comment at DefaultSystemUser definition
userFinder: service.DefaultSystemUser,
}
}
@@ -415,17 +414,22 @@ func (ctrl *Record) Export(ctx context.Context, r *request.RecordExport) (interf
}
// Custom user getter function for the underlying encoders.
users := map[uint64]*stypes.User{}
uf := func(ID uint64) (*stypes.User, error) {
if users[ID] != nil {
users := map[uint64]*systemTypes.User{}
uf := func(ID uint64) (*systemTypes.User, error) {
var err error
if _, exists := users[ID]; exists {
// nonexistent users are also cached!
return users[ID], nil
}
u, err := ctrl.userFinder.FindByID(ctx, ID)
// @todo this "communication" between system and compose
// services is ad-hoc solution
users[ID], err = ctrl.userFinder.With(ctx).FindByID(ID)
if err != nil {
return nil, err
}
users[ID] = u
return u, nil
return users[ID], nil
}
switch strings.ToLower(r.Ext) {
+7 -4
View File
@@ -15,6 +15,7 @@ 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"
)
@@ -27,18 +28,20 @@ type (
// Warning: API endpoints on compose should be kept so that we do not break backward compatibility)
notification struct {
actionlog actionlog.Recorder
users notificationUserFinder
users systemService.UserService
}
notificationUserFinder interface {
FindByID(context.Context, uint64) (*systemTypes.User, error)
FindByID(uint64) (*systemTypes.User, error)
}
)
func Notification() *notification {
return &notification{
actionlog: DefaultActionlog,
users: DefaultSystemUser,
// See comment at DefaultSystemUser definition
users: DefaultSystemUser,
}
}
@@ -118,7 +121,7 @@ func (svc notification) procEmailRecipients(ctx context.Context, m *gomail.Messa
if userID, err := strconv.ParseUint(rcpt, 10, 64); err == nil && userID > 0 {
// proc <user ID>
if user, err := svc.users.FindByID(ctx, userID); err != nil {
if user, err := svc.users.FindByID(userID); err != nil {
return NotificationErrFailedToLoadUser(aProps).Wrap(err)
} else {
email = user.Email
+22 -17
View File
@@ -3,24 +3,23 @@ package service
import (
"context"
"errors"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
actionlogRepository "github.com/cortezaproject/corteza-server/pkg/actionlog/repository"
"github.com/cortezaproject/corteza-server/pkg/corredor"
"time"
"go.uber.org/zap"
"time"
"github.com/cortezaproject/corteza-server/compose/repository"
"github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
actionlogRepository "github.com/cortezaproject/corteza-server/pkg/actionlog/repository"
"github.com/cortezaproject/corteza-server/pkg/app/options"
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/corredor"
"github.com/cortezaproject/corteza-server/pkg/eventbus"
"github.com/cortezaproject/corteza-server/pkg/permissions"
"github.com/cortezaproject/corteza-server/pkg/settings"
"github.com/cortezaproject/corteza-server/pkg/store"
"github.com/cortezaproject/corteza-server/pkg/store/minio"
"github.com/cortezaproject/corteza-server/pkg/store/plain"
systemProto "github.com/cortezaproject/corteza-server/system/proto"
systemService "github.com/cortezaproject/corteza-server/system/service"
)
type (
@@ -68,8 +67,13 @@ var (
DefaultAttachment AttachmentService
DefaultNotification *notification
DefaultSystemUser *systemUser
DefaultSystemRole *systemRole
// DefaultSystemUser is a bridge to users in a system service
// @todo this is ad-hoc solution that connects compose to system it breaks microservice
// architecture and service separation and should be refactored properly
// (that is, if we want to continue with microservice architecture)
DefaultSystemUser systemService.UserService
//DefaultSystemUser *systemUser
//DefaultSystemRole *systemRole
)
// Initializes compose-only services
@@ -148,15 +152,16 @@ func Initialize(ctx context.Context, log *zap.Logger, c Config) (err error) {
DefaultNamespace = Namespace()
DefaultModule = Module()
{
systemClientConn, err := NewSystemGRPCClient(ctx, c.GRPCClientSystem, DefaultLogger)
if err != nil {
return err
}
DefaultSystemUser = SystemUser(systemProto.NewUsersClient(systemClientConn))
DefaultSystemRole = SystemRole(systemProto.NewRolesClient(systemClientConn))
}
//{
// systemClientConn, err := NewSystemGRPCClient(ctx, c.GRPCClientSystem, DefaultLogger)
// if err != nil {
// return err
// }
//
// DefaultSystemUser = SystemUser(systemProto.NewUsersClient(systemClientConn))
// DefaultSystemRole = SystemRole(systemProto.NewRolesClient(systemClientConn))
//}
DefaultSystemUser = systemService.DefaultUser
DefaultImportSession = ImportSession()
DefaultRecord = Record()