Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pages/submission/SubmissionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use APP\section\Section;
use APP\submission\Submission;
use APP\template\TemplateManager;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use PKP\components\forms\FormComponent;
use PKP\components\forms\publication\Details;
Expand All @@ -36,7 +37,10 @@
use PKP\facades\Locale;
use PKP\pages\submission\PKPSubmissionHandler;
use PKP\plugins\Hook;
use PKP\security\Role;
use PKP\submission\GenreDAO;
use PKP\user\User;
use PKP\userGroup\UserGroup;

class SubmissionHandler extends PKPSubmissionHandler
{
Expand Down Expand Up @@ -295,4 +299,37 @@ protected function getConfirmSubmitMessage(Submission $submission, Context $cont
}
return __('submission.wizard.confirmSubmit', ['context' => $context->getLocalizedName()]);
}

/**
* Get the user groups that a user can submit in
*/
protected function getSubmitUserGroups(Context $context, User $user): Collection
{
$userGroups = UserGroup::query()
->withContextIds([$context->getId()])
->withUserIds([$user->getId()])
->whereHas('userUserGroups', function ($query) use ($user) {
$query->withUserId($user->getId())->withActive();
})
->withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_AUTHOR])
->get();

// Users without a submitting role can submit as an
// author role that allows self registration
if ($userGroups->isEmpty()) {
Repo::userGroup()->assignUserToGroup(
$user->getId(),
Repo::userGroup()->getByRoleIds([Role::ROLE_ID_AUTHOR], $context->getId())->first()->id
);

$defaultUserGroup = UserGroup::withContextIds([$context->getId()])
->withRoleIds([Role::ROLE_ID_AUTHOR])
->permitSelfRegistration(true)
->first();

$userGroups = collect($defaultUserGroup ? [$defaultUserGroup->id => $defaultUserGroup] : []);
}

return $userGroups;
}
}