Open platform to collect and prioritize feedback
fixes #24
goenningcf641b6b7316
diff --git a/app/identity/handler.go b/app/identity/handler.goindex d67963b48..4828e55d4 100644--- a/app/identity/handler.go+++ b/app/identity/handler.go@@ -53,7 +53,7 @@ func (h OAuthHandlers) Callback(provider string) app.HandlerFunc {return c.Failure(err)}- user, err := h.userService.GetByEmail(oauthUser.Email)+ user, err := h.userService.GetByEmail(tenant.ID, oauthUser.Email)if err != nil {if err == app.ErrNotFound {diff --git a/app/identity/service.go b/app/identity/service.goindex 4aae228f9..39f5d7227 100644--- a/app/identity/service.go+++ b/app/identity/service.go@@ -4,7 +4,7 @@ import "github.com/WeCanHearYou/wechy/app"// UserService is used for user operationstype UserService interface {- GetByEmail(email string) (*app.User, error)+ GetByEmail(tenantID int, email string) (*app.User, error)Register(user *app.User) error}diff --git a/app/postgres/identity.go b/app/postgres/identity.goindex 2e31f1e13..cf3492725 100644--- a/app/postgres/identity.go+++ b/app/postgres/identity.go@@ -15,9 +15,9 @@ type UserService struct {}// GetByEmail returns a user based on given email-func (svc UserService) GetByEmail(email string) (*app.User, error) {+func (svc UserService) GetByEmail(tenantID int, email string) (*app.User, error) {user := &app.User{}- row := svc.DB.QueryRow("SELECT id, name, email FROM users WHERE email = $1", email)+ row := svc.DB.QueryRow("SELECT id, name, email FROM users WHERE email = $1 AND tenant_id = $2", email, tenantID)if err := row.Scan(&user.ID, &user.Name, &user.Email); err != nil {return nil, app.ErrNotFounddiff --git a/app/postgres/identity_test.go b/app/postgres/identity_test.goindex 95c78d0c6..51cd54de5 100644--- a/app/postgres/identity_test.go+++ b/app/postgres/identity_test.go@@ -16,7 +16,7 @@ func TestUserService_GetByEmail_Error(t *testing.T) {defer db.Close()svc := &postgres.UserService{DB: db}- user, err := svc.GetByEmail("[email protected]")+ user, err := svc.GetByEmail(300, "[email protected]")Expect(user).To(BeNil())Expect(err).NotTo(BeNil())@@ -28,7 +28,7 @@ func TestUserService_GetByEmail(t *testing.T) {defer db.Close()svc := &postgres.UserService{DB: db}- user, err := svc.GetByEmail("[email protected]")+ user, err := svc.GetByEmail(300, "[email protected]")Expect(err).To(BeNil())Expect(user.ID).To(Equal(int(300)))@@ -36,6 +36,18 @@ func TestUserService_GetByEmail(t *testing.T) {Expect(user.Email).To(Equal("[email protected]"))}+func TestUserService_GetByEmail_WrongTenant(t *testing.T) {+ RegisterTestingT(t)+ db, _ := dbx.New()+ defer db.Close()++ svc := &postgres.UserService{DB: db}+ user, err := svc.GetByEmail(400, "[email protected]")++ Expect(user).To(BeNil())+ Expect(err).NotTo(BeNil())+}+func TestUserService_Register(t *testing.T) {RegisterTestingT(t)db, _ := dbx.New()@@ -58,7 +70,7 @@ func TestUserService_Register(t *testing.T) {err := svc.Register(user)Expect(err).To(BeNil())- user, err = svc.GetByEmail("[email protected]")+ user, err = svc.GetByEmail(300, "[email protected]")Expect(err).To(BeNil())Expect(user.ID).To(Equal(int(1)))Expect(user.Name).To(Equal("Rob Stark"))