Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions app/controllers/xapi/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,40 @@ public function getAttachedContent($name='content') {
public function getPostContent($name){
if (\Input::hasFile($name)) {
$content = \Input::file($name);
$type = $content->getClientMimeType();
} else if (\LockerRequest::hasParam($name)) {
$content = \LockerRequest::getParam('content');
$type = is_object(json_decode($content)) ? 'application/json' : 'text/plain';
$contentType = $content->getClientMimeType();
} else if (\LockerRequest::getContent()) {
$content = \LockerRequest::getContent();

$contentType = \LockerRequest::header('Content-Type');
$isForm = $this->checkFormContentType($contentType);

if( !$contentType || $isForm ){
$contentType = is_object(json_decode($content)) ? 'application/json' : 'text/plain';
}

} else {
\App::abort(400, sprintf('`%s` was not sent in this request', $name));
}

return [
'content' => $content,
'contentType' => $type
'contentType' => $contentType
];
}

/**
* Determines if $contentType is a form.
* @param string $contentType
* @return boolean
*/
private function checkFormContentType($contentType = '') {
if (!is_string($contentType)) return false;
return in_array(explode(';', $contentType)[0], [
'multipart/form-data',
'application/x-www-form-urlencoded'
]);
}

/**
* Generates content response.
* @param mixed $data used to select the Document.
Expand Down
32 changes: 9 additions & 23 deletions app/locker/request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public function getParams() {
if ($this->params === null || count($this->params) < 1) {
$requestParams = \Request::all();
$payloadParams = $this->getPayloadParams();
$this->params = array_merge($requestParams, $payloadParams);

// Merges params if they are both arrays.
if (is_array($requestParams) && is_array($payloadParams)) {
$this->params = array_merge($requestParams, $payloadParams);
} else {
$this->params = $requestParams;
}
}

// Return the cached params.
Expand All @@ -42,35 +48,15 @@ public function getPayloadParams() {
* @return String user in the basic auth.
*/
public function getUser() {
$user = \Request::getUser();

// If the password is set in the headers then return it.
if ($user) {
return $user;
}

// Else return it from the payload.
else {
return $this->getAuth()[self::authUser];
}
return \Request::getUser() ?: $this->getAuth()[self::authUser];
}

/**
* Gets the password from the basic auth.
* @return String password in the basic auth.
*/
public function getPassword() {
$pass = \Request::getPassword();

// If the password is set in the headers then return it.
if ($pass) {
return $pass;
}

// Else return it from the payload.
else {
return $this->getAuth()[self::authPass];
}
return \Request::getPassword() ?: $this->getAuth()[self::authPass];
}

/**
Expand Down
10 changes: 3 additions & 7 deletions app/models/DocumentAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,15 @@ public function setContent( $content_info, $method){
break;

case "text/plain":
if( !$this->exists ){
if( !$this->exists || $method === 'PUT' ){
$this->content = $content;
} else {
if ($method === 'PUT') {
$this->content = $content;
} else {
\App::abort(400, sprintf('Cannot amend existing %s document with a string', $this->contentType) );
}
\App::abort(400, sprintf('Cannot amend existing %s document with a string', $this->contentType) );
}
break;

default:
if( !$this->exists ){ // check we are adding a new document
if( !$this->exists || $method === 'PUT' ){ // check we are adding a new document
//HANDLE FILE SAVES???
$dir = $this->getContentDir();

Expand Down
3 changes: 2 additions & 1 deletion app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,9 @@
'code' => $code
);


if( Config::get('app.debug') ){
$error['trace'] = $exception->getTrace();
$error['trace'] = $exception->getTraceAsString();
}

return Response::json( $error, $code);
Expand Down
2 changes: 1 addition & 1 deletion app/tests/StatementPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testPostAuthService()
];

$response = $this->_makeRequest($param, "POST", $auth);
//dd($response);

$responseData = $response->getContent();
$responseStatus = $response->getStatusCode();

Expand Down