Skip to content

Commit

Permalink
pkp/pkp-lib#3594 Add entity schema, Context API, and Vue.js forms
Browse files Browse the repository at this point in the history
- Add journal and site schema
- Load journal and site defaults from schema
- Add source file for generating API docs using cli tool
- Document /context, /site, /temporaryFiles, /context/{id}/themeOptions,
  /_payments API endpoints
- Update journal_settings and site_settings db schema to remove setting_type
- Convert journal and site settings forms to Vue.js
- Deprecate Context::getSettings() in favor of Context::getData()
- Remove unused context settings: copyeditInstructions, refLinkInstructions,
  metaCitations, authorSelfArchivePolicy
- Change sequence to seq in API to match underlying data structure
- Add json linting to tests
- Add private endpoint for handling payment settings forms
- Migrate handling of journal stylesheet to pkp-lib
- Migrate active block plugins from plugin_settings to journal_settings
- Move article permission reset to tools
- Improve authorization failure responses in API
- Replace metadata grid with form fields
- Remove unused Reading Tools locale strings
- Replace journal settings wizard
- Rename ListHandlers to ListPanels and move to /components directory
- Add licenseTerms in place of copyrightNotice on article landing
- Update help panel to avoid using .md extensions, to fix issues with
  serves which try to serve the actual file instead of routing to our
handlers.
  • Loading branch information
NateWr committed Oct 23, 2018
1 parent d19b36a commit 4dd3043
Show file tree
Hide file tree
Showing 289 changed files with 14,890 additions and 9,244 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ script:
./lib/pkp/tools/travis/validate-xml.sh
./lib/pkp/tools/buildjs.sh -n
./lib/pkp/tools/checkHelp.sh
./lib/pkp/tools/travis/validate-json.sh
fi
after_script:
Expand Down
112 changes: 112 additions & 0 deletions api/v1/_payments/BackendPaymentsSettingsHandler.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* @file api/v1/_submissions/BackendPaymentsSettingsHandler.inc.php
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class BackendPaymentsSettingsHandler
* @ingroup api_v1_backend
*
* @brief A private API endpoint handler for payment settings. It may be
* possible to deprecate this when we have a working endpoint for plugin
* settings.
*/
import('lib.pkp.classes.handler.APIHandler');
import('classes.core.ServicesContainer');

class BackendPaymentsSettingsHandler extends APIHandler {

/**
* Constructor
*/
public function __construct() {
$rootPattern = '/{contextPath}/api/{version}/_payments';
$this->_endpoints = array_merge_recursive($this->_endpoints, array(
'PUT' => array(
array(
'pattern' => $rootPattern,
'handler' => array($this, 'editPayments'),
'roles' => array(
ROLE_ID_SITE_ADMIN,
ROLE_ID_MANAGER,
),
),
),
));
parent::__construct();
}

/**
* @copydoc PKPHandler::authorize
*/
public function authorize($request, &$args, $roleAssignments) {
import('lib.pkp.classes.security.authorization.PolicySet');
$rolePolicy = new PolicySet(COMBINING_PERMIT_OVERRIDES);

import('lib.pkp.classes.security.authorization.RoleBasedHandlerOperationPolicy');
foreach ($roleAssignments as $role => $operations) {
$rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations));
}
$this->addPolicy($rolePolicy);

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

/**
* Receive requests to edit the payments form
*
* @param $slimRequest Request Slim request object
* @param $response Response object
*
* @return Response
*/
public function editPayments($slimRequest, $response, $args) {
$request = $this->getRequest();
$context = $request->getContext();
$params = $slimRequest->getParsedBody();
$contextService = ServicesContainer::instance()->get('context');

// Process query params to format incoming data as needed
foreach ($slimRequest->getParsedBody() as $param => $val) {
switch ($param) {
case 'paymentsEnabled':
$params[$param] = $val === 'true';
break;
case 'currency':
$params[$param] = (string) $val;
break;
}
}

if (isset($params['currency'])) {
$errors = $contextService->validate(
VALIDATE_ACTION_EDIT,
['currency' => $params['currency']],
$context->getSupportedLocales(),
$context->getPrimaryLocale()
);
if (!empty($errors)) {
return $response->withStatus(400)->withJson($errors);
}
}

$paymentPlugins = PluginRegistry::loadCategory('paymethod', true);
$errors = [];
foreach ($paymentPlugins as $paymentPlugin) {
$errors = array_merge(
$errors,
$paymentPlugin->saveSettings($params, $slimRequest, $request)
);
}
if (!empty($errors)) {
return $response->withStatus(400)->withJson($errors);
}

$context = $contextService->getContext($context->getId());
$context = $contextService->editContext($context, $params, $request);

return $response->withJson($params);
}
}
20 changes: 20 additions & 0 deletions api/v1/_payments/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @defgroup api_v1_backend Backend API requests for payments settings
*/

/**
* @file api/v1/_payments/index.php
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @ingroup api_v1_backend
* @brief Handle requests for backend API.
*
*/

import('api.v1._payments.BackendPaymentsSettingsHandler');
return new BackendPaymentsSettingsHandler();
15 changes: 15 additions & 0 deletions api/v1/contexts/ContextHandler.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* @file api/v1/contexts/ContextHandler.inc.php
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class ContextHandler
* @ingroup api_v1_contexts
*
* @brief Handle API requests for contexts (journals/presses).
*/
import('lib.pkp.api.v1.contexts.PKPContextHandler');
class ContextHandler extends PKPContextHandler { }
17 changes: 17 additions & 0 deletions api/v1/contexts/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* @defgroup api_v1_contexts Context API requests
*/

/**
* @file api/v1/contexts/index.php
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @ingroup api_v1_contexts
* @brief Handle API requests for contexts (journals/presses).
*/
import('api.v1.contexts.ContextHandler');
return new ContextHandler();
6 changes: 3 additions & 3 deletions api/v1/issues/IssueHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getIssueList($slimRequest, $response, $args) {
$issueService = ServicesContainer::instance()->get('issue');

if (!$context) {
return $response->withStatus(404)->withJsonError('api.submissions.404.resourceNotFound');
return $response->withStatus(404)->withJsonError('api.404.resourceNotFound');
}

$defaultParams = array(
Expand Down Expand Up @@ -203,7 +203,7 @@ public function getCurrentIssue($slimRequest, $response, $args) {
$issue = $issueDao->getCurrent($context->getId());

if (!$issue) {
return $response->withStatus(404)->withJsonError('api.submissions.404.resourceNotFound');
return $response->withStatus(404)->withJsonError('api.404.resourceNotFound');
}

$data = ServicesContainer::instance()
Expand All @@ -230,7 +230,7 @@ public function getIssue($slimRequest, $response, $args) {
$issue = $this->getAuthorizedContextObject(ASSOC_TYPE_ISSUE);

if (!$issue) {
return $response->withStatus(404)->withJsonError('api.submissions.404.resourceNotFound');
return $response->withStatus(404)->withJsonError('api.404.resourceNotFound');
}

$data = ServicesContainer::instance()
Expand Down
Loading

0 comments on commit 4dd3043

Please sign in to comment.