-
Notifications
You must be signed in to change notification settings - Fork 3
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
D8AGE-291: The translate actions. #309
Merged
Merged
Changes from 39 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
6a219ba
D8AGE-291: Create the request updater.
intelektron ae1a8f7
D8AGE-291: Add the controller for operations.
intelektron acb3bc5
D8AGE-291: Adjust the callback controller.
intelektron e39f464
D8AGE-291: Move the status conversion to the updater.
intelektron becf87b
D8AGE-291: Add all fields support to the updater.
intelektron 0e8f524
D8AGE-291: Change the sample responses to be simplier.
intelektron be32c3a
D8AGE-291: Fix the Service Mock. for the Status API to support all fi…
intelektron 4115051
D8AGE-291: Mock the translation process.
intelektron 6189743
D8AGE-291: Support for fetching translated data.
intelektron 7a6f628
D8AGE-291: Sending all possible job/request statuses.
intelektron 42877ea
D8AGE-291: Cleanup obsolete exception.
intelektron e045d69
D8AGE-291: Update CDT branch.
intelektron 2d8e916
D8AGE-291: Fix the FileApi bug that was causing problems with status …
intelektron a7c7287
D8AGE-291: Two additional language statuses.
intelektron c12c1ef
D8AGE-291: An additional method for the remote translation entity.
intelektron 85a5f30
D8AGE-291: Status change hooks.
intelektron 12760de
D8AGE-291: Adjust to new File API endpoint.
intelektron 341143b
D8AGE-291: Fix actions bug in the mock module.
intelektron eb69eab
D8AGE-291: Downloading translations.
intelektron c0005eb
D8AGE-291: Additional status descriptions.
intelektron 71986d3
D8AGE-291: Extended language status transitions.
intelektron 78dcb93
D8AGE-291: Move statuses to constants.
intelektron bc935ab
D8AGE-291: Fix comments.
intelektron eba6725
D8AGE-291: Adjust tests.
intelektron 6ba9800
D8AGE-291: Tighten permissions.
intelektron 599fa01
D8AGE-291: Updated functional test.
intelektron 173124c
D8AGE-291: Fixed status API mock.
intelektron 4ed6696
D8AGE-291: Small updater improvements.
intelektron 5ebe535
D8AGE-291: Use constants for statuses.
intelektron 618755f
D8AGE-291: Kernel test for the Updater service.
intelektron bd182ad
D8AGE-291: Move the variable outside the loop, and rename buttons.
intelektron d618de7
D8AGE-291: Add comments to controller.
intelektron 488067b
D8AGE-291: Add namespace to tests.
intelektron d56bb92
D8AGE-291: Update test buttons.
intelektron 944d6d7
D8AGE-291: Phpcbf update and recheck.
intelektron 45b0d9e
D8AGE-291: Changed example URLs to be similar to CDT.
intelektron 1c9c26a
D8AGE-291: Changed API weights to avoid conflicts with the http mock …
intelektron 9ab107f
D8AGE-291: Revert changes to the endpoints.
intelektron edf1b2f
D8AGE-291: Change composer.json.
intelektron 76b2907
D8AGE-291: Fixed the interference with epoetry calls.
intelektron 66ea2f6
D8AGE-291: Updated the functional test.
intelektron ee3d4cb
D8AGE-341: Access checkers for the dashboard.
intelektron 0144c9f
D8AGE-341: Additional view fields.
intelektron 53a72c5
D8AGE-341: The dashboard view.
intelektron ccb4ab1
D8AGE-341: Simplify the additional classes.
intelektron 0d037d0
D8AGE-341: An addition to the functional test.
intelektron 229e125
D8AGE-341: Rename the access check and apply it to the routes.
intelektron 3264677
D8AGE-341: Change rendering method of field plugin.
intelektron 2c3a954
D8AGE-341: Fix the view schema.
intelektron 00d87bb
D8AGE-341: Kernel tests.
intelektron 734d208
D8AGE-341: Fix comments and strict standards.
intelektron 7318960
D8AGE-341: Add access tests.
intelektron 90ac5ce
D8AGE-341: Fixed the renderer to allow attaching libraries.
intelektron 5fa7dc3
D8AGE-341: Put the test inside a render context to avoid exceptions.
intelektron aeab27c
D8AGE-341: Fix the functional test after the rebase.
intelektron dc40226
Merge pull request #310 from openeuropa/D8AGE-341
drishu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
modules/oe_translation_cdt/modules/oe_translation_cdt_mock/oe_translation_cdt_mock.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Primary module hooks for OpenEuropa Translation CDT mock module. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface; | ||
use Drupal\Core\Entity\EntityInterface; | ||
use Drupal\Core\Url; | ||
use Drupal\oe_translation_cdt\Api\CdtApiWrapperInterface; | ||
use Drupal\oe_translation_cdt\TranslationRequestCdt; | ||
|
||
/** | ||
* Implements hook_entity_ENTITY_TYPE_view_alter(). | ||
*/ | ||
function oe_translation_cdt_mock_oe_translation_request_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) { | ||
if ($entity->bundle() !== 'cdt') { | ||
return; | ||
} | ||
|
||
/** @var \Drupal\oe_translation_cdt\TranslationRequestCdtInterface $entity */ | ||
if (!isset($build['meta'])) { | ||
return; | ||
} | ||
$row = &$build['meta']['#rows'][0]; | ||
|
||
$operations = []; | ||
$all_statuses = [ | ||
CdtApiWrapperInterface::STATUS_REQUEST_COMPLETED => 'Completed', | ||
CdtApiWrapperInterface::STATUS_REQUEST_IN_PROGRESS => 'In progress', | ||
CdtApiWrapperInterface::STATUS_REQUEST_CANCELLED => 'Cancelled', | ||
CdtApiWrapperInterface::STATUS_REQUEST_PENDING_APPROVAL => 'Pending approval', | ||
CdtApiWrapperInterface::STATUS_REQUEST_UNDER_QUOTATION => 'Under quotation', | ||
]; | ||
foreach ($all_statuses as $status => $label) { | ||
$operations[$status] = [ | ||
'title' => sprintf('Update status to %s (mock)', $label), | ||
'url' => Url::fromRoute('oe_translation_cdt_mock.request_status', [ | ||
'translation_request' => $entity->id(), | ||
], [ | ||
'query' => [ | ||
'destination' => Url::fromRoute('<current>')->toString(), | ||
'status' => $status, | ||
], | ||
]), | ||
]; | ||
} | ||
|
||
if (!isset($row['cdt_operations'])) { | ||
$row['cdt_operations'] = [ | ||
'data' => [ | ||
'#type' => 'operations', | ||
'#links' => $operations, | ||
], | ||
]; | ||
} | ||
else { | ||
$row['cdt_operations']['data']['#links'] += $operations; | ||
} | ||
} | ||
|
||
/** | ||
* Implements template_preprocess_table__remote_language_list(). | ||
*/ | ||
function oe_translation_cdt_mock_preprocess_table__remote_language_list(array &$variables) { | ||
$id = (string) $variables['attributes']['data-translation-request']; | ||
$request = TranslationRequestCdt::load($id); | ||
if (!$request || $request->bundle() !== 'cdt' || !$request->getCdtId()) { | ||
return; | ||
} | ||
|
||
$all_statuses = [ | ||
CdtApiWrapperInterface::STATUS_JOB_COMPLETED => 'Completed', | ||
CdtApiWrapperInterface::STATUS_JOB_FAILED => 'Failed', | ||
CdtApiWrapperInterface::STATUS_JOB_IN_PROGRESS => 'In progress', | ||
CdtApiWrapperInterface::STATUS_JOB_CANCELLED => 'Cancelled', | ||
CdtApiWrapperInterface::STATUS_JOB_TO_BE_CANCELLED => 'To be cancelled', | ||
]; | ||
foreach ($variables['rows'] as &$row) { | ||
$langcode = (string) $row['attributes']['hreflang']; | ||
foreach ($all_statuses as $status => $label) { | ||
$row['cells']['operations']['content']['#links'][] = [ | ||
'title' => sprintf('Update status to %s (mock)', $label), | ||
'url' => Url::fromRoute('oe_translation_cdt_mock.job_status', [ | ||
'translation_request' => $id, | ||
'langcode' => $langcode, | ||
], [ | ||
'query' => [ | ||
'destination' => Url::fromRoute('<current>')->toString(), | ||
'status' => $status, | ||
], | ||
]), | ||
]; | ||
} | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...es/oe_translation_cdt/modules/oe_translation_cdt_mock/oe_translation_cdt_mock.routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
oe_translation_cdt_mock.job_status: | ||
path: '/translation-request/cdt/mock/job_status/{translation_request}/{langcode}' | ||
defaults: | ||
_title: 'Change job status' | ||
_controller: '\Drupal\oe_translation_cdt_mock\Controller\MockController::changeJobStatus' | ||
requirements: | ||
_permission: 'translate any entity' | ||
options: | ||
parameters: | ||
translation_request: | ||
type: entity:oe_translation_request | ||
langcode: | ||
type: string | ||
|
||
oe_translation_cdt_mock.request_status: | ||
path: '/translation-request/cdt/mock/request_status/{translation_request}' | ||
defaults: | ||
_title: 'Change request status' | ||
_controller: '\Drupal\oe_translation_cdt_mock\Controller\MockController::changeRequestStatus' | ||
requirements: | ||
_permission: 'translate any entity' | ||
options: | ||
parameters: | ||
translation_request: | ||
type: entity:oe_translation_request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
modules/oe_translation_cdt/modules/oe_translation_cdt_mock/src/Controller/MockController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\oe_translation_cdt_mock\Controller; | ||
|
||
use Drupal\Core\Controller\ControllerBase; | ||
use Drupal\oe_translation_cdt\Mapper\LanguageCodeMapper; | ||
use Drupal\oe_translation_cdt\TranslationRequestCdtInterface; | ||
use Drupal\oe_translation_cdt\TranslationRequestUpdaterInterface; | ||
use OpenEuropa\CdtClient\Model\Callback\JobStatus; | ||
use OpenEuropa\CdtClient\Model\Callback\RequestStatus; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
/** | ||
* Returns responses for OpenEuropa Translation CDT mock routes. | ||
*/ | ||
final class MockController extends ControllerBase { | ||
|
||
/** | ||
* Constructs the controller. | ||
* | ||
* @param \Drupal\oe_translation_cdt\TranslationRequestUpdaterInterface $updater | ||
* The translation request updater. | ||
*/ | ||
public function __construct( | ||
private readonly TranslationRequestUpdaterInterface $updater, | ||
) {} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container): self { | ||
return new static( | ||
$container->get('oe_translation_cdt.translation_request_updater'), | ||
); | ||
} | ||
|
||
/** | ||
* Changes the translation job status by mocking. | ||
* | ||
* @param \Drupal\oe_translation_cdt\TranslationRequestCdtInterface $translation_request | ||
* The translation request. | ||
* @param string $langcode | ||
* The language code. | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* The request. | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
* The response. | ||
*/ | ||
public function changeJobStatus(TranslationRequestCdtInterface $translation_request, string $langcode, Request $request): Response { | ||
$job_status = new JobStatus(); | ||
$job_status->setTargetLanguageCode(LanguageCodeMapper::getCdtLanguageCode($langcode, $translation_request)); | ||
$job_status->setStatus((string) $request->query->get('status')); | ||
$job_status->setRequestIdentifier((string) $translation_request->getCdtId()); | ||
$this->updater->updateFromJobStatus($translation_request, $job_status); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We talked about the event dispatcher here, but it turns out that the separate updater service is a clean solution. |
||
|
||
$destination = $request->query->get('destination'); | ||
if (!$destination) { | ||
throw new NotFoundHttpException(); | ||
} | ||
return new RedirectResponse((string) $destination); | ||
} | ||
|
||
/** | ||
* Changes the translation request status by mocking. | ||
* | ||
* @param \Drupal\oe_translation_cdt\TranslationRequestCdtInterface $translation_request | ||
* The translation request. | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* The request. | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
* The response. | ||
*/ | ||
public function changeRequestStatus(TranslationRequestCdtInterface $translation_request, Request $request): Response { | ||
$request_status = new RequestStatus(); | ||
$request_status->setRequestIdentifier((string) $translation_request->getCdtId()); | ||
$request_status->setStatus((string) $request->query->get('status')); | ||
$this->updater->updateFromRequestStatus($translation_request, $request_status); | ||
|
||
$destination = $request->query->get('destination'); | ||
if (!$destination) { | ||
throw new NotFoundHttpException(); | ||
} | ||
return new RedirectResponse((string) $destination); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why but when using the "In progress" update option, there is no information logged in the request. Afaik we do not have an ongoing status for our requests but we should still log the update in the request logs. Same thing happens for the job updates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've got only these states of request in the CDT:
So I have no way to distinguish "requested" from "in progress".
The log is only written when there is an actual change. When you start the translation, it is already in INPR state.