Skip to content

Commit e58ecf0

Browse files
authored
Merge branch 'pkp:main' into structured-citations
2 parents 1df2f9f + 499f720 commit e58ecf0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1814
-274
lines changed

api/v1/invitations/InvitationController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ public function authorize(PKPRequest $request, array &$args, array $roleAssignme
221221
throw new Exception('This invitation does not support API handling');
222222
}
223223

224+
if (in_array($actionName, $this->requiresOnlyId) && $this->invitation->getStatus() != InvitationStatus::INITIALIZED) {
225+
throw new Exception('This action is not allowed');
226+
}
227+
228+
if (in_array($actionName, $this->requiresIdAndKey) && $this->invitation->getStatus() != InvitationStatus::PENDING) {
229+
throw new Exception('This action is not allowed');
230+
}
231+
224232
$this->createInvitationHandler = $invitation->getCreateInvitationController($this->invitation);
225233
$this->receiveInvitationHandler = $invitation->getReceiveInvitationController($this->invitation);
226234

classes/components/forms/context/PKPAppearanceSetupForm.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,18 @@ public function __construct($action, $locales, $context, $baseUrl, $temporaryFil
4343
$this->action = $action;
4444
$this->locales = $locales;
4545
$sidebarOptions = [];
46-
$enabledOptions = [];
47-
$disabledOptions = [];
4846

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

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

53-
foreach ($currentBlocks as $plugin) {
54-
if (isset($plugins[$plugin])) {
55-
$enabledOptions[] = [
56-
'value' => $plugin,
57-
'label' => htmlspecialchars($plugins[$plugin]->getDisplayName()),
58-
];
59-
}
60-
}
61-
6251
foreach ($plugins as $pluginName => $plugin) {
63-
if (!in_array($pluginName, $currentBlocks)) {
64-
$disabledOptions[] = [
65-
'value' => $pluginName,
66-
'label' => htmlspecialchars($plugin->getDisplayName()),
67-
];
68-
}
52+
$sidebarOptions[] = [
53+
'value' => $pluginName,
54+
'label' => htmlspecialchars($plugin->getDisplayName()),
55+
];
6956
}
7057

71-
$sidebarOptions = array_merge($enabledOptions, $disabledOptions);
72-
7358
$this->addField(new FieldUploadImage('pageHeaderLogoImage', [
7459
'label' => __('manager.setup.logo'),
7560
'value' => $context->getData('pageHeaderLogoImage'),
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* @file classes/components/forms/invitation/AcceptUserDetailsForm.php
4+
*
5+
* Copyright (c) 2014-2024 Simon Fraser University
6+
* Copyright (c) 2000-2024 John Willinsky
7+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
8+
*
9+
* @class AcceptUserDetailsForm
10+
*
11+
*
12+
* @brief Handles accept invitation user details form
13+
*/
14+
15+
namespace PKP\components\forms\invitation;
16+
17+
use PKP\components\forms\FieldSelect;
18+
use PKP\components\forms\FieldText;
19+
use PKP\components\forms\FormComponent;
20+
use PKP\facades\Locale;
21+
22+
class AcceptUserDetailsForm extends FormComponent
23+
{
24+
public const ACCEPT_FORM_USER_DETAILS = 'acceptUserDetails';
25+
/** @copydoc FormComponent::$id */
26+
public $id = self::ACCEPT_FORM_USER_DETAILS;
27+
28+
/** @copydoc FormComponent::$method */
29+
public $method = 'POST';
30+
31+
/**
32+
* Constructor
33+
*
34+
* @param string $action URL to submit the form to
35+
* @param array $locales Supported locales
36+
*/
37+
public function __construct($action, $locales)
38+
{
39+
$this->action = $action;
40+
$this->locales = $locales;
41+
42+
$countries = [];
43+
foreach (Locale::getCountries() as $country) {
44+
$countries[] = [
45+
'value' => $country->getAlpha2(),
46+
'label' => $country->getLocalName()
47+
];
48+
}
49+
50+
usort($countries, function ($a, $b) {
51+
return strcmp($a['label'], $b['label']);
52+
});
53+
54+
$this->addField(new FieldText('givenName', [
55+
'label' => __('user.givenName'),
56+
'description' => __('acceptInvitation.userDetailsForm.givenName.description'),
57+
'isRequired' => true,
58+
'isMultilingual' => true,
59+
'size' => 'large',
60+
'value' => ''
61+
]))
62+
->addField(new FieldText('familyName', [
63+
'label' => __('user.familyName'),
64+
'description' => __('acceptInvitation.userDetailsForm.familyName.description'),
65+
'isRequired' => false,
66+
'isMultilingual' => true,
67+
'size' => 'large',
68+
'value' => ''
69+
]))
70+
->addField(new FieldText('affiliation', [
71+
'label' => __('user.affiliation'),
72+
'description' => __('acceptInvitation.userDetailsForm.affiliation.description'),
73+
'isMultilingual' => true,
74+
'isRequired' => false,
75+
'size' => 'large',
76+
77+
]))
78+
->addField(new FieldSelect('userCountry', [
79+
'label' => __('acceptInvitation.userDetailsForm.countryOfAffiliation.label'),
80+
'description' => __('acceptInvitation.userDetailsForm.countryOfAffiliation.description'),
81+
'options' => $countries,
82+
'isRequired' => true,
83+
'size' => 'large',
84+
]));
85+
86+
}
87+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* @file classes/components/forms/invitation/UserDetailsForm.php
4+
*
5+
* Copyright (c) 2014-2024 Simon Fraser University
6+
* Copyright (c) 2000-2024 John Willinsky
7+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
8+
*
9+
* @class AcceptUserDetailsForm
10+
*
11+
*
12+
* @brief Handles send invitation user details form
13+
*/
14+
15+
namespace PKP\components\forms\invitation;
16+
17+
use PKP\components\forms\FieldHTML;
18+
use PKP\components\forms\FieldText;
19+
use PKP\components\forms\FormComponent;
20+
21+
class UserDetailsForm extends FormComponent
22+
{
23+
public const FORM_USER_DETAILS = 'userDetails';
24+
/** @copydoc FormComponent::$id */
25+
public $id = self::FORM_USER_DETAILS;
26+
27+
/** @copydoc FormComponent::$method */
28+
public $method = 'POST';
29+
30+
/**
31+
* Constructor
32+
*
33+
* @param string $action URL to submit the form to
34+
* @param array $locales Supported locales
35+
*/
36+
public function __construct(string $action, array $locales)
37+
{
38+
$this->action = $action;
39+
$this->locales = $locales;
40+
41+
$this->addField(new FieldText('inviteeEmail', [
42+
'label' => __('user.email'),
43+
'description' => __('invitation.email.description'),
44+
'isRequired' => true,
45+
'size' => 'large',
46+
]))
47+
->addField(new FieldHTML('orcid', [
48+
'label' => __('user.orcid'),
49+
'description' => __('invitation.orcid.description'),
50+
'isRequired' => false,
51+
'size' => 'large',
52+
]))
53+
->addField(new FieldText('givenName', [
54+
'label' => __('user.givenName'),
55+
'description' => __('invitation.givenName.description'),
56+
'isRequired' => false,
57+
'isMultilingual' => true,
58+
'size' => 'large',
59+
]))
60+
->addField(new FieldText('familyName', [
61+
'label' => __('user.familyName'),
62+
'description' => __('invitation.familyName.description'),
63+
'isRequired' => false,
64+
'isMultilingual' => true,
65+
'size' => 'large',
66+
]));
67+
}
68+
}

classes/core/Dispatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ public function _cacheContent(string $contents): string
304304
/**
305305
* Handle a 404 error (page not found).
306306
*/
307-
public static function handle404()
307+
public static function handle404(string $message = "404 Not Found"): void
308308
{
309309
header('HTTP/1.0 404 Not Found');
310-
echo "<h1>404 Not Found</h1>\n";
310+
echo "<h1>" . htmlspecialchars($message) . "</h1>\n";
311311
exit;
312312
}
313313
}

classes/file/PKPLibraryFileManager.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PKP\context\LibraryFile;
2121
use PKP\context\LibraryFileDAO;
2222
use PKP\db\DAORegistry;
23+
use PKP\plugins\Hook;
2324

2425
class PKPLibraryFileManager extends PrivateFileManager
2526
{
@@ -168,6 +169,7 @@ public function getFileSuffixFromType($type)
168169
/**
169170
* Get the type => suffix mapping array
170171
*
172+
* @hook PublisherLibrary::types::suffixes [[&$map]]
171173
* @return array
172174
*/
173175
public function &getTypeSuffixMap()
@@ -178,6 +180,7 @@ public function &getTypeSuffixMap()
178180
LibraryFile::LIBRARY_FILE_TYPE_REPORT => 'REP',
179181
LibraryFile::LIBRARY_FILE_TYPE_OTHER => 'OTH'
180182
];
183+
Hook::call('PublisherLibrary::types::suffixes', [&$map]);
181184
return $map;
182185
}
183186

@@ -199,6 +202,7 @@ public function getNameFromType($type)
199202
/**
200203
* Get the type => locale key mapping array
201204
*
205+
* @hook PublisherLibrary::types::titles [[&$map]]
202206
* @return array
203207
*/
204208
public function &getTypeTitleKeyMap()
@@ -209,6 +213,7 @@ public function &getTypeTitleKeyMap()
209213
LibraryFile::LIBRARY_FILE_TYPE_REPORT => 'settings.libraryFiles.category.reports',
210214
LibraryFile::LIBRARY_FILE_TYPE_OTHER => 'settings.libraryFiles.category.other'
211215
];
216+
Hook::call('PublisherLibrary::types::titles', [&$map]);
212217
return $map;
213218
}
214219

@@ -226,6 +231,7 @@ public function getTitleKeyFromType($type)
226231
/**
227232
* Get the type => name mapping array
228233
*
234+
* @hook PublisherLibrary::types::names [[&$typeNameMap]]
229235
* @return array
230236
*/
231237
public function &getTypeNameMap()
@@ -236,6 +242,7 @@ public function &getTypeNameMap()
236242
LibraryFile::LIBRARY_FILE_TYPE_REPORT => 'reports',
237243
LibraryFile::LIBRARY_FILE_TYPE_OTHER => 'other',
238244
];
245+
Hook::call('PublisherLibrary::types::names', [&$typeNameMap]);
239246
return $typeNameMap;
240247
}
241248
}

classes/invitation/invitations/userRoleAssignment/UserRoleAssignmentInvite.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class UserRoleAssignmentInvite extends Invitation implements IApiHandleable
4545

4646
protected array $notAccessibleAfterInvite = [
4747
'userGroupsToAdd',
48-
'userGroupsToRemove',
4948
];
5049

5150
protected array $notAccessibleBeforeInvite = [
@@ -164,8 +163,7 @@ public function getValidationRules(ValidationContext $validationContext = Valida
164163
$validationContext === ValidationContext::VALIDATION_CONTEXT_FINALIZE
165164
) {
166165
$invitationValidationRules[Invitation::VALIDATION_RULE_GENERIC][] = new NoUserGroupChangesRule(
167-
$this->getPayload()->userGroupsToAdd,
168-
$this->getPayload()->userGroupsToRemove
166+
$this->getPayload()->userGroupsToAdd
169167
);
170168
$invitationValidationRules[Invitation::VALIDATION_RULE_GENERIC][] = new UserMustExistRule($this->getUserId());
171169
$invitationValidationRules[Invitation::VALIDATION_RULE_GENERIC][] = new EmailMustNotExistRule($this->getEmail());

classes/invitation/invitations/userRoleAssignment/handlers/UserRoleAssignmentInviteRedirectController.php

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515

1616
use APP\core\Request;
1717
use APP\template\TemplateManager;
18+
use PKP\core\PKPApplication;
1819
use PKP\invitation\core\enums\InvitationAction;
20+
use PKP\invitation\core\enums\InvitationStatus;
1921
use PKP\invitation\core\InvitationActionRedirectController;
2022
use PKP\invitation\invitations\userRoleAssignment\UserRoleAssignmentInvite;
23+
use PKP\invitation\stepTypes\AcceptInvitationStep;
24+
use APP\facades\Repo;
2125

2226
class UserRoleAssignmentInviteRedirectController extends InvitationActionRedirectController
2327
{
@@ -26,17 +30,62 @@ public function getInvitation(): UserRoleAssignmentInvite
2630
return $this->invitation;
2731
}
2832

33+
/**
34+
* Redirect to accept invitation page
35+
* @param Request $request
36+
* @return void
37+
* @throws \Exception
38+
*/
2939
public function acceptHandle(Request $request): void
3040
{
3141
$templateMgr = TemplateManager::getManager($request);
32-
3342
$templateMgr->assign('invitation', $this->invitation);
34-
$templateMgr->display('frontend/pages/invitations.tpl');
43+
$context = $request->getContext();
44+
$steps = new AcceptInvitationStep();
45+
$invitationModel = $this->invitation->invitationModel->toArray();
46+
$user = $invitationModel['userId'] ?Repo::user()->get($invitationModel['userId']) : null;
47+
$templateMgr->setState([
48+
'steps' => $steps->getSteps($this->invitation,$context,$user),
49+
'primaryLocale' => $context->getData('primaryLocale'),
50+
'pageTitle' => __('invitation.wizard.pageTitle'),
51+
'invitationId' => (int)$request->getUserVar('id') ?: null,
52+
'invitationKey' => $request->getUserVar('key') ?: null,
53+
'pageTitleDescription' => __('invitation.wizard.pageTitleDescription'),
54+
]);
55+
$templateMgr->assign([
56+
'pageComponent' => 'PageOJS',
57+
]);
58+
$templateMgr->display('invitation/acceptInvitation.tpl');
3559
}
3660

61+
/**
62+
* Redirect to login page after decline invitation
63+
* @param Request $request
64+
* @return void
65+
* @throws \Exception
66+
*/
3767
public function declineHandle(Request $request): void
3868
{
39-
return;
69+
if ($this->invitation->getStatus() !== InvitationStatus::PENDING) {
70+
$request->getDispatcher()->handle404('The link is deactivated as the invitation was cancelled');
71+
}
72+
73+
$context = $request->getContext();
74+
75+
$url = PKPApplication::get()->getDispatcher()->url(
76+
PKPApplication::get()->getRequest(),
77+
PKPApplication::ROUTE_PAGE,
78+
$context->getData('urlPath'),
79+
'login',
80+
null,
81+
null,
82+
[
83+
]
84+
);
85+
86+
$this->getInvitation()->decline();
87+
88+
$request->redirectUrl($url);
4089
}
4190

4291
public function preRedirectActions(InvitationAction $action)

0 commit comments

Comments
 (0)