Moved setting of permissions into an API function and removed the 'type' field from the database.