Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
223b134
instrument API PUT endpoint to exception based validate
regisoc Jun 4, 2025
f5e0a1c
internal array_all for php < 8.4
regisoc Jun 4, 2025
40c24a5
default instrument metadata element names
regisoc Jun 4, 2025
1cd9002
instrument - validation method update
regisoc Jun 4, 2025
40563a7
instrument flag endpoint update
regisoc Jun 4, 2025
d7f3dbd
instrument endpoint update
regisoc Jun 4, 2025
61b88f5
instrument api fallback exceptions cases
regisoc Jun 4, 2025
31a9a41
lint
regisoc Jun 4, 2025
51bf977
instrument validate only data
regisoc Jun 10, 2025
8017dea
instrument and flags endpoint to validate data
regisoc Jun 10, 2025
c919618
test- flag checks - rm instrument validation
regisoc Jun 10, 2025
2e23e98
instrument validation from API instrument - instrument name
regisoc Jun 10, 2025
76bbb05
instrument validate - additional fields and exception message
regisoc Jun 10, 2025
7f46e8b
instrument validate test update
regisoc Jun 10, 2025
bb292b2
test lint
regisoc Jun 10, 2025
17942bf
lint
regisoc Jun 12, 2025
f66e204
lint
regisoc Jun 19, 2025
7c9bd47
null option fix
regisoc Jun 19, 2025
a0d9777
instrument additional field note
regisoc Jun 19, 2025
a2f4a68
instrument validate test - missing/additional field keys
regisoc Jun 19, 2025
3957d2d
validate instrument data - message fix
regisoc Jun 19, 2025
98e1afe
typo
regisoc Jun 20, 2025
5deaeba
instrument validate keys - trim
regisoc Jun 20, 2025
21ac6ba
instrument validate instrument data test - include facotry creation
regisoc Jun 20, 2025
1974a31
instrument class as global import
regisoc Jun 20, 2025
6a34687
fix unit test
kongtiaowang Jun 27, 2025
7de47f5
phan cs
kongtiaowang Jun 27, 2025
4addc5b
phan cs
kongtiaowang Jun 27, 2025
934791c
fix patch mothed
kongtiaowang Jun 27, 2025
abd7dd7
test
kongtiaowang Jun 27, 2025
734a58e
fix request
kongtiaowang Jun 27, 2025
fa52dac
fix
kongtiaowang Jun 27, 2025
d5ca715
fix
kongtiaowang Jun 27, 2025
c7086fd
fix
kongtiaowang Jun 27, 2025
5683910
fix
kongtiaowang Jun 27, 2025
e941923
fix var
kongtiaowang Jun 27, 2025
21a97f2
fix var
kongtiaowang Jun 27, 2025
11b4623
try
kongtiaowang Jun 27, 2025
6840edf
try
kongtiaowang Jun 27, 2025
69eba3e
try
kongtiaowang Jun 27, 2025
e0ff627
try
kongtiaowang Jun 27, 2025
1383e91
try
kongtiaowang Jun 27, 2025
8f536e6
done
kongtiaowang Jun 28, 2025
562d365
done
kongtiaowang Jun 28, 2025
2b0a09c
done
kongtiaowang Jun 28, 2025
656ac7d
todo rm dubug
kongtiaowang Jun 28, 2025
a40f7ee
todo rm dubug
kongtiaowang Jun 28, 2025
ed28579
rm debug
kongtiaowang Jul 2, 2025
4f4635f
handle PUT instrument flag endpoint - remove data_entry complete check
regisoc Jul 9, 2025
b4d4ccc
handle PATCH instrument flag endpoint - remove data_entry complete check
regisoc Jul 9, 2025
a1a4f5d
fusion instrument PATCH/PUT
regisoc Jul 24, 2025
08efd43
instrument validate to check all or part of the payload values
regisoc Jul 24, 2025
2a3002d
instrument put test update
regisoc Jul 24, 2025
eed39e3
clear userid to var
regisoc Jul 24, 2025
72539ac
put instrument
regisoc Jul 24, 2025
95631ca
trail end
regisoc Jul 24, 2025
e701003
clear userid to var
regisoc Jul 24, 2025
bf1f386
put/patch dde flag
regisoc Jul 24, 2025
90523ec
remove bmi ref
regisoc Jul 24, 2025
8fcf94d
move data from bmi to testtest instrument
regisoc Jul 24, 2025
0eb9414
v0.0.4 api put/patch update test
regisoc Jul 24, 2025
d8ad013
v0.0.4 api put/patch update test
regisoc Jul 24, 2025
6a64fd3
remove server/request post mention
regisoc Oct 3, 2025
004f428
including github action fix from #10034
regisoc Oct 3, 2025
0ba4053
trigger
regisoc Dec 16, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/loristest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
# (see https://github.com/actions/runner-images/blob/releases/ubuntu22/20230305/images/linux/Ubuntu2204-Readme.md)
# that updated the list of installed apt packages/apt repositories. That issue may disappear in future Ubuntu images.
run: |
sudo apt-get update
sudo apt install -y imagemagick-6-common libmagickcore-6.q16-7t64 libmagickwand-6.q16-7t64 \
libprotobuf-dev libprotobuf32t64 libprotoc32t64 protobuf-compiler
cd modules/electrophysiology_browser/jsx/react-series-data-viewer/
Expand Down Expand Up @@ -268,6 +269,7 @@ jobs:
# (see https://github.com/actions/runner-images/blob/releases/ubuntu22/20230305/images/linux/Ubuntu2204-Readme.md)
# that updated the list of installed apt packages/apt repositories. That issue may disappear in future Ubuntu images.
run: |
sudo apt-get update
sudo apt install -y imagemagick-6-common libmagickcore-6.q16-7t64 libmagickwand-6.q16-7t64 \
libprotobuf-dev libprotobuf32t64 libprotoc32t64 protobuf-compiler
cd modules/electrophysiology_browser/jsx/react-series-data-viewer/
Expand Down
15 changes: 15 additions & 0 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
// See: https://www.php.net/manual/en/session.configuration.php#ini.session.use-strict-mode
ini_set('session.use_strict_mode', '1');

// TODO: Remove this code once PHP 8.4 becomes the minimal PHP version in LORIS.
if (version_compare(PHP_VERSION, '8.4', '<')) {
// @phan-file-suppress PhanRedefineFunctionInternal

// phpcs:ignore
function array_all(array $array, callable $callable): bool {
foreach ($array as $key => $value) {
if (!$callable($value, $key)) {
return false;
}
}
return true;
}
}

// FIXME: The code in NDB_Client should mostly be replaced by middleware.
$client = new \NDB_Client;
$client->initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,27 +156,19 @@ class Flags extends Endpoint implements \LORIS\Middleware\ETagCalculator
$this->_instrumentStatus = new \NDB_BVL_InstrumentStatus($loris);
$this->_instrumentStatus->select($this->_instrument->commentID);

if (!$this->_instrument->determineDataEntryAllowed()) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Can not update instruments that are flagged as complete.'
);
}

$data = json_decode((string) $request->getBody(), true);

if (!is_array($data)) {
return new \LORIS\Http\Response\JSON\BadRequest(
'Invalid request'
);
}
if (!$this->_instrument->validate($data)) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Could not update.'
if (!array_key_exists('Flags', $data)) {
return new \LORIS\Http\Response\JSON\BadRequest(
"Invalid request. 'Flags' missing."
);
}

try {

$requiredfields = [
'Data_entry',
'Administration',
Expand Down Expand Up @@ -229,22 +221,15 @@ class Flags extends Endpoint implements \LORIS\Middleware\ETagCalculator
$this->_instrumentStatus = new \NDB_BVL_InstrumentStatus($loris);
$this->_instrumentStatus->select($this->_instrument->commentID);

if (!$this->_instrument->determineDataEntryAllowed()) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Can not update instruments that are flagged as complete.'
);
}

$data = json_decode((string) $request->getBody(), true);
if (!is_array($data)) {
return new \LORIS\Http\Response\JSON\BadRequest(
'Invalid request'
);
}

if (!$this->_instrument->validate($data)) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Could not update.'
if (!array_key_exists('Flags', $data)) {
return new \LORIS\Http\Response\JSON\BadRequest(
"Invalid request. 'Flags' missing."
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,41 +170,7 @@ class Instrument extends Endpoint implements \LORIS\Middleware\ETagCalculator
*/
private function _handlePUT(ServerRequestInterface $request) : ResponseInterface
{
if (!$this->_instrument->determineDataEntryAllowed()) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Can not update instruments that are flagged as complete.'
);
}

$data = json_decode((string) $request->getBody(), true);
if (!is_array($data)) {
return new \LORIS\Http\Response\JSON\BadRequest(
'Invalid request'
);
}

if (!$this->_instrument->validate($data)) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Could not update.'
);
}

try {
$this->_instrument->clearInstrument();
$version = $request->getAttribute('LORIS-API-Version');
if ($version == 'v0.0.3') {
$instrumentname = $this->_instrument->testName;
$this->_instrument->_saveValues($data[$instrumentname]);
} else {
$this->_instrument->_saveValues($data['Data']);
}
$this->_instrument->score();
$this->_instrument->updateRequiredElementsCompletedFlag();
} catch (\Throwable $e) {
error_log($e->getMessage());
return new \LORIS\Http\Response\JSON\InternalServerError();
}
return (new \LORIS\Http\Response\JSON\NoContent());
return $this->_handlePATCHAndPUT($request);
}

/**
Expand All @@ -217,40 +183,86 @@ class Instrument extends Endpoint implements \LORIS\Middleware\ETagCalculator
*/
private function _handlePATCH(ServerRequestInterface $request): ResponseInterface
{
return $this->_handlePATCHAndPUT($request);
}

/**
* Handles a PUT and PATCH request.
* Mainly serves as a quick PATCH/PUT selection to validate all (PUT) or
* part (PATCH) of the sent payload.
*
* @param ServerRequestInterface $request The incoming PSR7 request
*
* @return ResponseInterface The outgoing PSR7 response
*/
private function _handlePATCHAndPUT(
ServerRequestInterface $request
): ResponseInterface {
$requestType = $request->getMethod();
if ($requestType !== "PATCH" && $requestType !== "PUT") {
return new \LORIS\Http\Response\JSON\BadRequest(
'Invalid request'
);
}
$isRequestPUT = $requestType === "PUT";

// data entry allowed?
if (!$this->_instrument->determineDataEntryAllowed()) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Can not update instruments that are flagged as complete.'
);
}

// get payload
$data = json_decode((string) $request->getBody(), true);
if (!is_array($data)) {
return new \LORIS\Http\Response\JSON\BadRequest(
'Invalid request'
);
}

if (!$this->_instrument->validate($data)) {
// validate given data against the instrument
$instrumentName = $this->_instrument->testName;
try {
$version = $request->getAttribute('LORIS-API-Version');

// extract data according to LORIS API version
$instrumentData = $version == 'v0.0.3'
? ($data[$instrumentName] ?? [])
: ($data['Data'] ?? []);

// validate
$this->_instrument->validate(
$instrumentData,
$isRequestPUT
);
} catch (\LorisException $th) {
return new \LORIS\Http\Response\JSON\BadRequest(
"Could not update. {$th->getMessage()}"
);
} catch (\Throwable $th) {
error_log($th->getMessage());
return new \LORIS\Http\Response\JSON\Forbidden(
'Could not update.'
"Could not update."
);
}

// update values
try {
$version = $request->getAttribute('LORIS-API-Version');
if ($version == 'v0.0.3') {
$instrumentname = $this->_instrument->testName;
$this->_instrument->_saveValues($data[$instrumentname]);
} else {
$this->_instrument->_saveValues($data['Data']);
// only clear if PUT
if ($isRequestPUT) {
$this->_instrument->clearInstrument();
}

// save/score data
$this->_instrument->_saveValues($instrumentData);
$this->_instrument->score();
$this->_instrument->updateRequiredElementsCompletedFlag();
} catch (\Throwable $e) {
error_log($e->getMessage());
return new \LORIS\Http\Response\JSON\InternalServerError();
}
return (new \LORIS\Http\Response\JSON\NoContent());
return new \LORIS\Http\Response\JSON\NoContent();
}

/**
Expand Down
Loading
Loading