3
0

fix(system): apps and credential tests, findbymemberid

This commit is contained in:
Tit Petric
2019-03-15 00:38:27 +01:00
parent f39fa72bad
commit a260196a19
3 changed files with 5 additions and 20 deletions
@@ -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",
@@ -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"},
+3 -18
View File
@@ -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
}