mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
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
This commit is contained in:
@@ -1227,7 +1227,7 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea
|
||||
}
|
||||
|
||||
List<AlfrescoImapFolder> fullList = new LinkedList<AlfrescoImapFolder>();
|
||||
ImapSubFolderFilter filter = new ImapSubFolderFilter(viewMode, name.replace('%', '*'));
|
||||
ImapSubFolderFilter filter = new ImapSubFolderFilter(viewMode, name.replace('%', '*'), Arrays.asList("calendar", "dataLists"));
|
||||
List<FileInfo> 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<NodeRef> favs;
|
||||
private String mailboxPattern;
|
||||
private ImapViewMode imapViewMode;
|
||||
/**
|
||||
* Exclude folders which represent components with these IDs
|
||||
*/
|
||||
private List<String> excludedComponentIds;
|
||||
|
||||
ImapSubFolderFilter(ImapViewMode imapViewMode)
|
||||
{
|
||||
@@ -1666,12 +1670,23 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea
|
||||
this.mailboxPattern = mailboxPattern.replaceAll("\\*", "(.)*");;
|
||||
}
|
||||
|
||||
ImapSubFolderFilter(ImapViewMode imapViewMode, String mailboxPattern, List<String> excludedComponentIds)
|
||||
{
|
||||
this(imapViewMode, mailboxPattern);
|
||||
this.excludedComponentIds = excludedComponentIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnterSubfolder(ChildAssociationRef subfolderRef)
|
||||
{
|
||||
return isEnterSubfolder(subfolderRef.getChildRef());
|
||||
}
|
||||
|
||||
private boolean containsIgnoreCase(String s, List<String> list)
|
||||
{
|
||||
return list.stream().anyMatch((e) -> e.equalsIgnoreCase(s));
|
||||
}
|
||||
|
||||
public boolean isEnterSubfolder(NodeRef folder)
|
||||
{
|
||||
String name = (String) nodeService.getProperty(folder, ContentModel.PROP_NAME);
|
||||
@@ -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))
|
||||
{
|
||||
|
@@ -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;
|
||||
@@ -352,6 +353,25 @@ public class ImapServiceImplTest extends TestCase
|
||||
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<AlfrescoImapFolder> 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
|
||||
{
|
||||
imapService.getOrCreateMailbox(user, MAILBOX_NAME_A, false, true);
|
||||
|
Reference in New Issue
Block a user