From 6fcbd6c55f37419afe73c2cd3b26e0270e6c4ae7 Mon Sep 17 00:00:00 2001 From: Vitalii Bezsheiko Date: Fri, 13 Dec 2024 17:42:58 +0200 Subject: [PATCH 1/2] pkp/pkp-lib#10506 User Group refactoring to Eloquent Model --- api/v1/submissions/SubmissionController.php | 6 ++++-- .../forms/publication/PublicationLicenseForm.php | 5 +++-- classes/monograph/Chapter.php | 1 - classes/search/MonographSearch.php | 4 +++- classes/submission/Submission.php | 8 ++++++-- pages/catalog/CatalogBookHandler.php | 5 ++--- pages/catalog/CatalogHandler.php | 13 ++++++++++--- pages/index/IndexHandler.php | 5 ++++- pages/manageCatalog/ManageCatalogHandler.php | 5 ++--- pages/search/SearchHandler.php | 9 ++++----- plugins/importexport/csv/CSVImportExportPlugin.php | 13 +++++++------ plugins/reports/monographReport/Report.php | 8 +++++--- .../grid/settings/series/form/seriesForm.tpl | 4 ++-- .../grid/settings/user/userGroupsList.tpl | 2 +- 14 files changed, 53 insertions(+), 35 deletions(-) diff --git a/api/v1/submissions/SubmissionController.php b/api/v1/submissions/SubmissionController.php index 84976d97789..9df3223f800 100644 --- a/api/v1/submissions/SubmissionController.php +++ b/api/v1/submissions/SubmissionController.php @@ -21,7 +21,6 @@ use APP\components\forms\publication\PublicationLicenseForm; use APP\components\forms\submission\AudienceForm; use APP\components\forms\submission\PublicationDatesForm; -use APP\facades\Repo; use APP\file\PublicFileManager; use APP\publication\Publication; use APP\submission\Submission; @@ -33,6 +32,7 @@ use PKP\context\Context; use PKP\core\PKPApplication; use PKP\security\Role; +use PKP\userGroup\UserGroup; class SubmissionController extends PKPSubmissionController { @@ -150,7 +150,9 @@ protected function getPublicationLicenseForm(Request $illuminateRequest): JsonRe $publicationApiUrl = $data['publicationApiUrl']; /** @var String $publicationApiUrl */ $locales = $this->getPublicationFormLocales($context, $submission); - $authorUserGroups = Repo::userGroup()->getByRoleIds([Role::ROLE_ID_AUTHOR], $submission->getData('contextId')); + $authorUserGroups = UserGroup::withRoleIds([Role::ROLE_ID_AUTHOR]) + ->withContextIds([$submission->getData('contextId')]) + ->get(); $publicationLicenseForm = new PublicationLicenseForm($publicationApiUrl, $locales, $publication, $context, $authorUserGroups); $submissionLocale = $submission->getData('locale'); diff --git a/classes/components/forms/publication/PublicationLicenseForm.php b/classes/components/forms/publication/PublicationLicenseForm.php index 527511873ae..697ba1cf2f4 100644 --- a/classes/components/forms/publication/PublicationLicenseForm.php +++ b/classes/components/forms/publication/PublicationLicenseForm.php @@ -1,4 +1,5 @@ $userGroups User groups in this context + * @param Enumerable $userGroups User groups in this context */ public function __construct($action, $locales, $publication, $context, $userGroups) { diff --git a/classes/monograph/Chapter.php b/classes/monograph/Chapter.php index 19b902b4e58..f10fcc79fc9 100644 --- a/classes/monograph/Chapter.php +++ b/classes/monograph/Chapter.php @@ -286,7 +286,6 @@ public function setSourceChapterId(?int $sourceChapterId): void public function isPageEnabled(): ?bool { return $this->getData('isPageEnabled') || !empty($this->getDoi()); - ; } /** diff --git a/classes/search/MonographSearch.php b/classes/search/MonographSearch.php index b3c988e34f0..50e59b92635 100644 --- a/classes/search/MonographSearch.php +++ b/classes/search/MonographSearch.php @@ -26,6 +26,7 @@ use PKP\db\DAORegistry; use PKP\plugins\Hook; use PKP\search\SubmissionSearch; +use PKP\userGroup\UserGroup; class MonographSearch extends SubmissionSearch { @@ -75,7 +76,8 @@ public function getSparseArray($unorderedResults, $orderBy, $orderDir, $exclude) } $i = 0; // Used to prevent ties from clobbering each other - $authorUserGroups = Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->getMany(); + $authorUserGroups = UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->get(); foreach ($unorderedResults as $submissionId => $data) { // Exclude unwanted IDs. if (in_array($submissionId, $exclude)) { diff --git a/classes/submission/Submission.php b/classes/submission/Submission.php index 6a841e14ba5..30ae72200de 100644 --- a/classes/submission/Submission.php +++ b/classes/submission/Submission.php @@ -22,9 +22,9 @@ namespace APP\submission; -use APP\facades\Repo; use APP\publication\Publication; use PKP\submission\PKPSubmission; +use PKP\userGroup\UserGroup; class Submission extends PKPSubmission { @@ -67,7 +67,11 @@ public function _getContextLicenseFieldValue($locale, $field, $publication = nul if (!$publication) { $publication = $this->getCurrentPublication(); } - $authorUserGroups = Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$context->getId()])->getMany(); + + $authorUserGroups = UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds([$context->getId()]) + ->get(); + $fieldValue = [$context->getPrimaryLocale() => $publication->getAuthorString($authorUserGroups)]; break; case 'context': diff --git a/pages/catalog/CatalogBookHandler.php b/pages/catalog/CatalogBookHandler.php index 6fb7fac0f29..1dc7c0a48e8 100755 --- a/pages/catalog/CatalogBookHandler.php +++ b/pages/catalog/CatalogBookHandler.php @@ -44,6 +44,7 @@ use PKP\submission\GenreDAO; use PKP\submission\PKPSubmission; use PKP\submissionFile\SubmissionFile; +use PKP\userGroup\UserGroup; class CatalogBookHandler extends Handler { @@ -175,9 +176,7 @@ public function book($args, $request) return empty($a) || strtotime((string) $b->getData('datePublished')) < strtotime((string) $a->getData('datePublished')) ? $b : $a; }, 0); - $userGroups = Repo::userGroup()->getCollector() - ->filterByContextIds([$submission->getData('contextId')]) - ->getMany(); + $userGroups = UserGroup::withContextIds([$submission->getData('contextId')])->get(); $templateMgr->assign([ 'isChapterRequest' => $this->isChapterRequest, diff --git a/pages/catalog/CatalogHandler.php b/pages/catalog/CatalogHandler.php index 1c03503ed68..3672074eb24 100644 --- a/pages/catalog/CatalogHandler.php +++ b/pages/catalog/CatalogHandler.php @@ -30,6 +30,7 @@ use PKP\db\DAORegistry; use PKP\file\ContextFileManager; use PKP\pages\catalog\PKPCatalogHandler; +use PKP\userGroup\UserGroup; class CatalogHandler extends PKPCatalogHandler { @@ -104,7 +105,9 @@ public function page($args, $request, $isFirstPage = false) $templateMgr->assign([ 'publishedSubmissions' => $submissions->toArray(), - 'authorUserGroups' => $authorUserGroups = Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$context->getId()])->getMany()->remember(), + 'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds([$context->getId()]) + ->get(), 'featuredMonographIds' => $featuredMonographIds, 'contextSeries' => $seriesIterator->toArray(), ]); @@ -131,7 +134,9 @@ public function newReleases($args, $request) $newReleases = $newReleaseDao->getMonographsByAssoc(Application::ASSOC_TYPE_PRESS, $press->getId()); $templateMgr->assign([ 'publishedSubmissions' => $newReleases, - 'authorUserGroups' => $authorUserGroups = Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$press->getId()])->getMany()->remember(), + 'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds([$press->getId()]) + ->get(), ]); // Display @@ -199,7 +204,9 @@ public function series($args, $request) 'publishedSubmissions' => $submissions->toArray(), 'featuredMonographIds' => $featuredMonographIds, 'newReleasesMonographs' => $newReleases, - 'authorUserGroups' => $authorUserGroups = Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$context->getId()])->getMany()->remember(), + 'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds([$context->getId()]) + ->get(), ]); $templateMgr->display('frontend/pages/catalogSeries.tpl'); diff --git a/pages/index/IndexHandler.php b/pages/index/IndexHandler.php index 924fd1f41d1..f11ccd1e1b6 100644 --- a/pages/index/IndexHandler.php +++ b/pages/index/IndexHandler.php @@ -30,6 +30,7 @@ use PKP\pages\index\PKPIndexHandler; use PKP\security\Validation; use PKP\site\Site; +use PKP\userGroup\UserGroup; class IndexHandler extends PKPIndexHandler { @@ -129,7 +130,9 @@ public function _displayPressIndexPage($press, $request) 'homepageImage' => $press->getLocalizedSetting('homepageImage'), 'pageTitleTranslated' => $press->getLocalizedSetting('name'), 'displayCreativeCommons' => $press->getSetting('includeCreativeCommons'), - 'authorUserGroups' => Repo::userGroup()->getCollector()->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR])->filterByContextIds([$press->getId()])->getMany()->remember(), + 'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds([$press->getId()]) + ->get(), ]); $this->_setupAnnouncements($press, $templateMgr); diff --git a/pages/manageCatalog/ManageCatalogHandler.php b/pages/manageCatalog/ManageCatalogHandler.php index 46085149c61..09ac9dee812 100644 --- a/pages/manageCatalog/ManageCatalogHandler.php +++ b/pages/manageCatalog/ManageCatalogHandler.php @@ -27,6 +27,7 @@ use PKP\security\authorization\PKPSiteAccessPolicy; use PKP\security\Role; use PKP\submission\GenreDAO; +use PKP\userGroup\UserGroup; class ManageCatalogHandler extends Handler { @@ -124,9 +125,7 @@ public function index($args, $request) $total = $collector->getCount(); $submissions = $collector->limit($catalogList->count)->getMany(); - $userGroups = Repo::userGroup()->getCollector() - ->filterByContextIds([$context->getId()]) - ->getMany(); + $userGroups = UserGroup::withContextIds([$context->getId()])->get(); /** @var GenreDAO $genreDao */ $genreDao = DAORegistry::getDAO('GenreDAO'); diff --git a/pages/search/SearchHandler.php b/pages/search/SearchHandler.php index ecb6fada01c..404247775f9 100644 --- a/pages/search/SearchHandler.php +++ b/pages/search/SearchHandler.php @@ -17,10 +17,10 @@ namespace APP\pages\search; use APP\core\Request; -use APP\facades\Repo; use APP\handler\Handler; use APP\search\MonographSearch; use APP\template\TemplateManager; +use PKP\userGroup\UserGroup; class SearchHandler extends Handler { @@ -57,10 +57,9 @@ public function search($args, $request) $templateMgr->assign([ 'results' => $monographSearch->retrieveResults($request, $press, [null => $query], $error, null, null, $rangeInfo), 'searchQuery' => $query, - 'authorUserGroups' => Repo::userGroup()->getCollector() - ->filterByRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) - ->filterByContextIds($press ? [$press->getId()] : null) - ->getMany()->remember(), + 'authorUserGroups' => UserGroup::withRoleIds([\PKP\security\Role::ROLE_ID_AUTHOR]) + ->withContextIds($press ? [$press->getId()] : null) + ->get(), ]); // Display diff --git a/plugins/importexport/csv/CSVImportExportPlugin.php b/plugins/importexport/csv/CSVImportExportPlugin.php index bfded81317e..2e2468db016 100644 --- a/plugins/importexport/csv/CSVImportExportPlugin.php +++ b/plugins/importexport/csv/CSVImportExportPlugin.php @@ -28,6 +28,7 @@ use PKP\submission\GenreDAO; use PKP\submission\PKPSubmission; use PKP\submissionFile\SubmissionFile; +use PKP\userGroup\UserGroup; class CSVImportExportPlugin extends ImportExportPlugin { @@ -162,11 +163,11 @@ public function executeCLI($scriptName, &$args) continue; } - $authorGroup = Repo::userGroup()->getCollector() - ->filterByContextIds([$press->getId()]) - ->filterByRoleIds([Role::ROLE_ID_AUTHOR]) - ->filterByIsDefault(true) - ->getMany() + $authorGroup = UserGroup::withContextIds([$press->getId()]) + ->withContextIds([$press->getId()]) + ->withRoleIds([Role::ROLE_ID_AUTHOR]) + ->isDefault(true) + ->get() ->first(); if (!$authorGroup) { echo __('plugins.importexport.csv.noAuthorGroup', ['press' => $pressPath]) . "\n"; @@ -217,7 +218,7 @@ public function executeCLI($scriptName, &$args) $author = Repo::author()->newDataObject(); $author->setData('publicationId', $publicationId); $author->setSubmissionId($submissionId); - $author->setUserGroupId($authorGroup->getId()); + $author->setUserGroupId($authorGroup->id); $author->setGivenName($givenName, $locale); $author->setFamilyName($familyName, $locale); $author->setEmail($emailAddress); diff --git a/plugins/reports/monographReport/Report.php b/plugins/reports/monographReport/Report.php index 070472cdc5e..b834821acfe 100644 --- a/plugins/reports/monographReport/Report.php +++ b/plugins/reports/monographReport/Report.php @@ -294,9 +294,11 @@ private function getDecision(int $editorIndex, int $decisionIndex): ?Decision */ private function getEditorUserGroups(): Collection { - return $this->editorUserGroups ??= collect(Repo::userGroup()->getCollector()->filterByContextIds([$this->press->getId()])->getMany()) - ->filter(fn (UserGroup $userGroup) => in_array($userGroup->getRoleId(), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])) - ->mapWithKeys(fn (UserGroup $userGroup) => [$userGroup->getId() => true]); + $userGroups = UserGroup::withContextIds([$this->press->getId()])->get(); + + return $this->editorUserGroups ??= $userGroups + ->filter(fn (UserGroup $userGroup) => in_array($userGroup->roleId, [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])) + ->mapWithKeys(fn (UserGroup $userGroup) => [$userGroup->id => true]); } /** diff --git a/templates/controllers/grid/settings/series/form/seriesForm.tpl b/templates/controllers/grid/settings/series/form/seriesForm.tpl index 6d71ef5a899..e2616092f71 100644 --- a/templates/controllers/grid/settings/series/form/seriesForm.tpl +++ b/templates/controllers/grid/settings/series/form/seriesForm.tpl @@ -83,8 +83,8 @@ {fbvFormSection list=true title="manager.sections.form.assignEditors"}
{translate key="manager.sections.form.assignEditors.description"}
{foreach from=$assignableUserGroups item="assignableUserGroup"} - {assign var="role" value=$assignableUserGroup.userGroup->getLocalizedName()} - {assign var="userGroupId" value=$assignableUserGroup.userGroup->getId()} + {assign var="role" value=$assignableUserGroup.userGroup->getLocalizedData('name')} + {assign var="userGroupId" value=$assignableUserGroup.userGroup->id} {foreach from=$assignableUserGroup.users item=$username key="id"} {fbvElement type="checkbox" diff --git a/templates/controllers/grid/settings/user/userGroupsList.tpl b/templates/controllers/grid/settings/user/userGroupsList.tpl index e59c852be7c..cecd271bd63 100644 --- a/templates/controllers/grid/settings/user/userGroupsList.tpl +++ b/templates/controllers/grid/settings/user/userGroupsList.tpl @@ -13,7 +13,7 @@ From eb13ac67e0a13e7abcccce28f7c6b2c262388473 Mon Sep 17 00:00:00 2001 From: Vitalii Bezsheiko Date: Mon, 16 Dec 2024 10:53:25 +0200 Subject: [PATCH 2/2] Submodule update ##Vitaliy-1/i10506_usergroup_eloquent## --- lib/pkp | 2 +- plugins/generic/citationStyleLanguage | 2 +- plugins/generic/webFeed | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pkp b/lib/pkp index 5c6eaa0ea27..d05f1af72f3 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit 5c6eaa0ea2764450c139062c8f3709466cee1a19 +Subproject commit d05f1af72f322c6b3ff241f8185292ca71990f35 diff --git a/plugins/generic/citationStyleLanguage b/plugins/generic/citationStyleLanguage index e2d5a1f17d8..904daa2197c 160000 --- a/plugins/generic/citationStyleLanguage +++ b/plugins/generic/citationStyleLanguage @@ -1 +1 @@ -Subproject commit e2d5a1f17d8b854de35ca96d747c17bc3ca69a61 +Subproject commit 904daa2197c709b28b754a26b9828c2ba0629719 diff --git a/plugins/generic/webFeed b/plugins/generic/webFeed index 7e99fa5c1dc..ebed779fff0 160000 --- a/plugins/generic/webFeed +++ b/plugins/generic/webFeed @@ -1 +1 @@ -Subproject commit 7e99fa5c1dc42c1b1e6f3588e5c894cdb9d92dff +Subproject commit ebed779fff0bc97dca563ed70c761c32445fcf81