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

Moving old AJAX routes to Api/App namespace #3619

Open
wants to merge 54 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
06ca404
fetchChangeRatesController
mauretto78 Oct 9, 2024
4b5c0c1
outsourceToController
mauretto78 Oct 10, 2024
fa439ff
error codes
mauretto78 Oct 10, 2024
ad80824
GetVolumeAnalysisController
mauretto78 Oct 10, 2024
8e32838
getProjectsController
mauretto78 Oct 10, 2024
c96d64a
DeleteContributionController
mauretto78 Oct 10, 2024
5b91dd6
commentController wip
mauretto78 Oct 10, 2024
e57eae9
wip
mauretto78 Oct 10, 2024
ae6b781
wip
mauretto78 Oct 10, 2024
fb357f7
wip
mauretto78 Oct 10, 2024
1d68ab2
wip
mauretto78 Oct 10, 2024
0212e20
deleted old commentController
mauretto78 Oct 10, 2024
ddc7754
CopyAllSourceToTargetController
mauretto78 Oct 10, 2024
51c2106
GetWarningController
mauretto78 Oct 11, 2024
0c1acda
splitJobController
mauretto78 Oct 11, 2024
0fe6168
userKeysController
mauretto78 Oct 11, 2024
0e4ce91
createRandUserController
mauretto78 Oct 11, 2024
a1248dd
getTagProjection
mauretto78 Oct 11, 2024
4efca9c
setCurrentSegmentController
mauretto78 Oct 11, 2024
ea12909
getSegmentsController
mauretto78 Oct 14, 2024
4ddbed3
ajaxUtilsController
mauretto78 Oct 14, 2024
0767d9c
GetTranslationMismatchesController
mauretto78 Oct 14, 2024
b04d0e7
engineController
mauretto78 Oct 15, 2024
6418dd6
GetContributionController
mauretto78 Oct 15, 2024
c1a016b
Handling Exception refactoring
mauretto78 Oct 15, 2024
c173622
getSearchController
mauretto78 Oct 15, 2024
13e6649
UpdateJobKeysController
mauretto78 Oct 15, 2024
a0496fa
setTranslationController
mauretto78 Oct 16, 2024
2fbb038
SplitSegmentController
mauretto78 Oct 16, 2024
0e3d2f5
Removed setSegmentSplitController
mauretto78 Oct 16, 2024
c8ab927
ChangeJobStatus
mauretto78 Oct 16, 2024
2271ba1
DownloadTMXController
mauretto78 Oct 16, 2024
d7d1ec2
CreateProjectController
mauretto78 Oct 21, 2024
316de23
convert file
mauretto78 Oct 22, 2024
b260359
SetChunkCompletedController
mauretto78 Oct 22, 2024
85ad30a
api/v1/new refactoring
mauretto78 Oct 23, 2024
48979f8
api/v1/new fix
mauretto78 Oct 23, 2024
810cd6c
Merge branch 'login-required' into remove-ajax-routes
mauretto78 Oct 23, 2024
d362787
refactoring wip
mauretto78 Oct 24, 2024
cb9d9a6
Adding return types
mauretto78 Oct 25, 2024
c95907d
return types
mauretto78 Oct 25, 2024
1bf56f1
code fixes
mauretto78 Oct 29, 2024
f0f19e5
code fix
mauretto78 Oct 29, 2024
9c14b4b
code fix
mauretto78 Oct 29, 2024
67c5cc0
Merge branch 'develop' into remove-ajax-routes
mauretto78 Nov 7, 2024
8639fe2
Merge branch 'develop' into remove-ajax-routes
mauretto78 Nov 8, 2024
2fb3938
DownloadAnalysisReportController
mauretto78 Nov 8, 2024
6328e4e
Update dependency webpack to v5.96.1 (#3710)
renovate[bot] Dec 2, 2024
9b43447
Update dependency react-hotkeys-hook to v4.6.1 (#3709)
renovate[bot] Dec 2, 2024
51040ae
Update dependency eslint-plugin-testing-library to v7 (#3711)
renovate[bot] Dec 2, 2024
ce48ca7
yarn.lock update
riccio82 Dec 2, 2024
20e3f7b
Merge remote-tracking branch 'origin/develop' into remove-ajax-routes
riccio82 Dec 3, 2024
4756ecf
Fix: refactoring old api ajax
riccio82 Dec 3, 2024
e92722a
Fix tests
riccio82 Dec 3, 2024
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: 0 additions & 2 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ RewriteRule ^activityLog/([^/]*)/([^/]*)[/]?(download)?$ index.php?action=activi
RewriteRule ^utils/xliff-to-target$ index.php?action=xliffToTargetView [L]
RewriteRule ^api/docs$ lib/View/APIDoc.php [L]

RewriteRule ^api/v1/new$ index.php?api=true&action=new [QSA,L]

RewriteRule ^(api)[/]?([^/]*)?[/]?$ index.php?api=true&action=$2 [QSA,L]
RewriteRule ^api/(.*)$ router.php [QSA,L]
RewriteRule ^webhooks/(.*)$ router.php [QSA,L]
Expand Down
71 changes: 71 additions & 0 deletions lib/Controller/API/App/AjaxUtilsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace API\App;

use API\Commons\KleinController;
use API\Commons\Validators\LoginValidator;
use ConnectedServices\Google\GDrive\Session;
use Database;
use Exception;
use InvalidArgumentException;
use Klein\Response;
use TMS\TMSService;

class AjaxUtilsController extends KleinController {

protected function afterConstruct() {
$this->appendValidator( new LoginValidator( $this ) );
}

public function ping(): Response
{
$db = Database::obtain();
$stmt = $db->getConnection()->prepare( "SELECT 1" );
$stmt->execute();

return $this->response->json([
'data' => [
"OK", time()
]
]);
}

public function checkTMKey(): Response
{
try {
$tm_key = filter_var( $this->request->param( 'tm_key' ), FILTER_SANITIZE_STRING, [ 'flags' => FILTER_FLAG_STRIP_LOW ] );

if ( empty($tm_key) ) {
throw new InvalidArgumentException("TM key not provided.", -9);
}

$tmxHandler = new TMSService();
$keyExists = $tmxHandler->checkCorrectKey( $tm_key );

if ( !isset( $keyExists ) || $keyExists === false ) {
throw new InvalidArgumentException("TM key is not valid.", -9);
}

return $this->response->json([
'success' => true
]);

} catch (Exception $exception){
return $this->returnException($exception);
}
}

public function clearNotCompletedUploads(): Response
{
try {
( new Session() )->cleanupSessionFiles();

return $this->response->json([
'success' => true
]);

} catch ( Exception $exception ) {
return $this->returnException($exception);
}
}
}
124 changes: 124 additions & 0 deletions lib/Controller/API/App/ChangeJobsStatusController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace API\App;

use API\Commons\KleinController;
use API\Commons\Validators\LoginValidator;
use Chunks_ChunkDao;
use Exception;
use Exceptions\NotFoundException;
use INIT;
use InvalidArgumentException;
use Jobs_JobDao;
use Klein\Response;
use Log;
use Projects_ProjectDao;
use Translations_SegmentTranslationDao;
use Utils;

class ChangeJobsStatusController extends KleinController {

protected function afterConstruct() {
$this->appendValidator( new LoginValidator( $this ) );
}

public function changeStatus(): Response
{
try {
$request = $this->validateTheRequest();

if ( $request['res_type'] == "prj" ) {

try {
$project = Projects_ProjectDao::findByIdAndPassword( $request['res_id'], $request['password'] );
} catch( Exception $e ){
$msg = "Error : wrong password provided for Change Project Status \n\n " . var_export( $_POST, true ) . "\n";
$this->log( $msg );
Utils::sendErrMailReport( $msg );
throw new NotFoundException("Job not found");
}

$chunks = $project->getJobs();

Jobs_JobDao::updateAllJobsStatusesByProjectId( $project->id, $request['new_status'] );

foreach( $chunks as $chunk ){
$lastSegmentsList = Translations_SegmentTranslationDao::getMaxSegmentIdsFromJob( $chunk );
Translations_SegmentTranslationDao::updateLastTranslationDateByIdList( $lastSegmentsList, Utils::mysqlTimestamp( time() ) );
}

} else {

try {
$firstChunk = Chunks_ChunkDao::getByIdAndPassword( $request['res_id'], $request['password'] );
} catch( Exception $e ){
$msg = "Error : wrong password provided for Change Job Status \n\n " . var_export( $_POST, true ) . "\n";
$this->log( $msg );
Utils::sendErrMailReport( $msg );
throw new NotFoundException("Job not found");
}

Jobs_JobDao::updateJobStatus( $firstChunk, $request['new_status'] );
$lastSegmentsList = Translations_SegmentTranslationDao::getMaxSegmentIdsFromJob( $firstChunk );
Translations_SegmentTranslationDao::updateLastTranslationDateByIdList( $lastSegmentsList, Utils::mysqlTimestamp( time() ) );
}

return $this->response->json([
'errors' => [],
'code' => 1,
'data' => 'OK',
'status' => $request['new_status']
]);

} catch (Exception $exception){
return $this->returnException($exception);
}
}

/**
* @return array
*/
private function validateTheRequest(): array
{
$name = filter_var( $this->request->param( 'name' ), FILTER_SANITIZE_STRING, [ 'flags' => FILTER_FLAG_STRIP_LOW ] );
$tm_key = filter_var( $this->request->param( 'tm_key' ), FILTER_SANITIZE_STRING, [ 'flags' => FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW ] );
$uuid = filter_var( $this->request->param( 'uuid' ), FILTER_SANITIZE_STRING, [ 'flags' => FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW ] );
$res_id = filter_var( $this->request->param( 'res_id' ), FILTER_VALIDATE_INT );
$password = filter_var( $this->request->param( 'password' ), FILTER_SANITIZE_STRING, [ 'flags' => FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW ] );
$new_status = filter_var( $this->request->param( 'new_status' ), FILTER_SANITIZE_STRING, [ 'flags' => FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW ] );

if ( empty( $tm_key ) ) {

if ( empty( INIT::$DEFAULT_TM_KEY ) ) {
throw new InvalidArgumentException("Please specify a TM key.", -2);
}

/*
* Added the default Key.
* This means if no private key are provided the TMX will be loaded in the default MyMemory key
*/
$tm_key = INIT::$DEFAULT_TM_KEY;
}

if ( empty( $res_id) ) {
throw new InvalidArgumentException("No id job provided", -1);
}

if ( empty( $password ) ) {
throw new InvalidArgumentException("No job password provided", -2);
}

if ( empty( $new_status ) ) {
throw new InvalidArgumentException("No new status provided", -3);
}

return [
'name' => $name,
'tm_key' => $tm_key,
'uuid' => $uuid,
'res_id' => $res_id,
'password' => $password,
'new_status' => $new_status,
];
}
}
Loading