public function post($request) { /** * Creates a new bugnote. * * Sets the location header and returns the main URL of the created resource, * as RFC2616 says we SHOULD. * * @param $request - The Request we're responding to */ $this->bug_id = BugnoteList::get_bug_id_from_url($request->url); if (!access_has_bug_level(config_get('add_bugnote_threshold'), $this->bug_id)) { throw new HTTPException(403, "Access denied to add bugnote"); } if (bug_is_readonly($this->bug_id)) { throw new HTTPException(500, "Cannot add a bugnote to a read-only bug"); } $new_note = new Bugnote(); $new_note->populate_from_repr($request->body); $bugnote_added = bugnote_add($this->bug_id, $new_note->mantis_data['note'], '0:00', $new_note->mantis_data['view_state'] == VS_PRIVATE); if ($bugnote_added) { $bugnote_added_url = Bugnote::get_url_from_mantis_id($bugnote_added); $this->rsrc_data = $bugnote_added_url; $resp = new Response(); $resp->headers[] = "location: {$bugnote_added_url}"; $resp->status = 201; $resp->body = json_encode($bugnote_added_url); return $resp; } else { throw new HTTPException(500, "Couldn't create bugnote"); } }