1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 13:37:40 +02:00

[KOE-142] Now suppressing moving of any shared folder or into a shared folder. This prevents deletion of folders moved into shared folders. Also added the SuppressHierarchyChanges property to enable/disable it.

This commit is contained in:
Patrick Simpson 2017-09-20 14:56:54 +03:00
parent eb8df70e67
commit f1937cd3d6
2 changed files with 56 additions and 15 deletions

View File

@ -314,12 +314,32 @@ namespace Acacia.Features.SharedFolders
} }
} }
[AcaciaOption("If enabled, modifications to the local hierarchy of shared folders is suppressed. " +
"This should only be disabled for debug purposes.")]
public bool SuppressHierarchyChanges
{
get { return GetOption(OPTION_SUPPRESS_HIERARCHY_CHANGES); }
set { SetOption(OPTION_SUPPRESS_HIERARCHY_CHANGES, value); }
}
private static readonly BoolOption OPTION_SUPPRESS_HIERARCHY_CHANGES =
new BoolOption("SuppressHierarchyChanges", true);
private void SetupHierarchyChangeSuppression() private void SetupHierarchyChangeSuppression()
{ {
Watcher.WatchFolder(new SharedFolderRegistration(this), if (SuppressHierarchyChanges)
OnSharedFolderDiscovered, {
OnSharedFolderChanged, Watcher.WatchFolder(new SharedFolderRegistration(this),
OnSharedFolderRemoved); OnSharedFolderDiscovered,
OnSharedFolderChanged,
OnSharedFolderRemoved);
// Register for any folder move
Watcher.WatchFolder(new FolderRegistrationAny(this),
(folder) =>
{
folder.BeforeFolderMove += Folder_BeforeFolderMove;
});
}
} }
private void OnSharedFolderDiscovered(IFolder folder) private void OnSharedFolderDiscovered(IFolder folder)
@ -340,8 +360,6 @@ namespace Acacia.Features.SharedFolders
} }
else else
{ {
folder.BeforeFolderMove += Folder_BeforeFolderMove;
// Check if it was renamed before the events were fully set up // Check if it was renamed before the events were fully set up
CheckSharedFolderRename(folder); CheckSharedFolderRename(folder);
} }
@ -349,15 +367,19 @@ namespace Acacia.Features.SharedFolders
private void Folder_BeforeFolderMove(IFolder src, IFolder moveTo, ref bool cancel) private void Folder_BeforeFolderMove(IFolder src, IFolder moveTo, ref bool cancel)
{ {
Logger.Instance.Fatal(this, "SHARED FOLDER MOVE: {0}", moveTo.Name); if (src.SyncId?.IsShared == true || moveTo.SyncId?.IsShared == true)
{
MessageBox.Show(ThisAddIn.Instance.Window, // Suppress any move of or into a shared folder
Properties.Resources.SharedFolders_LocalFolder_Body, Logger.Instance.Warning(this, "Shared folder move: {0} - {1}", src.Name, moveTo.Name);
Properties.Resources.SharedFolders_LocalFolder_Title,
MessageBoxButtons.OK, MessageBox.Show(ThisAddIn.Instance.Window,
MessageBoxIcon.Warning Properties.Resources.SharedFolders_LocalFolder_Body,
); Properties.Resources.SharedFolders_LocalFolder_Title,
cancel = true; MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
cancel = true;
}
} }
private void OnSharedFolderChanged(IFolder folder) private void OnSharedFolderChanged(IFolder folder)

View File

@ -36,6 +36,25 @@ namespace Acacia.ZPush
abstract public bool IsApplicable(IFolder folder); abstract public bool IsApplicable(IFolder folder);
} }
public class FolderRegistrationAny : FolderRegistration
{
public FolderRegistrationAny(Feature feature)
:
base(feature)
{
}
public override bool IsApplicable(IFolder folder)
{
return folder != null;
}
public override string ToString()
{
return Feature.Name;
}
}
public class FolderRegistrationTyped : FolderRegistration public class FolderRegistrationTyped : FolderRegistration
{ {
private readonly ItemType _itemType; private readonly ItemType _itemType;