I had a similar problem a few years ago. I don't remember what the outcome was but my posts on Perspective table disable editing on certain rows may give you some ideas. You might need to return a hidden column. e.g.,
SELECT
something,
from_something
from_something AS canEdit
FROM ABC
and use that hidden value to decide whether or not a row can be edited.