Skip to content

Commit

Permalink
Merge branch 'pkp:main' into structured-citations
Browse files Browse the repository at this point in the history
  • Loading branch information
GaziYucel authored Nov 4, 2024
2 parents 1df2f9f + 499f720 commit e58ecf0
Show file tree
Hide file tree
Showing 46 changed files with 1,814 additions and 274 deletions.
8 changes: 8 additions & 0 deletions api/v1/invitations/InvitationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ public function authorize(PKPRequest $request, array &$args, array $roleAssignme
throw new Exception('This invitation does not support API handling');
}

if (in_array($actionName, $this->requiresOnlyId) && $this->invitation->getStatus() != InvitationStatus::INITIALIZED) {
throw new Exception('This action is not allowed');
}

if (in_array($actionName, $this->requiresIdAndKey) && $this->invitation->getStatus() != InvitationStatus::PENDING) {
throw new Exception('This action is not allowed');
}

$this->createInvitationHandler = $invitation->getCreateInvitationController($this->invitation);
$this->receiveInvitationHandler = $invitation->getReceiveInvitationController($this->invitation);

Expand Down
23 changes: 4 additions & 19 deletions classes/components/forms/context/PKPAppearanceSetupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,18 @@ public function __construct($action, $locales, $context, $baseUrl, $temporaryFil
$this->action = $action;
$this->locales = $locales;
$sidebarOptions = [];
$enabledOptions = [];
$disabledOptions = [];

$currentBlocks = (array) $context->getData('sidebar');

$plugins = PluginRegistry::loadCategory('blocks', true);

foreach ($currentBlocks as $plugin) {
if (isset($plugins[$plugin])) {
$enabledOptions[] = [
'value' => $plugin,
'label' => htmlspecialchars($plugins[$plugin]->getDisplayName()),
];
}
}

foreach ($plugins as $pluginName => $plugin) {
if (!in_array($pluginName, $currentBlocks)) {
$disabledOptions[] = [
'value' => $pluginName,
'label' => htmlspecialchars($plugin->getDisplayName()),
];
}
$sidebarOptions[] = [
'value' => $pluginName,
'label' => htmlspecialchars($plugin->getDisplayName()),
];
}

$sidebarOptions = array_merge($enabledOptions, $disabledOptions);

$this->addField(new FieldUploadImage('pageHeaderLogoImage', [
'label' => __('manager.setup.logo'),
'value' => $context->getData('pageHeaderLogoImage'),
Expand Down
87 changes: 87 additions & 0 deletions classes/components/forms/invitation/AcceptUserDetailsForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* @file classes/components/forms/invitation/AcceptUserDetailsForm.php
*
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class AcceptUserDetailsForm
*
*
* @brief Handles accept invitation user details form
*/

namespace PKP\components\forms\invitation;

use PKP\components\forms\FieldSelect;
use PKP\components\forms\FieldText;
use PKP\components\forms\FormComponent;
use PKP\facades\Locale;

class AcceptUserDetailsForm extends FormComponent
{
public const ACCEPT_FORM_USER_DETAILS = 'acceptUserDetails';
/** @copydoc FormComponent::$id */
public $id = self::ACCEPT_FORM_USER_DETAILS;

/** @copydoc FormComponent::$method */
public $method = 'POST';

/**
* Constructor
*
* @param string $action URL to submit the form to
* @param array $locales Supported locales
*/
public function __construct($action, $locales)
{
$this->action = $action;
$this->locales = $locales;

$countries = [];
foreach (Locale::getCountries() as $country) {
$countries[] = [
'value' => $country->getAlpha2(),
'label' => $country->getLocalName()
];
}

usort($countries, function ($a, $b) {
return strcmp($a['label'], $b['label']);
});

$this->addField(new FieldText('givenName', [
'label' => __('user.givenName'),
'description' => __('acceptInvitation.userDetailsForm.givenName.description'),
'isRequired' => true,
'isMultilingual' => true,
'size' => 'large',
'value' => ''
]))
->addField(new FieldText('familyName', [
'label' => __('user.familyName'),
'description' => __('acceptInvitation.userDetailsForm.familyName.description'),
'isRequired' => false,
'isMultilingual' => true,
'size' => 'large',
'value' => ''
]))
->addField(new FieldText('affiliation', [
'label' => __('user.affiliation'),
'description' => __('acceptInvitation.userDetailsForm.affiliation.description'),
'isMultilingual' => true,
'isRequired' => false,
'size' => 'large',

]))
->addField(new FieldSelect('userCountry', [
'label' => __('acceptInvitation.userDetailsForm.countryOfAffiliation.label'),
'description' => __('acceptInvitation.userDetailsForm.countryOfAffiliation.description'),
'options' => $countries,
'isRequired' => true,
'size' => 'large',
]));

}
}
68 changes: 68 additions & 0 deletions classes/components/forms/invitation/UserDetailsForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* @file classes/components/forms/invitation/UserDetailsForm.php
*
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class AcceptUserDetailsForm
*
*
* @brief Handles send invitation user details form
*/

namespace PKP\components\forms\invitation;

use PKP\components\forms\FieldHTML;
use PKP\components\forms\FieldText;
use PKP\components\forms\FormComponent;

class UserDetailsForm extends FormComponent
{
public const FORM_USER_DETAILS = 'userDetails';
/** @copydoc FormComponent::$id */
public $id = self::FORM_USER_DETAILS;

/** @copydoc FormComponent::$method */
public $method = 'POST';

/**
* Constructor
*
* @param string $action URL to submit the form to
* @param array $locales Supported locales
*/
public function __construct(string $action, array $locales)
{
$this->action = $action;
$this->locales = $locales;

$this->addField(new FieldText('inviteeEmail', [
'label' => __('user.email'),
'description' => __('invitation.email.description'),
'isRequired' => true,
'size' => 'large',
]))
->addField(new FieldHTML('orcid', [
'label' => __('user.orcid'),
'description' => __('invitation.orcid.description'),
'isRequired' => false,
'size' => 'large',
]))
->addField(new FieldText('givenName', [
'label' => __('user.givenName'),
'description' => __('invitation.givenName.description'),
'isRequired' => false,
'isMultilingual' => true,
'size' => 'large',
]))
->addField(new FieldText('familyName', [
'label' => __('user.familyName'),
'description' => __('invitation.familyName.description'),
'isRequired' => false,
'isMultilingual' => true,
'size' => 'large',
]));
}
}
4 changes: 2 additions & 2 deletions classes/core/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ public function _cacheContent(string $contents): string
/**
* Handle a 404 error (page not found).
*/
public static function handle404()
public static function handle404(string $message = "404 Not Found"): void
{
header('HTTP/1.0 404 Not Found');
echo "<h1>404 Not Found</h1>\n";
echo "<h1>" . htmlspecialchars($message) . "</h1>\n";
exit;
}
}
Expand Down
7 changes: 7 additions & 0 deletions classes/file/PKPLibraryFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PKP\context\LibraryFile;
use PKP\context\LibraryFileDAO;
use PKP\db\DAORegistry;
use PKP\plugins\Hook;

class PKPLibraryFileManager extends PrivateFileManager
{
Expand Down Expand Up @@ -168,6 +169,7 @@ public function getFileSuffixFromType($type)
/**
* Get the type => suffix mapping array
*
* @hook PublisherLibrary::types::suffixes [[&$map]]
* @return array
*/
public function &getTypeSuffixMap()
Expand All @@ -178,6 +180,7 @@ public function &getTypeSuffixMap()
LibraryFile::LIBRARY_FILE_TYPE_REPORT => 'REP',
LibraryFile::LIBRARY_FILE_TYPE_OTHER => 'OTH'
];
Hook::call('PublisherLibrary::types::suffixes', [&$map]);
return $map;
}

Expand All @@ -199,6 +202,7 @@ public function getNameFromType($type)
/**
* Get the type => locale key mapping array
*
* @hook PublisherLibrary::types::titles [[&$map]]
* @return array
*/
public function &getTypeTitleKeyMap()
Expand All @@ -209,6 +213,7 @@ public function &getTypeTitleKeyMap()
LibraryFile::LIBRARY_FILE_TYPE_REPORT => 'settings.libraryFiles.category.reports',
LibraryFile::LIBRARY_FILE_TYPE_OTHER => 'settings.libraryFiles.category.other'
];
Hook::call('PublisherLibrary::types::titles', [&$map]);
return $map;
}

Expand All @@ -226,6 +231,7 @@ public function getTitleKeyFromType($type)
/**
* Get the type => name mapping array
*
* @hook PublisherLibrary::types::names [[&$typeNameMap]]
* @return array
*/
public function &getTypeNameMap()
Expand All @@ -236,6 +242,7 @@ public function &getTypeNameMap()
LibraryFile::LIBRARY_FILE_TYPE_REPORT => 'reports',
LibraryFile::LIBRARY_FILE_TYPE_OTHER => 'other',
];
Hook::call('PublisherLibrary::types::names', [&$typeNameMap]);
return $typeNameMap;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class UserRoleAssignmentInvite extends Invitation implements IApiHandleable

protected array $notAccessibleAfterInvite = [
'userGroupsToAdd',
'userGroupsToRemove',
];

protected array $notAccessibleBeforeInvite = [
Expand Down Expand Up @@ -164,8 +163,7 @@ public function getValidationRules(ValidationContext $validationContext = Valida
$validationContext === ValidationContext::VALIDATION_CONTEXT_FINALIZE
) {
$invitationValidationRules[Invitation::VALIDATION_RULE_GENERIC][] = new NoUserGroupChangesRule(
$this->getPayload()->userGroupsToAdd,
$this->getPayload()->userGroupsToRemove
$this->getPayload()->userGroupsToAdd
);
$invitationValidationRules[Invitation::VALIDATION_RULE_GENERIC][] = new UserMustExistRule($this->getUserId());
$invitationValidationRules[Invitation::VALIDATION_RULE_GENERIC][] = new EmailMustNotExistRule($this->getEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

use APP\core\Request;
use APP\template\TemplateManager;
use PKP\core\PKPApplication;
use PKP\invitation\core\enums\InvitationAction;
use PKP\invitation\core\enums\InvitationStatus;
use PKP\invitation\core\InvitationActionRedirectController;
use PKP\invitation\invitations\userRoleAssignment\UserRoleAssignmentInvite;
use PKP\invitation\stepTypes\AcceptInvitationStep;
use APP\facades\Repo;

class UserRoleAssignmentInviteRedirectController extends InvitationActionRedirectController
{
Expand All @@ -26,17 +30,62 @@ public function getInvitation(): UserRoleAssignmentInvite
return $this->invitation;
}

/**
* Redirect to accept invitation page
* @param Request $request
* @return void
* @throws \Exception
*/
public function acceptHandle(Request $request): void
{
$templateMgr = TemplateManager::getManager($request);

$templateMgr->assign('invitation', $this->invitation);
$templateMgr->display('frontend/pages/invitations.tpl');
$context = $request->getContext();
$steps = new AcceptInvitationStep();
$invitationModel = $this->invitation->invitationModel->toArray();
$user = $invitationModel['userId'] ?Repo::user()->get($invitationModel['userId']) : null;
$templateMgr->setState([
'steps' => $steps->getSteps($this->invitation,$context,$user),
'primaryLocale' => $context->getData('primaryLocale'),
'pageTitle' => __('invitation.wizard.pageTitle'),
'invitationId' => (int)$request->getUserVar('id') ?: null,
'invitationKey' => $request->getUserVar('key') ?: null,
'pageTitleDescription' => __('invitation.wizard.pageTitleDescription'),
]);
$templateMgr->assign([
'pageComponent' => 'PageOJS',
]);
$templateMgr->display('invitation/acceptInvitation.tpl');
}

/**
* Redirect to login page after decline invitation
* @param Request $request
* @return void
* @throws \Exception
*/
public function declineHandle(Request $request): void
{
return;
if ($this->invitation->getStatus() !== InvitationStatus::PENDING) {
$request->getDispatcher()->handle404('The link is deactivated as the invitation was cancelled');
}

$context = $request->getContext();

$url = PKPApplication::get()->getDispatcher()->url(
PKPApplication::get()->getRequest(),
PKPApplication::ROUTE_PAGE,
$context->getData('urlPath'),
'login',
null,
null,
[
]
);

$this->getInvitation()->decline();

$request->redirectUrl($url);
}

public function preRedirectActions(InvitationAction $action)
Expand Down
Loading

0 comments on commit e58ecf0

Please sign in to comment.