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()
{
Watcher.WatchFolder(new SharedFolderRegistration(this),
OnSharedFolderDiscovered,
OnSharedFolderChanged,
OnSharedFolderRemoved);
if (SuppressHierarchyChanges)
{
Watcher.WatchFolder(new SharedFolderRegistration(this),
OnSharedFolderDiscovered,
OnSharedFolderChanged,
OnSharedFolderRemoved);
// Register for any folder move
Watcher.WatchFolder(new FolderRegistrationAny(this),
(folder) =>
{
folder.BeforeFolderMove += Folder_BeforeFolderMove;
});
}
}
private void OnSharedFolderDiscovered(IFolder folder)
@ -340,8 +360,6 @@ namespace Acacia.Features.SharedFolders
}
else
{
folder.BeforeFolderMove += Folder_BeforeFolderMove;
// Check if it was renamed before the events were fully set up
CheckSharedFolderRename(folder);
}
@ -349,15 +367,19 @@ namespace Acacia.Features.SharedFolders
private void Folder_BeforeFolderMove(IFolder src, IFolder moveTo, ref bool cancel)
{
Logger.Instance.Fatal(this, "SHARED FOLDER MOVE: {0}", moveTo.Name);
MessageBox.Show(ThisAddIn.Instance.Window,
Properties.Resources.SharedFolders_LocalFolder_Body,
Properties.Resources.SharedFolders_LocalFolder_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
cancel = true;
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,
Properties.Resources.SharedFolders_LocalFolder_Body,
Properties.Resources.SharedFolders_LocalFolder_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
cancel = true;
}
}
private void OnSharedFolderChanged(IFolder folder)

View File

@ -36,6 +36,25 @@ namespace Acacia.ZPush
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
{
private readonly ItemType _itemType;