public function test_successful_save_for_new_item()
 {
     $response = new \WeBWorK\Server\Response();
     $response->set_content('foo');
     $response->set_question_id(20);
     $response->set_is_answer(false);
     $saved = $response->save();
     $this->assertTrue($saved);
     $new_response = new \WeBWorK\Server\Response($response->get_id());
     $this->assertSame('foo', $new_response->get_content());
     $this->assertSame(20, $new_response->get_question_id());
     $this->assertFalse($new_response->get_is_answer());
 }
 public function update_item_permissions_check($request)
 {
     if (!is_user_logged_in()) {
         return false;
     }
     $params = $request->get_params();
     if (!isset($params['id'])) {
         return false;
     }
     $response_id = $params['id'];
     $response = new \WeBWorK\Server\Response($response_id);
     if (!$response->exists()) {
         return false;
     }
     $question_id = $response->get_question_id();
     if (!$question_id) {
         return false;
     }
     // @todo modeling
     $question = get_post($question_id);
     if (!$question) {
         return false;
     }
     $user_is_admin = current_user_can('edit_others_posts');
     $user_is_admin = apply_filters('webwork_user_is_admin', $user_is_admin);
     return $user_is_admin || $question->post_author == get_current_user_id();
 }