Skip to content

Commit

Permalink
PHRAS-3770_quarantine-enhancement (#4352)
Browse files Browse the repository at this point in the history
* wip

* add: quarantine: when "adding", can copy metadata from the selected record

* fix failing test ; add test for "add & copy caption" (to be completed with field values...)

* wip

* add: quarantine: when "adding", can copy metadata from the selected record

* fix failing test ; add test for "add & copy caption" (to be completed with field values...)

* fix add button (did nothing when no doc selected at right) ; add clickable label on "copy meta" ckbox

* fix missing sb-off icons
  • Loading branch information
jygaulier authored Nov 16, 2023
1 parent b4b7ebf commit dc80246
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 71 deletions.
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

0 comments on commit dc80246

Please sign in to comment.