|
27 | 27 | use APP\section\Section;
|
28 | 28 | use APP\submission\Submission;
|
29 | 29 | use APP\template\TemplateManager;
|
| 30 | +use Illuminate\Support\Collection; |
30 | 31 | use Illuminate\Support\LazyCollection;
|
31 | 32 | use PKP\components\forms\FormComponent;
|
32 | 33 | use PKP\components\forms\publication\Details;
|
|
36 | 37 | use PKP\facades\Locale;
|
37 | 38 | use PKP\pages\submission\PKPSubmissionHandler;
|
38 | 39 | use PKP\plugins\Hook;
|
| 40 | +use PKP\security\Role; |
39 | 41 | use PKP\submission\GenreDAO;
|
| 42 | +use PKP\user\User; |
| 43 | +use PKP\userGroup\UserGroup; |
40 | 44 |
|
41 | 45 | class SubmissionHandler extends PKPSubmissionHandler
|
42 | 46 | {
|
@@ -295,4 +299,29 @@ protected function getConfirmSubmitMessage(Submission $submission, Context $cont
|
295 | 299 | }
|
296 | 300 | return __('submission.wizard.confirmSubmit', ['context' => $context->getLocalizedName()]);
|
297 | 301 | }
|
| 302 | + |
| 303 | + /** |
| 304 | + * Get the user groups that a user can submit in |
| 305 | + */ |
| 306 | + protected function getSubmitUserGroups(Context $context, User $user): Collection |
| 307 | + { |
| 308 | + $userGroups = UserGroup::query() |
| 309 | + ->withContextIds([$context->getId()]) |
| 310 | + ->withUserIds([$user->getId()]) |
| 311 | + ->withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_AUTHOR]) |
| 312 | + ->get(); |
| 313 | + |
| 314 | + // Users without a submitting role can submit as an |
| 315 | + // author role that allows self registration |
| 316 | + if ($userGroups->isEmpty()) { |
| 317 | + $defaultUserGroup = UserGroup::withContextIds([$context->getId()]) |
| 318 | + ->withRoleIds([Role::ROLE_ID_AUTHOR]) |
| 319 | + ->permitSelfRegistration(true) |
| 320 | + ->first(); |
| 321 | + |
| 322 | + $userGroups = collect($defaultUserGroup ? [$defaultUserGroup->id => $defaultUserGroup] : []); |
| 323 | + } |
| 324 | + |
| 325 | + return $userGroups; |
| 326 | + } |
298 | 327 | }
|
0 commit comments