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 user. * * The user will get a confirmation email, and will have the password provided * in the incoming representation. * * @param $request - The Request we're responding to */ if (!access_has_global_level(config_get('manage_user_threshold'))) { throw new HTTPException(403, "Access denied to create user"); } $new_user = new User(); $new_user->populate_from_repr($request->body); $username = $new_user->mantis_data['username']; $password = $new_user->mantis_data['password']; $email = email_append_domain($new_user->mantis_data['email']); $access_level = $new_user->mantis_data['access_level']; $protected = $new_user->mantis_data['protected']; $enabled = $new_user->mantis_data['enabled']; $realname = $new_user->mantis_data['realname']; if (!user_is_name_valid($username)) { throw new HTTPException(500, "Invalid username"); } elseif (!user_is_realname_valid($realname)) { throw new HTTPException(500, "Invalid realname"); } user_create($username, $password, $email, $access_level, $protected, $enabled, $realname); $new_user_id = user_get_id_by_name($username); $new_user_url = User::get_url_from_mantis_id($new_user_id); $this->rsrc_data = $new_user_url; $resp = new Response(); $resp->status = 201; $resp->headers[] = "location: {$new_user_url}"; $resp->body = $this->_repr($request); return $resp; }