Convert key string to lower case

The key string used to query the rules must be converted to lower case because keys are also added in lower case. Fixes problems with keys that contain upper case letters like "database.bypassRestricted".
Check permissions before adding a new record

Check permissions before adding a new record with record operation created, updated and deleted. Without this fix permissions aren't checked for tx status == "BEGUN" which is the norm.
Merge pull request #1947 from oflaschel/master

Check permissions before adding records in optimistic transaction