3
0

upd(internal): add ListGrants

This commit is contained in:
Mitja Zivkovic
2019-01-23 20:15:35 +01:00
committed by Tit Petric
parent 0538336956
commit 3747bce99d
3 changed files with 22 additions and 0 deletions
+1
View File
@@ -15,4 +15,5 @@ type ResourcesInterface interface {
CheckAccess(resource string, operation string) error
Grant(resource string, teamID uint64, operations []string, value types.Access) error
ListGrants(resource string, teamID uint64) ([]types.Rules, error)
}
+10
View File
@@ -122,3 +122,13 @@ func (r *resources) Grant(resource string, teamID uint64, operations []string, v
}
return err
}
func (r *resources) ListGrants(resource string, teamID uint64) ([]types.Rules, error) {
result := []types.Rules{}
query := "select * from sys_rules where rel_team = ? and resource = ?"
if err := r.db.Select(&result, query, teamID, resource); err != nil {
return nil, err
}
return result, nil
}
+11
View File
@@ -47,6 +47,17 @@ func TestRules(t *testing.T) {
NoError(t, resources.CheckAccessMulti("channel:*", "edit"), "channel:* edit, expected no error")
}
// list grants for team
{
grants, err := resources.ListGrants("channel:2", 2)
NoError(t, err, "expect no error")
Assert(t, len(grants) == 2, "expected 2 grants")
Assert(t, grants[0].TeamID == 2, "expected TeamID == 2, got %v", grants[0].TeamID)
Assert(t, grants[0].Resource == "channel:2", "expected Resource == channel:2, got %s", grants[0].Resource)
Assert(t, grants[0].Operation == "delete", "expected Operation == delete, got %s", grants[0].Operation)
Assert(t, grants[0].Value == rules.Allow, "expected Value == Allow, got %s", grants[0].Value)
}
// deny channel:1 group:1 (explicit deny, multi=deny)
{
resources.Grant("channel:1", 1, []string{"edit"}, rules.Deny)