protected function _get_rsrc_attr($attr_name) { if ($attr_name == 'bug') { return Bug::get_url_from_mantis_id($this->mantis_data['bug_id']); } elseif ($attr_name == 'reporter') { return User::get_url_from_mantis_id($this->mantis_data['reporter_id']); } elseif ($attr_name == 'private') { return $this->mantis_data['view_state'] == VS_PRIVATE; } elseif ($attr_name == 'date_submitted' || $attr_name == 'last_modified') { return date_to_iso_date($this->mantis_data[$attr_name]); } elseif ($attr_name == 'text') { return $this->mantis_data['note']; } elseif (in_array($attr_name, Bugnote::$rsrc_attrs)) { return $this->mantis_data[$attr_name]; } else { throw new HTTPException(415, "Unknown resource attribute: {$attr_name}"); } }
protected function _get_rsrc_attr($attr_name) { if ($attr_name == 'reporter') { return User::get_url_from_mantis_id($this->mantis_data['reporter_id']); } elseif ($attr_name == 'handler') { return $this->mantis_data['handler_id'] ? User::get_url_from_mantis_id($this->mantis_data['handler_id']) : ""; } elseif ($attr_name == 'duplicate') { return $this->mantis_data['duplicate_id'] ? Bug::get_url_from_mantis_id($this->mantis_data['duplicate_id']) : ""; } elseif (in_array($attr_name, array('priority', 'severity', 'reproducibility', 'status', 'resolution', 'projection', 'eta'))) { return get_enum_to_string(config_get($attr_name . "_enum_string"), $this->mantis_data[$attr_name]); } elseif ($attr_name == 'date_submitted' || $attr_name == 'last_updated') { return timestamp_to_iso_date($this->mantis_data[$attr_name]); } elseif ($attr_name == 'private') { return $this->mantis_data['view_state'] == VS_PRIVATE; } elseif ($attr_name == 'project_id' or $attr_name == 'profile_id') { return (int) $this->mantis_data[$attr_name]; } elseif (in_array($attr_name, Bug::$rsrc_attrs)) { return $this->mantis_data[$attr_name]; } }
public function post($request) { /** * Creates a new bug. * * 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 is all copied from Mantis's bug_report.php. $new_bug = new Bug(); $new_bug->populate_from_repr($request->body); $new_bugdata = $new_bug->to_bugdata(); if (!access_has_project_level(config_get('report_bug_threshold'), $new_bugdata->project_id)) { throw new HTTPException(403, "Access denied to report bug"); } $new_bug_id = bug_create($new_bugdata); email_new_bug($new_bug_id); if ($new_bug_id) { $new_bug_url = Bug::get_url_from_mantis_id($new_bug_id); $this->rsrc_data = $new_bug_url; $resp = new Response(); $resp->status = 201; $resp->headers[] = "location: {$new_bug_url}"; $resp->body = $this->_repr($request); return $resp; } else { throw new HTTPException(500, "Failed to create bug"); } }