From a260196a1993381cdb0986620353129331e480a2 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Fri, 15 Mar 2019 00:38:27 +0100 Subject: [PATCH] fix(system): apps and credential tests, findbymemberid --- .../internal/repository/applications_test.go | 2 +- .../internal/repository/credentials_test.go | 2 +- system/internal/repository/role.go | 21 +++---------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/system/internal/repository/applications_test.go b/system/internal/repository/applications_test.go index 255bcefaf..feb81e35b 100644 --- a/system/internal/repository/applications_test.go +++ b/system/internal/repository/applications_test.go @@ -25,7 +25,7 @@ func TestApplication(t *testing.T) { // Run tests in transaction to maintain DB state. Error(t, db.Transaction(func() error { - db.Delete("sys_application", "1=1") + db.Exec("DELETE FROM sys_application WHERE 1=1") app := &types.Application{ Name: "created", diff --git a/system/internal/repository/credentials_test.go b/system/internal/repository/credentials_test.go index 0f960b707..af12b337c 100644 --- a/system/internal/repository/credentials_test.go +++ b/system/internal/repository/credentials_test.go @@ -25,7 +25,7 @@ func TestCredentials(t *testing.T) { // Run tests in transaction to maintain DB state. Error(t, db.Transaction(func() error { - db.Delete("sys_credentials", "1=1") + db.Exec("DELETE FROM sys_credentials WHERE 1=1") cc := types.CredentialsSet{ &types.Credentials{OwnerID: 10000, Kind: types.CredentialsKindLinkedin, Credentials: "linkedin-profile-id"}, diff --git a/system/internal/repository/role.go b/system/internal/repository/role.go index d4a415420..d0bffd653 100644 --- a/system/internal/repository/role.go +++ b/system/internal/repository/role.go @@ -67,26 +67,11 @@ func (r *role) FindByID(id uint64) (*types.Role, error) { } func (r *role) FindByMemberID(userID uint64) ([]*types.Role, error) { - ids := make([]uint64, 0) - params := make([]interface{}, 0) - - sql := "SELECT DISTINCT rel_role FROM " + r.members + " " - sql += "WHERE rel_user = ?" - params = append(params, userID) - - if err := r.db().Select(&ids, sql, params...); err != nil { + sql := "SELECT * FROM " + r.roles + " where id in (select rel_role from " + r.members + " where rel_user=?) and " + sqlRoleScope + rval := make([]*types.Role, 0) + if err := r.db().Select(&rval, sql, userID); err != nil { return nil, err } - - rval := make([]*types.Role, 0) - for _, id := range ids { - mod, err := r.FindByID(id) - if err != nil && err != ErrRoleNotFound { - return nil, err - } - rval = append(rval, mod) - } - return rval, nil }