create policy "users can update own questions or admins/teachers" on api.chapter_questions for update to authenticated using (
profile_id = (select api.get_profile_id()) or
((select private.get_my_roles()) && array ['teacher', 'school_admin', 'org_admin'] and
exists (select 1 from api.chapters as c where c.id = chapter_questions.chapter_id))) with check (
profile_id = (select api.get_profile_id()) -- owners can change anything
or ((select private.get_my_roles()) && array ['teacher', 'school_admin', 'org_admin'] and
exists (select 1 from api.chapters as c where c.id = chapter_questions.chapter_id)
-- Only allow changes to best_answer_id or deleted_at
and title = old.title and content = old.content));
create policy "users can update own questions or admins/teachers" on api.chapter_questions for update to authenticated using (
profile_id = (select api.get_profile_id()) or
((select private.get_my_roles()) && array ['teacher', 'school_admin', 'org_admin'] and
exists (select 1 from api.chapters as c where c.id = chapter_questions.chapter_id))) with check (
profile_id = (select api.get_profile_id()) -- owners can change anything
or ((select private.get_my_roles()) && array ['teacher', 'school_admin', 'org_admin'] and
exists (select 1 from api.chapters as c where c.id = chapter_questions.chapter_id)
-- Only allow changes to best_answer_id or deleted_at
and title = old.title and content = old.content));