Refactored permissions, and added a basic test. Breaks BC due to DB column change.