Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instruments] Escaping issue sub-optimal - Redirect on save success to load defaults from database #7776

Merged
merged 1 commit into from
Nov 17, 2021
Merged
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
21 changes: 19 additions & 2 deletions php/libraries/NDB_BVL_Instrument.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2881,9 +2881,10 @@ abstract class NDB_BVL_Instrument extends NDB_Page
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$req = $request->getParsedBody();
$req = $request->getParsedBody();
$success = false;
if ($request->getMethod() === "POST" && !isset($req['ClearInstrument'])) {
$this->save();
$success = $this->save();
}

// Disable form if data entry is complete
Expand Down Expand Up @@ -2913,6 +2914,22 @@ abstract class NDB_BVL_Instrument extends NDB_Page
$this->freeze();
}

if ($success) {
$sessionID = $request->getQueryParams()["sessionID"];
$candID = $request->getQueryParams()["candID"];
$baseURL = \NDB_Factory::singleton()->settings()->getBaseURL();
$pageURL = !empty($this->page) ? urlencode($this->page) ."/" : "";
$url = $baseURL . "/instruments/" .
urlencode($this->testName) . "/" .
$pageURL .
'?commentID=' . urlencode($this->getCommentID()) .
'&candID=' . urlencode($candID) .
'&sessionID=' . urlencode($sessionID);
return (new \LORIS\Http\Response())
->withStatus(303)
->withHeader("Location", $url);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response should also have a 303 See Other response code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what other response code ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No other one. The code's name is See Other.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 2846 above in the same file has the exact same code, should we move this to a function ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2846 already had the 303? I don't see why it would be moved to a function.. setting the response code is always going to be context specific

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont like code duplication

}

return (new \LORIS\Http\Response())
->withBody(new \LORIS\Http\StringStream($this->display() ?? ""));
}
Expand Down