public void MakeMember(ICanJoinKey memberKey, ICanBeJoinedKey memberOfKey)
 {
     _client.Cypher
     .MergeKey(memberKey, "memberKey")
     .MergeKey(memberOfKey, "memberOfKey")
     .Merge("(memberKey) - [:MEMBER] -> (memberOfKey)")
     .ExecuteWithoutResults();
 }
 public void GrantPermission(ICanJoinKey grantedToKey, ICanBeGrantedKey grantedKey, string action)
 {
     _client.Cypher
     .MergeKey(grantedToKey, "grantedToKey")
     .MergeKey(grantedKey, "grantedKey")
     .Merge("(grantedToKey) - [:GRANT {action: {action}}] -> (grantedKey)")
     .WithParam("action", action)
     .ExecuteWithoutResults();
 }
 public void RemoveMember(ICanJoinKey memberKey, ICanBeJoinedKey memberOfKey)
 {
     _client.Cypher
     .MergeKey(memberKey, "memberKey")
     .MergeKey(memberOfKey, "memberOfKey")
     .With("memberKey,memberOfKey")
     .Match("(memberKey) - [m:MEMBER] -> (memberOfKey)")
     .Delete("m")
     .ExecuteWithoutResults();
 }
 public bool CanItAccess(ICanJoinKey accessor, ICanBeGrantedKey thing, string action)
 {
     return(_client.Cypher
            .MergeKey(accessor, "accessor")
            .MergeKey(thing, "thing")
            .With("accessor,thing")
            .Match("(accessor) - [:MEMBER *0..] -> () - [g:GRANT {action: {action}}] -> (thing)")
            .WithParam("action", action)
            .Return <bool>("count(g) > 0").
            Results.
            First());
 }
        public void ActorPermissionMultiplePath(int depth)
        {
            var s     = GetMethodName();
            var sut   = new PermissionableService(_client);
            var actor = new ActorKey {
                Key = Guid.NewGuid().ToString(), Name = $"{GetMethodName()}_Actor"
            };
            ICanJoinKey next  = actor;
            ICanJoinKey next2 = actor;

            for (int i = 0; i < depth; i++)
            {
                {
                    var node = new NodeKey {
                        Key = Guid.NewGuid().ToString(), Name = $"{GetMethodName()}_Node_Path1_" + depth
                    };
                    sut.MakeMember(next, node);
                    next = node;
                }

                {
                    var node = new NodeKey {
                        Key = Guid.NewGuid().ToString(), Name = $"{GetMethodName()}_Node_Path2_" + depth
                    };
                    sut.MakeMember(next2, node);
                    next2 = node;
                }
            }
            var thing = new ThingKey {
                Key = Guid.NewGuid().ToString(), Name = $"{GetMethodName()}_Thing"
            };

            sut.GrantPermission(next, thing, $"{GetMethodName()}_Action");
            sut.GrantPermission(next2, thing, $"{GetMethodName()}_Action");

            Assert.True(sut.CanItAccess(actor, thing, $"{GetMethodName()}_Action"));
        }