Check study access rights and study exists

 Fix #445
it needs the cls to get `cls._table` for the sql.