From c6cd3a45523db1828fe71e13d670991d36347dc3 Mon Sep 17 00:00:00 2001 From: eknizat <26163420+eknizat@users.noreply.github.com> Date: Mon, 15 Apr 2019 09:40:26 +0100 Subject: [PATCH] REPO-830: 6.0 Cleanup: Remove link between IMAP, Calendar and Data Lists (#396) * Added functionality to filter IMAP folders based on their component IDS --- .../alfresco/repo/imap/ImapServiceImpl.java | 36 +++++- .../repo/imap/ImapServiceImplTest.java | 120 ++++++++++-------- 2 files changed, 105 insertions(+), 51 deletions(-) diff --git a/src/main/java/org/alfresco/repo/imap/ImapServiceImpl.java b/src/main/java/org/alfresco/repo/imap/ImapServiceImpl.java index 3985148785..77b88d9e72 100644 --- a/src/main/java/org/alfresco/repo/imap/ImapServiceImpl.java +++ b/src/main/java/org/alfresco/repo/imap/ImapServiceImpl.java @@ -1227,7 +1227,7 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea } List fullList = new LinkedList(); - ImapSubFolderFilter filter = new ImapSubFolderFilter(viewMode, name.replace('%', '*')); + ImapSubFolderFilter filter = new ImapSubFolderFilter(viewMode, name.replace('%', '*'), Arrays.asList("calendar", "dataLists")); List list; // Only list this folder if we have a wildcard name. Otherwise do a direct lookup by name. if (name.contains("*") || name.contains("%")) @@ -1652,6 +1652,10 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea private List favs; private String mailboxPattern; private ImapViewMode imapViewMode; + /** + * Exclude folders which represent components with these IDs + */ + private List excludedComponentIds; ImapSubFolderFilter(ImapViewMode imapViewMode) { @@ -1665,12 +1669,23 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea this(imapViewMode); this.mailboxPattern = mailboxPattern.replaceAll("\\*", "(.)*");; } + + ImapSubFolderFilter(ImapViewMode imapViewMode, String mailboxPattern, List excludedComponentIds) + { + this(imapViewMode, mailboxPattern); + this.excludedComponentIds = excludedComponentIds; + } @Override public boolean isEnterSubfolder(ChildAssociationRef subfolderRef) { return isEnterSubfolder(subfolderRef.getChildRef()); } + + private boolean containsIgnoreCase(String s, List list) + { + return list.stream().anyMatch((e) -> e.equalsIgnoreCase(s)); + } public boolean isEnterSubfolder(NodeRef folder) { @@ -1685,6 +1700,25 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea if (!name.matches(mailboxPattern)) return false; } + + /** + * Exclude folders which represent unsupported components, like calendar and dataLists. + * See REPO-830 + */ + if (excludedComponentIds != null && !excludedComponentIds.isEmpty()) + { + String componentId = (String) nodeService.getProperty(folder, SiteModel.PROP_COMPONENT_ID); + if (componentId != null && containsIgnoreCase(componentId, excludedComponentIds)) + { + if (logger.isDebugEnabled()) + { + logger.debug("[ImapSubFolderFilter] Excluding folder with name: " + name + + " because its componentID is: " + componentId); + } + return false; + } + } + QName typeOfFolder = nodeService.getType(folder); if (typesToExclude.contains(typeOfFolder)) { diff --git a/src/test/java/org/alfresco/repo/imap/ImapServiceImplTest.java b/src/test/java/org/alfresco/repo/imap/ImapServiceImplTest.java index 341e78837d..919ffa1674 100644 --- a/src/test/java/org/alfresco/repo/imap/ImapServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/imap/ImapServiceImplTest.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.imap; import java.io.FileInputStream; @@ -67,6 +67,7 @@ import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory; import org.alfresco.repo.node.integrity.IntegrityChecker; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.model.FileFolderService; @@ -136,7 +137,7 @@ public class ImapServiceImplTest extends TestCase private ContentService contentService; private NodeRef testImapFolderNodeRef; - private Flags flags; + private Flags flags; private ImapServiceImpl imapServiceImpl; String anotherUserName; @@ -144,7 +145,7 @@ public class ImapServiceImplTest extends TestCase @Override public void setUp() throws Exception - { + { ctx = ApplicationContextHelper.getApplicationContext(); ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry"); transactionService = serviceRegistry.getTransactionService(); @@ -171,22 +172,22 @@ public class ImapServiceImplTest extends TestCase authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray()); // downgrade integrity - IntegrityChecker.setWarnInTransaction(); - - anotherUserName = "user" + System.currentTimeMillis(); - - PropertyMap testUser = new PropertyMap(); - testUser.put(ContentModel.PROP_USERNAME, anotherUserName); - testUser.put(ContentModel.PROP_FIRSTNAME, anotherUserName); - testUser.put(ContentModel.PROP_LASTNAME, anotherUserName); - testUser.put(ContentModel.PROP_EMAIL, anotherUserName + "@alfresco.com"); - testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle"); - - personService.createPerson(testUser); - - // create the ACEGI Authentication instance for the new user - authenticationService.createAuthentication(anotherUserName, anotherUserName.toCharArray()); - + IntegrityChecker.setWarnInTransaction(); + + anotherUserName = "user" + System.currentTimeMillis(); + + PropertyMap testUser = new PropertyMap(); + testUser.put(ContentModel.PROP_USERNAME, anotherUserName); + testUser.put(ContentModel.PROP_FIRSTNAME, anotherUserName); + testUser.put(ContentModel.PROP_LASTNAME, anotherUserName); + testUser.put(ContentModel.PROP_EMAIL, anotherUserName + "@alfresco.com"); + testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle"); + + personService.createPerson(testUser); + + // create the ACEGI Authentication instance for the new user + authenticationService.createAuthentication(anotherUserName, anotherUserName.toCharArray()); + user = new AlfrescoImapUser(anotherUserName + "@alfresco.com", anotherUserName, anotherUserName); NodeRef companyHomeNodeRef = findCompanyHomeNodeRef(); @@ -351,6 +352,25 @@ public class ImapServiceImplTest extends TestCase List aif2 = imapService.listMailboxes(user, MAILBOX_PATTERN, true); assertEquals("not subscribed to one mailbox", 1, aif2.size()); } + + public void testExcludeFoldersByComponentIt() + { + NodeRef imapFolderA = imapService.getOrCreateMailbox(user, MAILBOX_NAME_A, false, true).getFolderInfo().getNodeRef(); + NodeRef imapFolderB = imapService.getOrCreateMailbox(user, MAILBOX_NAME_B, false, true).getFolderInfo().getNodeRef(); + NodeRef imapFolderC = imapService.getOrCreateMailbox(user, "mailboxCalendarFolder", false, true).getFolderInfo().getNodeRef(); + NodeRef imapFolderD = imapService.getOrCreateMailbox(user, "mailboxDataListsFolder", false, true).getFolderInfo().getNodeRef(); + NodeRef imapFolderE = imapService.getOrCreateMailbox(user, "mailboxDocumentLibraryFolder", false, true).getFolderInfo().getNodeRef(); + + List mf = imapService.listMailboxes(user, MAILBOX_PATTERN, false); + assertEquals(5, mf.size()); + + nodeService.setProperty(imapFolderC, SiteModel.PROP_COMPONENT_ID, "calendar"); + nodeService.setProperty(imapFolderD, SiteModel.PROP_COMPONENT_ID, "dataLists"); + nodeService.setProperty(imapFolderE, SiteModel.PROP_COMPONENT_ID, "documentLibrary"); + + mf = imapService.listMailboxes(user, MAILBOX_PATTERN, false); + assertEquals("Imap folders with component IDs 'calendar' or 'dataLists' were not excluded.", 3, mf.size()); + } public void testListSubscribedMailbox() throws Exception { @@ -1005,13 +1025,13 @@ public class ImapServiceImplTest extends TestCase assertEquals("The parent should change to destination.", destinationNode.getNodeRef(), copiedParentNodeRef); assertEquals("There should be only one node in the destination folder", 1, nodeService.getChildAssocs(destinationNode.getNodeRef()).size()); assertTrue("New node should have original node aspects", nodeService.hasAspect(copiedNode.getNodeRef(), ContentModel.ASPECT_TAGGABLE)); - } - - public void testListMailboxOnStartup() - { - authenticationService.clearCurrentSecurityContext(); - // Starting IMAP - imapServiceImpl.startupInTxn(true); + } + + public void testListMailboxOnStartup() + { + authenticationService.clearCurrentSecurityContext(); + // Starting IMAP + imapServiceImpl.startupInTxn(true); } /**