Check study access rights and study exists

 Fix #445
Looking into this further, I think if it is moved to the study object it can be done in a single gigantic exists/join query which will greatly ease the load on the SQL server as well as slim down the code.