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

PHRAS-3770 quarantine-enhancement #4352

Merged
merged 17 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
50 changes: 43 additions & 7 deletions lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ public function addElement(Request $request, $file_id)
/** @var LazaretManipulator $lazaretManipulator */
$lazaretManipulator = $this->app['manipulator.lazaret'];

//Check if the chosen record is eligible to the substitution
$recordId = $request->request->get('record_id');
/** @var LazaretFile $lazaretFile */
$metadatasToSet = [];
if($recordId !== "" && !!$request->request->get('copy_meta', false)) {

$substitutedRecord = null;

$lazaretFile = $this->getLazaretFileRepository()->find($file_id);
foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $r) {
if ($r->getRecordId() === (int)$recordId) {
$substitutedRecord = $r;
break;
}
}
if (!$substitutedRecord) {
$ret['message'] = $this->app->trans('The destination record provided is not allowed');

return $this->app->json($ret);
}

$fieldsToCopy = [];
foreach ($substitutedRecord->getDatabox()->get_meta_structure() as $df) {
if(!$df->is_readonly()) {
$fieldsToCopy[] = $df->get_name();
}
}
foreach ($substitutedRecord->getCaption($fieldsToCopy) as $k=>$v) {
$metadatasToSet[] = ['field_name' => $k, 'value' => $v];
}
}

$ret = $lazaretManipulator->add($file_id, $keepAttributes, $attributesToKeep);

try{
Expand All @@ -140,7 +172,13 @@ public function addElement(Request $request, $file_id)
$postStatus = (array) $request->request->get('status');
// update status
$this->updateRecordStatus($record, $postStatus);
}catch(\Exception $e){

if(!empty($metadatasToSet)) {
$actions = json_decode(json_encode(['metadatas' => $metadatasToSet]));
$record->setMetadatasByActions($actions);
}
}
catch(\Exception $e){
$ret['message'] = $this->app->trans('An error occured when wanting to change status!');
}

Expand Down Expand Up @@ -229,16 +267,14 @@ public function acceptElement(Request $request, $file_id)
return $this->app->json($ret);
}

$found = false;

//Check if the chosen record is eligible to the substitution
$found = false;
foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $record) {
if ($record->getRecordId() !== (int) $recordId) {
continue;
if ($record->getRecordId() === (int) $recordId) {
$found = true;
break;
}

$found = true;
break;
}

if (!$found) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ public function connect(Application $app)

$controllers->match('/search/', 'controller.api.v2.search:searchAction');

/** @uses LazaretController::quarantineItemEmptyAction */
$controllers->delete('/quarantine/', 'controller.api.v2.lazaret:quarantineItemEmptyAction')
->bind('api_v2_quarantine_empty');

/** @uses LazaretController::quarantineItemDeleteAction */
$controller = $controllers->delete('/quarantine/item/{lazaret_id}/', 'controller.api.v2.lazaret:quarantineItemDeleteAction')
->bind('api_v2_quarantine_item_delete');
$this->addQuarantineMiddleware($controller);

/** @uses LazaretController::quarantineItemAddAction */
$controller = $controllers->post('/quarantine/item/{lazaret_id}/add/', 'controller.api.v2.lazaret:quarantineItemAddAction')
->bind('api_v2_quarantine_item_add');
$this->addQuarantineMiddleware($controller);
Expand Down
8 changes: 8 additions & 0 deletions lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,40 @@ public function connect(Application $app)
$firewall->requireRight(\ACL::CANADDRECORD);
});

/** @uses LazaretController::listElement */
$controllers->get('/', 'controller.prod.lazaret:listElement')
->bind('lazaret_elements');

/** @uses LazaretController::getElement */
$controllers->get('/{file_id}/', 'controller.prod.lazaret:getElement')
->assert('file_id', '\d+')
->bind('lazaret_element');

/** @uses LazaretController::addElement */
$controllers->post('/{file_id}/force-add/', 'controller.prod.lazaret:addElement')
->assert('file_id', '\d+')
->bind('lazaret_force_add');

/** @uses LazaretController::denyElement */
$controllers->post('/{file_id}/deny/', 'controller.prod.lazaret:denyElement')
->assert('file_id', '\d+')
->bind('lazaret_deny_element');

/** @uses LazaretController::emptyLazaret */
$controllers->post('/empty/', 'controller.prod.lazaret:emptyLazaret')
->bind('lazaret_empty');

/** @uses LazaretController::acceptElement */
$controllers->post('/{file_id}/accept/', 'controller.prod.lazaret:acceptElement')
->assert('file_id', '\d+')
->bind('lazaret_accept');

/** @uses LazaretController::thumbnailElement */
$controllers->get('/{file_id}/thumbnail/', 'controller.prod.lazaret:thumbnailElement')
->assert('file_id', '\d+')
->bind('lazaret_thumbnail');

/** @uses LazaretController::getDestinationStatus */
$controllers->get('/{databox_id}/{record_id}/status', 'controller.prod.lazaret:getDestinationStatus')
->assert('databox_id', '\d+')
->assert('record_id', '\d+')
Expand Down
Loading