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()
{
if (SuppressHierarchyChanges)
{ {
Watcher.WatchFolder(new SharedFolderRegistration(this), Watcher.WatchFolder(new SharedFolderRegistration(this),
OnSharedFolderDiscovered, OnSharedFolderDiscovered,
OnSharedFolderChanged, OnSharedFolderChanged,
OnSharedFolderRemoved); 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,7 +367,10 @@ 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)
{
// Suppress any move of or into a shared folder
Logger.Instance.Warning(this, "Shared folder move: {0} - {1}", src.Name, moveTo.Name);
MessageBox.Show(ThisAddIn.Instance.Window, MessageBox.Show(ThisAddIn.Instance.Window,
Properties.Resources.SharedFolders_LocalFolder_Body, Properties.Resources.SharedFolders_LocalFolder_Body,
@ -359,6 +380,7 @@ namespace Acacia.Features.SharedFolders
); );
cancel = true; 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;