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

pkp/pkp-lib#3594 Add entity schema and Vue.js forms for context #3931

Merged
merged 4 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

112 changes: 112 additions & 0 deletions api/v1/_payments/PKPBackendPaymentsSettingsHandler.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* @file api/v1/_payments/PKPBackendPaymentsSettingsHandler.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 PKPBackendPaymentsSettingsHandler
* @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.Services');

class PKPBackendPaymentsSettingsHandler 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, 'edit'),
'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 edit($slimRequest, $response, $args) {
$request = $this->getRequest();
$context = $request->getContext();
$params = $slimRequest->getParsedBody();
$contextService = Services::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->get($context->getId());
$context = $contextService->edit($context, $params, $request);

return $response->withJson($params);
}
}
27 changes: 14 additions & 13 deletions api/v1/_submissions/PKPBackendSubmissionsHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import('lib.pkp.classes.handler.APIHandler');
import('lib.pkp.classes.submission.Submission');
import('classes.core.ServicesContainer');
import('classes.core.Services');

abstract class PKPBackendSubmissionsHandler extends APIHandler {

Expand All @@ -29,7 +29,7 @@ public function __construct() {
'GET' => array(
array(
'pattern' => "{$rootPattern}",
'handler' => array($this, 'getSubmissions'),
'handler' => array($this, 'getMany'),
'roles' => array(
ROLE_ID_SITE_ADMIN,
ROLE_ID_MANAGER,
Expand All @@ -43,7 +43,7 @@ public function __construct() {
'DELETE' => array(
array(
'pattern' => "{$rootPattern}/{submissionId}",
'handler' => array($this, 'deleteSubmission'),
'handler' => array($this, 'delete'),
'roles' => array(
ROLE_ID_SITE_ADMIN,
ROLE_ID_MANAGER,
Expand Down Expand Up @@ -72,7 +72,7 @@ function authorize($request, &$args, $roleAssignments) {
*
* @return Response
*/
public function getSubmissions($slimRequest, $response, $args) {
public function getMany($slimRequest, $response, $args) {

$request = $this->getRequest();
$currentUser = $request->getUser();
Expand Down Expand Up @@ -139,6 +139,8 @@ public function getSubmissions($slimRequest, $response, $args) {
}
}

$params['contextId'] = $context->getId();

\HookRegistry::call('API::_submissions::params', array(&$params, $slimRequest, $response));

// Prevent users from viewing submissions they're not assigned to,
Expand All @@ -147,8 +149,8 @@ public function getSubmissions($slimRequest, $response, $args) {
return $response->withStatus(403)->withJsonError('api.submissions.403.requestedOthersUnpublishedSubmissions');
}

$submissionService = ServicesContainer::instance()->get('submission');
$submissions = $submissionService->getSubmissions($context->getId(), $params);
$submissionService = Services::get('submission');
$submissions = $submissionService->getMany($params);
$items = array();
if (!empty($submissions)) {
$propertyArgs = array(
Expand All @@ -161,7 +163,7 @@ public function getSubmissions($slimRequest, $response, $args) {
}
$data = array(
'items' => $items,
'itemsMax' => $submissionService->getSubmissionsMaxCount($context->getId(), $params),
'itemsMax' => $submissionService->getMax($params),
);

return $response->withJson($data);
Expand All @@ -175,7 +177,7 @@ public function getSubmissions($slimRequest, $response, $args) {
* @param array $args arguments
* @return Response
*/
public function deleteSubmission($slimRequest, $response, $args) {
public function delete($slimRequest, $response, $args) {

$request = $this->getRequest();
$currentUser = $request->getUser();
Expand All @@ -187,22 +189,21 @@ public function deleteSubmission($slimRequest, $response, $args) {
$submission = $submissionDao->getById($submissionId);

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

if ($context->getId() != $submission->getContextId()) {
return $response->withStatus(403)->withJsonError('api.submissions.403.deleteSubmissionOutOfContext');
}

import('classes.core.ServicesContainer');
$submissionService = ServicesContainer::instance()
->get('submission');
import('classes.core.Services');
$submissionService = Services::get('submission');

if (!$submissionService->canCurrentUserDelete($submission)) {
return $response->withStatus(403)->withJsonError('api.submissions.403.unauthorizedDeleteSubmission');
}

$submissionService->deleteSubmission($submissionId);
$submissionService->delete($submissionId);

return $response->withJson(true);
}
Expand Down
Loading