How to trigger an error: “You are not allowed to edit this post.”

Check or Alter user capabilities on call of current_user_can. Check current_user_can fucntion and has_cap fitler for further info.