Skip to content

Commit

Permalink
[battery manager] duplicate check fix (aces#9355)
Browse files Browse the repository at this point in the history
Add a request method param to tests to only check and avoid performing duplicate
checks during the update operation.
  • Loading branch information
kongtiaowang authored and ZhichGaming committed Nov 25, 2024
1 parent e8b0426 commit 950aeaf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/battery_manager/php/testendpoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,18 @@ class TestEndpoint extends \NDB_Page implements RequestHandlerInterface
$testArray = json_decode($request->getBody()->getContents(), true);
$test = new Test($this->loris, null, $testArray);
$test->row['active'] = 'Y';
return $this->_saveInstance($test);
return $this->_saveInstance($test, "post");
}

/**
* Generic save function for Test Instances.
*
* @param Test $test The Test Instance to be saved.
* @param Test $test The Test Instance to be saved.
* @param string $method check the request method
*
* @return ResponseInterface response
*/
private function _saveInstance(Test $test)
private function _saveInstance(Test $test , $method=null)
{
if (!$this->user->hasPermission('battery_manager_edit')) {
return new \LORIS\Http\Response\JSON\Forbidden('Edit Permission Denied');
Expand All @@ -183,7 +184,7 @@ class TestEndpoint extends \NDB_Page implements RequestHandlerInterface
}

// check if instance is duplicate
if ($this->_isDuplicate($test)) {
if ($this->_isDuplicate($test) && $method =='post') {
return new \LORIS\Http\Response\JSON\Conflict(
'This Test already exists in the database'
);
Expand Down

0 comments on commit 950aeaf

Please sign in to comment.