Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
withanage committed Jan 8, 2024
1 parent 10fad57 commit ecc352e
Show file tree
Hide file tree
Showing 184 changed files with 2,855 additions and 631 deletions.
56 changes: 11 additions & 45 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,20 @@
on: [push,pull_request]
name: ops
on: [push, pull_request]
name: upgrade
jobs:
validate:
name: validate
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
application: ['ojs','omp','ops']
php-version: [ '8.1','8.2' ]
steps:
- uses: withanage/validate-action@v1
with:
application: '${{matrix.application}}'
repository: '${{github.repository_owner}}'
branch: '${{ github.head_ref || github.ref_name }}'
test:
name: test
runs-on: ubuntu-latest
# needs: validate
strategy:
fail-fast: false
matrix:
application: ['ojs','omp','ops']
php-version: [ '8.1','8.2' ]
database: [ 'pgsql', 'mysql','mariadb']
steps:
- uses: actions/checkout@v4

- uses: withanage/test-action@v1
with:
application: '${{matrix.application}}'
repository: '${{github.repository_owner}}'
branch: '${{ github.head_ref || github.ref_name }}'
upgrade:
name: upgrade
runs-on: ubuntu-latest
# needs: test
strategy:
fail-fast: false
matrix:
application: ['ojs','omp','ops']
dataset-branch: [ 'stable-3_4_0','stable-3_3_0','stable-3_2_1','stable-3_2_0' ]
database: [ 'pgsql','mysql']
php-version: [ '8.1' ]
application: ['omp','ojs','ops']
database: ['pgsql','mysql']
php-version: [ '8.1' ,'8.2']

name: upgrade
steps:
- uses: withanage/upgrade-action@v1
- uses: xmlFlow/upgrade-action@v1
with:
application: '${{matrix.application}}'
repository: '${{github.repository_owner}}'
branch: '${{ github.head_ref || github.ref_name }}'

application: ${{matrix.application}}
repository: 'pkp'
branch: 'main'
upgrade: true
218 changes: 218 additions & 0 deletions api/v1/jats/PKPJatsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
<?php

/**
* @file api/v1/jats/PKPJatsController.php
*
* Copyright (c) 2023 Simon Fraser University
* Copyright (c) 2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PKPJatsController
*
* @ingroup api_v1_jats
*
* @brief Handle API requests for JATS File operations.
*
*/

namespace PKP\API\v1\jats;

use APP\core\Application;
use APP\facades\Repo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use PKP\core\PKPBaseController;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\security\authorization\internal\SubmissionFileStageAccessPolicy;
use PKP\security\authorization\PublicationAccessPolicy;
use PKP\security\authorization\PublicationWritePolicy;
use PKP\security\authorization\SubmissionFileAccessPolicy;
use PKP\security\authorization\UserRolesRequiredPolicy;
use PKP\security\Role;
use PKP\services\PKPSchemaService;
use PKP\submissionFile\SubmissionFile;

class PKPJatsController extends PKPBaseController
{
/**
* @copydoc \PKP\core\PKPBaseController::getHandlerPath()
*/
public function getHandlerPath(): string
{
return 'submissions/{submissionId}/publications/{publicationId}/jats';
}

/**
* @copydoc \PKP\core\PKPBaseController::getRouteGroupMiddleware()
*/
public function getRouteGroupMiddleware(): array
{
return [
'has.user',
'has.context',
];
}

public function getGroupRoutes(): void
{
Route::middleware([
self::roleAuthorizer([
Role::ROLE_ID_MANAGER,
Role::ROLE_ID_SITE_ADMIN,
Role::ROLE_ID_SUB_EDITOR,
Role::ROLE_ID_ASSISTANT,
Role::ROLE_ID_AUTHOR,
]),
])->group(function () {

Route::get('', $this->get(...))
->name('publication.jats.get');

Route::post('', $this->add(...))
->name('publication.jats.add');

Route::delete('', $this->delete(...))
->name('publication.jats.delete');

})->whereNumber(['submissionId', 'publicationId']);
}

/**
* @copydoc \PKP\core\PKPBaseController::authorize()
*/
public function authorize(PKPRequest $request, array &$args, array $roleAssignments): bool
{
$illuminateRequest = $args[0]; /** @var \Illuminate\Http\Request $illuminateRequest */
$actionName = static::getRouteActionName($illuminateRequest);

$this->addPolicy(new UserRolesRequiredPolicy($request), true);

$this->addPolicy(new ContextAccessPolicy($request, $roleAssignments));

if ($actionName === 'get') {
$this->addPolicy(new PublicationAccessPolicy($request, $args, $roleAssignments));
} else {
$this->addPolicy(new PublicationWritePolicy($request, $args, $roleAssignments));
}

if ($actionName === 'add') {
$params = $illuminateRequest->input();
$fileStage = isset($params['fileStage']) ? (int) $params['fileStage'] : SubmissionFile::SUBMISSION_FILE_JATS;
$this->addPolicy(
new SubmissionFileStageAccessPolicy(
$fileStage,
SubmissionFileAccessPolicy::SUBMISSION_FILE_ACCESS_MODIFY,
'api.submissionFiles.403.unauthorizedFileStageIdWrite'
)
);
}

return parent::authorize($request, $args, $roleAssignments);
}

/**
* Get JATS XML Files
*/
public function get(Request $illuminateRequest): JsonResponse
{
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
$publication = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_PUBLICATION);

if (!$publication) {
return response()->json([
'error' => __('api.404.resourceNotFound'),
], Response::HTTP_NOT_FOUND);
}

$context = Application::get()->getRequest()->getContext();
$genreDao = DAORegistry::getDAO('GenreDAO');
$genres = $genreDao->getEnabledByContextId($context->getId());

$jatsFile = Repo::jats()
->getJatsFile($publication->getId(), $submission->getId(), $genres->toArray());

$jatsFilesProp = Repo::jats()
->summarize($jatsFile);

return response()->json($jatsFilesProp, Response::HTTP_OK);
}

/**
* Add a JATS XML Submission File to a publication
*/
public function add(Request $illuminateRequest): JsonResponse
{
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
$publication = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_PUBLICATION);

if (empty($_FILES)) {
return response()->json([
'error' => __('api.files.400.noUpload'),
], Response::HTTP_BAD_REQUEST);
}

if ($_FILES['file']['error'] !== UPLOAD_ERR_OK) {
return $this->getUploadErrorResponse($_FILES['file']['error']);
}

$params = $this->convertStringsToSchema(PKPSchemaService::SCHEMA_SUBMISSION_FILE, $illuminateRequest->input());

Repo::jats()
->addJatsFile(
$_FILES['file']['tmp_name'],
$_FILES['file']['name'],
$publication->getId(),
$submission->getId(),
SubmissionFile::SUBMISSION_FILE_JATS,
$params);

$context = Application::get()->getRequest()->getContext();
$genreDao = DAORegistry::getDAO('GenreDAO');
$genres = $genreDao->getEnabledByContextId($context->getId());

$jatsFile = Repo::jats()
->getJatsFile($publication->getId(), $submission->getId(), $genres->toArray());

$jatsFilesProp = Repo::jats()
->summarize($jatsFile);

return response()->json($jatsFilesProp, Response::HTTP_OK);
}

/**
* Delete the publication's JATS Submission file
*/
public function delete(Request $illuminateRequest): JsonResponse
{
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
$publication = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_PUBLICATION);

$context = Application::get()->getRequest()->getContext();
$genreDao = DAORegistry::getDAO('GenreDAO');
$genres = $genreDao->getEnabledByContextId($context->getId());

$jatsFile = Repo::jats()
->getJatsFile($publication->getId(), $submission->getId(), $genres->toArray());

if (!$jatsFile->submissionFile) {
return response()->json([
'error' => __('api.404.resourceNotFound'),
], Response::HTTP_NOT_FOUND);
}

Repo::submissionFile()
->delete($jatsFile->submissionFile);

$jatsFile = Repo::jats()
->getJatsFile($publication->getId(), $submission->getId(), $genres->toArray());

$jatsFilesProp = Repo::jats()
->summarize($jatsFile);

return response()->json($jatsFilesProp, Response::HTTP_OK);
}
}
9 changes: 5 additions & 4 deletions api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@ public function getGroupRoutes(): void
]);
}




/**
* @copydoc \PKP\core\PKPBaseController::authorize()
*/
Expand Down Expand Up @@ -838,6 +835,7 @@ public function getParticipants(Request $illuminateRequest): JsonResponse
$request = Application::get()->getRequest();
$context = $request->getContext();
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
$args = $illuminateRequest->input();
$stageId = $args['stageId'] ?? null;

if (!$submission || $submission->getData('contextId') !== $context->getId()) {
Expand Down Expand Up @@ -1591,8 +1589,11 @@ public function saveContributorsOrder(Request $illuminateRequest): JsonResponse
->filterByPublicationIds([$publication->getId()])
->getMany();

$authorsArray = Repo::author()->getSchemaMap()->summarizeMany($authors)->toArray();
$indexedArray = array_values($authorsArray);

return response()->json(
Repo::author()->getSchemaMap()->summarizeMany($authors),
$indexedArray,
Response::HTTP_OK
);
}
Expand Down
28 changes: 28 additions & 0 deletions classes/author/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,32 @@ public function getLocalizedUserGroupName()
$userGroup = $this->getUserGroup();
return $userGroup->getLocalizedName();
}

/**
* Get competing interests.
*
* @return string|array|null
*/
public function getCompetingInterests(?string $locale)
{
return $this->getData('competingInterests', $locale);
}

/**
* Set competing interests.
*
* @param $competingInterests string|array|null
*/
public function setCompetingInterests($competingInterests, ?string $locale)
{
$this->setData('competingInterests', $competingInterests, $locale);
}

/**
* Get a localized version competing interest statement
*/
public function getLocalizedCompetingInterests(): ?string
{
return $this->getLocalizedData('competingInterests');
}
}
19 changes: 5 additions & 14 deletions classes/cliTool/CommandLineTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use PKP\config\Config;
use PKP\core\Registry;
use PKP\plugins\PluginRegistry;
use PKP\security\Role;
use PKP\session\SessionManager;
use PKP\user\User;

Expand Down Expand Up @@ -109,26 +108,18 @@ private function checkArgsForUsername()

unset($this->argv[$usernameKeyPos]);
}

if ($this->username) {
$user = Repo::user()->getByUsername($this->username, true);

$this->setUser($user);
}

if (!$this->user) {
$adminGroups = Repo::userGroup()->getArrayIdByRoleId(Role::ROLE_ID_SITE_ADMIN);

if (count($adminGroups)) {
$groupUsers = Repo::user()->getCollector()
->filterByUserGroupIds([$adminGroups[0]])
->getMany();

if ($groupUsers->isNotEmpty()) {
$this->setUser($groupUsers->first());
} else {
$this->exitWithUsageMessage();
}
$adminUsers = Repo::user()->getAdminUsers();
if ($adminUsers->isNotEmpty()) {
$this->setUser($adminUsers->first());
} else {
$this->exitWithUsageMessage();
}
}
}
Expand Down
Loading

0 comments on commit ecc352e

Please sign in to comment.