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