From 8f5ffca79bf62a5c15815d00dd8f332787e808e7 Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Thu, 25 Apr 2024 12:22:18 -0400 Subject: [PATCH 1/3] Adds numeric suffix to username if already in use Issue: documentacao-e-tarefas/desenvolvimento_e_infra#813 Signed-off-by: Thiago Matos --- filter/filterConfig.xml | 11 ++++++ filter/import/NativeXmlUserFilter.inc.php | 42 ++++++++++++++++++++++ tests/import/NativeXmlUserFilterTest.php | 43 +++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 filter/import/NativeXmlUserFilter.inc.php create mode 100644 tests/import/NativeXmlUserFilterTest.php diff --git a/filter/filterConfig.xml b/filter/filterConfig.xml index 98c2a12..94d0770 100644 --- a/filter/filterConfig.xml +++ b/filter/filterConfig.xml @@ -26,6 +26,13 @@ description="plugins.importexport.fullJournalTransfer.description" inputType="xml::schema(plugins/importexport/fullJournalTransfer/fullJournal.xsd)" outputType="class::classes.journal.Journal" /> + + + setDisplayName('Native XML user import'); + parent::__construct($filterGroup); + } + + public function getClassName() + { + return 'plugins.importexport.fullJournalTransfer.filter.import.NativeXmlUserFilter'; + } + + public function generateUsername($user) + { + $userDAO = DAORegistry::getDAO('UserDAO'); + $baseUsername = preg_replace('/[^A-Z0-9]/i', '', $user->getUsername()); + for ($username = $baseUsername, $i = 1; $userDAO->userExistsByUsername($username); $i++) { + $username = $baseUsername . $i; + } + + $user->setUsername($username); + } +} diff --git a/tests/import/NativeXmlUserFilterTest.php b/tests/import/NativeXmlUserFilterTest.php new file mode 100644 index 0000000..5a180d0 --- /dev/null +++ b/tests/import/NativeXmlUserFilterTest.php @@ -0,0 +1,43 @@ +user'; + } + + protected function getNativeImportExportFilterClass() + { + return NativeXmlUserFilter::class; + } + + protected function getMockedDAOs() + { + return ['UserDAO']; + } + + public function testGenerateUsername() + { + $userImportFilter = $this->getNativeImportExportFilter(); + + $mockUserDAO = $this->getMockBuilder(UserDAO::class) + ->setMethods(['userExistsByUsername']) + ->getMock(); + $mockUserDAO->expects($this->any()) + ->method('userExistsByUsername') + ->will($this->onConsecutiveCalls(true, false)); + + DAORegistry::registerDAO('UserDAO', $mockUserDAO); + + $user = new User(); + $user->setUsername('reviewer'); + + $userImportFilter->generateUsername($user); + + $this->assertEquals('reviewer1', $user->getUsername()); + } +} From b9491b014729798327ebf79b2942fa9201b67b4f Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Thu, 25 Apr 2024 14:35:22 -0400 Subject: [PATCH 2/3] Uses custom user import filter Issue: documentacao-e-tarefas/desenvolvimento_e_infra#813 Signed-off-by: Thiago Matos --- filter/import/NativeXmlJournalFilter.inc.php | 2 +- filter/import/NativeXmlUserFilter.inc.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/filter/import/NativeXmlJournalFilter.inc.php b/filter/import/NativeXmlJournalFilter.inc.php index 22619e0..59ad811 100644 --- a/filter/import/NativeXmlJournalFilter.inc.php +++ b/filter/import/NativeXmlJournalFilter.inc.php @@ -221,7 +221,7 @@ public function parseNavigationMenu($node) public function parseUsers($node, $journal) { $filterDao = DAORegistry::getDAO('FilterDAO'); - $userFilters = $filterDao->getObjectsByGroup('user-xml=>user'); + $userFilters = $filterDao->getObjectsByGroup('native-xml=>user'); assert(count($userFilters) == 1); $filter = array_shift($userFilters); $filter->setDeployment(new PKPUserImportExportDeployment($journal, null)); diff --git a/filter/import/NativeXmlUserFilter.inc.php b/filter/import/NativeXmlUserFilter.inc.php index 91acb7e..f706d6d 100644 --- a/filter/import/NativeXmlUserFilter.inc.php +++ b/filter/import/NativeXmlUserFilter.inc.php @@ -29,6 +29,15 @@ public function getClassName() return 'plugins.importexport.fullJournalTransfer.filter.import.NativeXmlUserFilter'; } + public function importUserPasswordValidation($userToImport, $encryption) + { + $password = parent::importUserPasswordValidation($userToImport, $encryption); + + $this->generateUsername($userToImport); + + return $password; + } + public function generateUsername($user) { $userDAO = DAORegistry::getDAO('UserDAO'); From 664e5078f59ca255491d099b04b29cd9e7bfcf0b Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Thu, 25 Apr 2024 14:37:05 -0400 Subject: [PATCH 3/3] Update version.xml Issue: documentacao-e-tarefas/desenvolvimento_e_infra#813 Signed-off-by: Thiago Matos --- version.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.xml b/version.xml index dcee599..71bdee9 100644 --- a/version.xml +++ b/version.xml @@ -10,7 +10,7 @@ fullJournalTransfer plugins.importexport - 2.0.10.1 - 2024-04-24 + 2.0.10.2 + 2024-04-25 FullJournalImportExportPlugin