Skip to content

Commit

Permalink
roles: List roles from keto_role table (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadysnaat authored and arekkas committed Jun 15, 2018
1 parent 0ba3c06 commit 9e16605
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion role/manager_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (m *SQLManager) FindRolesByMember(member string, limit, offset int) ([]Role

func (m *SQLManager) ListRoles(limit, offset int) ([]Role, error) {
var ids []string
if err := m.DB.Select(&ids, m.DB.Rebind(fmt.Sprintf("SELECT role_id from %s GROUP BY role_id ORDER BY role_id LIMIT ? OFFSET ?", m.TableMember)), limit, offset); err == sql.ErrNoRows {
if err := m.DB.Select(&ids, m.DB.Rebind(fmt.Sprintf("SELECT id from %s LIMIT ? OFFSET ?", m.TableRole)), limit, offset); err == sql.ErrNoRows {
return nil, errors.WithStack(pkg.ErrNotFound)
} else if err != nil {
return nil, errors.WithStack(err)
Expand Down
7 changes: 7 additions & 0 deletions role/manager_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@ func TestHelperManagers(m Manager) func(t *testing.T) {
assert.NoError(t, m.DeleteRole("1"))
_, err = m.GetRole("1")
require.NotNil(t, err)

assert.NoError(t, m.CreateRole(&Role{
ID: "3",
}))
ds, err = m.ListRoles(100, 0)
require.NoError(t, err)
assert.Len(t, ds, 2)
}
}

0 comments on commit 9e16605

Please sign in to comment.