Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Windows
pEp for Outlook
Commits
0cdb38d0
Commit
0cdb38d0
authored
Sep 16, 2021
by
Thomas
Browse files
Add dialog to add patches
parent
d3d2dd8c
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
DPE/DistributedPolicyEngine.cs
View file @
0cdb38d0
...
@@ -11,6 +11,7 @@ namespace pEp.DPE
...
@@ -11,6 +11,7 @@ namespace pEp.DPE
internal
class
DistributedPolicyEngine
:
IDistributedPolicyEngine
internal
class
DistributedPolicyEngine
:
IDistributedPolicyEngine
{
{
private
readonly
static
string
DPE_FOLDER
=
Path
.
Combine
(
Globals
.
PEPUserFolder
,
"DPE"
);
private
readonly
static
string
DPE_FOLDER
=
Path
.
Combine
(
Globals
.
PEPUserFolder
,
"DPE"
);
public
readonly
static
string
DPE_BACKUP_LOCATION
=
Path
.
Combine
(
DistributedPolicyEngine
.
DPE_FOLDER
,
"temp"
);
private
const
string
PATCH_EXTENSION
=
".patch"
;
private
const
string
PATCH_EXTENSION
=
".patch"
;
private
const
string
PATCH_MESSAGE_SUBJECT
=
"Configuration changes"
;
private
const
string
PATCH_MESSAGE_SUBJECT
=
"Configuration changes"
;
public
const
string
DPE_MESSAGE_CLASS
=
"IPM.Note.DPE"
;
public
const
string
DPE_MESSAGE_CLASS
=
"IPM.Note.DPE"
;
...
@@ -201,27 +202,6 @@ namespace pEp.DPE
...
@@ -201,27 +202,6 @@ namespace pEp.DPE
return
false
;
return
false
;
}
}
/// <summary>
/// Saves the patch to disk.
/// </summary>
/// <param name="patch">The patch to save.</param>
/// <returns>True if the patch was saved successfully, otherwise false.</returns>
private
bool
SavePatch
(
Patch
patch
)
{
try
{
string
fileName
=
Path
.
Combine
(
DistributedPolicyEngine
.
DPE_FOLDER
,
patch
.
Id
+
DistributedPolicyEngine
.
PATCH_EXTENSION
);
string
xml
=
patch
.
Serialize
();
File
.
WriteAllText
(
fileName
,
xml
);
return
File
.
Exists
(
fileName
);
}
catch
(
Exception
ex
)
{
Log
.
Error
(
"SavePatch: Error saving patch. "
+
ex
.
ToString
());
}
return
false
;
}
#
endregion
#
endregion
#
region
Static
methods
#
region
Static
methods
...
...
UI/FormRegionDPE.cs
View file @
0cdb38d0
...
@@ -36,7 +36,7 @@ namespace pEp
...
@@ -36,7 +36,7 @@ namespace pEp
string
xml
=
omi
.
HTMLBody
;
string
xml
=
omi
.
HTMLBody
;
Patch
patch
=
Patch
.
Deserialize
(
xml
);
Patch
patch
=
Patch
.
Deserialize
(
xml
);
PEPIdentity
.
GetFromIdentity
(
omi
,
out
PEPIdentity
submitter
);
PEPIdentity
.
GetFromIdentity
(
omi
,
out
PEPIdentity
submitter
);
this
.
FormControlPatchView
.
DataContext
=
new
FormControlPatchViewModel
(
patch
,
submitter
,
PatchDialog
.
PatchAction
.
SupportOrRejectPatch
);
this
.
FormControlPatchView
.
DataContext
=
new
FormControlPatchViewModel
(
patch
,
submitter
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
...
UI/Models/OptionsDialog.cs
View file @
0cdb38d0
...
@@ -62,11 +62,11 @@ namespace pEp.UI.Models
...
@@ -62,11 +62,11 @@ namespace pEp.UI.Models
{
{
// Get group manager
// Get group manager
pEpIdentity
groupManager
=
(
pEpIdentity
)
AdapterExtensions
.
ExecuteWithPassphraseCheck
(()
=>
ThisAddIn
.
PEPEngine
.
GroupQueryManager
(
groupIdentity
));
pEpIdentity
groupManager
=
(
pEpIdentity
)
AdapterExtensions
.
ExecuteWithPassphraseCheck
(()
=>
ThisAddIn
.
PEPEngine
.
GroupQueryManager
(
groupIdentity
));
Log
.
Verbose
(
"GetManagedGroup
e
: Retrieved group manager "
+
groupManager
.
Address
);
Log
.
Verbose
(
"GetManagedGroup
s
: Retrieved group manager "
+
groupManager
.
Address
);
// Get group members
// Get group members
pEpIdentity
[]
members
=
(
pEpIdentity
[])
AdapterExtensions
.
ExecuteWithPassphraseCheck
(()
=>
ThisAddIn
.
PEPEngine
.
GroupQueryMembers
(
groupIdentity
));
pEpIdentity
[]
members
=
(
pEpIdentity
[])
AdapterExtensions
.
ExecuteWithPassphraseCheck
(()
=>
ThisAddIn
.
PEPEngine
.
GroupQueryMembers
(
groupIdentity
));
Log
.
Verbose
(
"GetManagedGroup
e
: Retrieved group {0} group members"
,
members
.
Length
);
Log
.
Verbose
(
"GetManagedGroup
s
: Retrieved group {0} group members"
,
members
.
Length
);
// Add group
// Add group
messageGroups
.
Add
(
new
MessageGroup
(
groupIdentity
,
groupManager
,
members
));
messageGroups
.
Add
(
new
MessageGroup
(
groupIdentity
,
groupManager
,
members
));
...
...
UI/ViewModels/FormControlPatchViewModel.cs
View file @
0cdb38d0
using
pEp.DPE
;
using
pEp.DPE
;
using
pEp.UI.Models
;
using
System.Windows.Documents
;
using
System.Windows.Documents
;
using
System.Windows.Media
;
using
System.Windows.Media
;
...
@@ -16,7 +15,6 @@ namespace pEp.UI.ViewModels
...
@@ -16,7 +15,6 @@ namespace pEp.UI.ViewModels
private
bool
_IsDiffValid
=
false
;
private
bool
_IsDiffValid
=
false
;
private
bool
_IsUriValid
=
false
;
private
bool
_IsUriValid
=
false
;
private
bool
_IsValid
=
false
;
private
bool
_IsValid
=
false
;
private
RelayCommand
_LoadFromFileCommand
=
null
;
#
endregion
#
endregion
...
@@ -31,7 +29,6 @@ namespace pEp.UI.ViewModels
...
@@ -31,7 +29,6 @@ namespace pEp.UI.ViewModels
set
set
{
{
this
.
patch
.
CommitMessage
=
value
;
this
.
patch
.
CommitMessage
=
value
;
this
.
ValidatePatch
();
this
.
OnPropertyChanged
();
this
.
OnPropertyChanged
();
}
}
}
}
...
@@ -50,7 +47,6 @@ namespace pEp.UI.ViewModels
...
@@ -50,7 +47,6 @@ namespace pEp.UI.ViewModels
set
set
{
{
this
.
patch
.
Diff
=
value
;
this
.
patch
.
Diff
=
value
;
this
.
ValidatePatch
();
this
.
OnPropertyChanged
();
this
.
OnPropertyChanged
();
}
}
}
}
...
@@ -149,22 +145,6 @@ namespace pEp.UI.ViewModels
...
@@ -149,22 +145,6 @@ namespace pEp.UI.ViewModels
}
}
}
}
/// <summary>
/// Gets the command to load the diff from file.
/// </summary>
public
RelayCommand
LoadFromFileCommand
{
get
{
if
(
this
.
_LoadFromFileCommand
==
null
)
{
this
.
_LoadFromFileCommand
=
new
RelayCommand
(
LoadFromFile
);
}
return
this
.
_LoadFromFileCommand
;
}
}
/// <summary>
/// <summary>
/// The command to accept the patch dialog.
/// The command to accept the patch dialog.
/// </summary>
/// </summary>
...
@@ -212,7 +192,6 @@ namespace pEp.UI.ViewModels
...
@@ -212,7 +192,6 @@ namespace pEp.UI.ViewModels
set
set
{
{
this
.
patch
.
Uri
=
value
;
this
.
patch
.
Uri
=
value
;
this
.
ValidatePatch
();
this
.
OnPropertyChanged
();
this
.
OnPropertyChanged
();
}
}
}
}
...
@@ -226,42 +205,16 @@ namespace pEp.UI.ViewModels
...
@@ -226,42 +205,16 @@ namespace pEp.UI.ViewModels
/// </summary>
/// </summary>
/// <param name="patch">The patch to create the form region with.</param>
/// <param name="patch">The patch to create the form region with.</param>
/// <param name="submitter">The submitter of the patch.</param>
/// <param name="submitter">The submitter of the patch.</param>
/// <param name="patchAction">The action to perform with the patch.</param>
/// <param name="isEditable">Whether this patch is editable.</param>
/// <param name="isEditable">Whether this patch is editable.</param>
public
FormControlPatchViewModel
(
Patch
patch
,
PEPIdentity
submitter
,
PatchDialog
.
PatchAction
patchAction
,
bool
isEditable
=
false
)
public
FormControlPatchViewModel
(
Patch
patch
,
PEPIdentity
submitter
,
bool
isEditable
=
false
)
{
{
this
.
patch
=
patch
;
this
.
patch
=
patch
;
this
.
IsEditable
=
isEditable
;
this
.
IsEditable
=
isEditable
;
this
.
Submitter
=
submitter
;
this
.
Submitter
=
submitter
;
this
.
Explanation
=
"New configuration changes pending approval"
;
switch
(
patchAction
)
this
.
IsRejectButtonVisible
=
true
;
{
this
.
OKButtonText
=
"Support"
;
case
PatchDialog
.
PatchAction
.
EditPatch
:
break
;
case
PatchDialog
.
PatchAction
.
NewPatch
:
{
this
.
Explanation
=
"New patch"
;
}
break
;
case
PatchDialog
.
PatchAction
.
ShowPatch
:
{
this
.
Explanation
=
"Patch "
+
patch
.
Id
;
this
.
IsCancelButtonVisible
=
false
;
}
break
;
case
PatchDialog
.
PatchAction
.
SupportOrRejectPatch
:
{
this
.
Explanation
=
"New configuration changes pending approval"
;
this
.
IsRejectButtonVisible
=
true
;
this
.
OKButtonText
=
"Support"
;
}
break
;
default
:
break
;
}
this
.
DisplayDiff
=
this
.
FormatDiff
();
this
.
DisplayDiff
=
this
.
FormatDiff
();
this
.
ValidatePatch
();
}
}
#
endregion
#
endregion
...
@@ -314,11 +267,6 @@ namespace pEp.UI.ViewModels
...
@@ -314,11 +267,6 @@ namespace pEp.UI.ViewModels
return
document
;
return
document
;
}
}
private
void
LoadFromFile
(
object
parameter
)
{
// Get diff from disk
}
private
void
RejectPatch
(
object
parameter
)
private
void
RejectPatch
(
object
parameter
)
{
{
Globals
.
ThisAddIn
.
DistributedPolicyEngine
.
Reject
(
this
.
patch
,
new
PEPIdentity
());
Globals
.
ThisAddIn
.
DistributedPolicyEngine
.
Reject
(
this
.
patch
,
new
PEPIdentity
());
...
@@ -329,18 +277,6 @@ namespace pEp.UI.ViewModels
...
@@ -329,18 +277,6 @@ namespace pEp.UI.ViewModels
Globals
.
ThisAddIn
.
DistributedPolicyEngine
.
Support
(
this
.
patch
,
new
PEPIdentity
());
Globals
.
ThisAddIn
.
DistributedPolicyEngine
.
Support
(
this
.
patch
,
new
PEPIdentity
());
}
}
/// <summary>
/// Validates the patch.
/// </summary>
private
void
ValidatePatch
()
{
this
.
IsCommitMessageValid
=
!
string
.
IsNullOrEmpty
(
this
.
CommitMessage
);
this
.
IsDiffValid
=
!
string
.
IsNullOrEmpty
(
this
.
Diff
);
this
.
IsUriValid
=
!
string
.
IsNullOrEmpty
(
this
.
Uri
);
this
.
IsValid
=
this
.
IsCommitMessageValid
&&
this
.
IsDiffValid
&&
this
.
IsUriValid
;
}
#
endregion
#
endregion
}
}
}
}
UI/ViewModels/PatchDialogViewModel.cs
View file @
0cdb38d0
This diff is collapsed.
Click to expand it.
UI/Views/PatchDialogView.xaml
View file @
0cdb38d0
<UserControl xmlns:UI="clr-namespace:pEp.UI"
<UserControl x:Class="pEp.UI.Views.PatchDialogView"
x:Class="pEp.UI.Views.PatchDialogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:p="clr-namespace:pEp.Properties"
xmlns:ui="clr-namespace:pEp.UI"
xmlns:ui="clr-namespace:pEp.UI"
xmlns:vm="clr-namespace:pEp.UI.ViewModels"
xmlns:vm="clr-namespace:pEp.UI.ViewModels"
mc:Ignorable="d"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=vm:PatchDialogViewModel}"
d:DataContext="{d:DesignInstance Type=vm:PatchDialogViewModel}"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="450" d:DesignWidth="800">
...
@@ -26,105 +24,83 @@
...
@@ -26,105 +24,83 @@
<Grid>
<Grid>
<Grid.ColumnDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
</Grid.RowDefinitions>
<Label Grid.Column="0"
<Label Grid.Row="0"
Grid.Row="0"
Grid.Column="0"
Content="{Binding Explanation}"
Grid.ColumnSpan="3"
Content="Change config"
Margin="10"/>
Margin="10"/>
<Button Grid.Column="1"
<ListBox Grid.Row="1"
Grid.Row="0"
Grid.Column="0"
Content="Load from file"
Margin="10"
Margin="10"
Width="500"
HorizontalAlignment="Right"
Height="500"
Style="{StaticResource StyleButtonGray}"
SelectedItem="{Binding SelectedFile}"
Command="{Binding LoadFromFileCommand}" />
ItemsSource="{Binding ConfigFiles}">
<Label Grid.Column="0"
<ListBox.ItemTemplate>
Grid.Row="1"
<DataTemplate>
Content="Diff*"
<Label Content="{Binding Item1}" />
Margin="10,10,5,10"/>
</DataTemplate>
<UI:TextBoxWithPlaceholder Grid.Column="1"
</ListBox.ItemTemplate>
Grid.Row="1"
</ListBox>
Text="{Binding Diff, UpdateSourceTrigger=PropertyChanged}"
<StackPanel Grid.Row="1"
MultiLine="True"
Grid.Column="1">
IsReadOnly="{Binding IsEditable, Converter={StaticResource InvertBool}}"
<Button Content="Add file"
IsValidInput="{Binding IsDiffValid}"
Margin="5"
Placeholder="Please add diff"
Style="{StaticResource StyleButtonGray}"
Height="400"
Command="{Binding LoadFromFileCommand}"/>
Width="600"
<Button Content="Remove file"
Margin="5,10,10,10"
Margin="5"
Visibility="{Binding IsEditable, Converter={StaticResource BoolToVisibility}}"/>
Style="{StaticResource StyleButtonGray}"
<FlowDocumentScrollViewer Grid.Column="1"
Command="{Binding RemoveButtonCommand}" />
</StackPanel>
<FlowDocumentScrollViewer Grid.Column="2"
Grid.Row="1"
Grid.Row="1"
Height="400"
Width="500"
Width="600"
Height="500"
BorderBrush="Black"
BorderThickness="1"
Margin="5,10,10,10"
Margin="5,10,10,10"
Document="{Binding DisplayDiff}"
Document="{Binding VisibleDiff}"/>
Visibility="{Binding IsEditable, Converter={StaticResource InvertBoolToVisibility}}"/>
<ui:TextBoxWithPlaceholder Grid.Column="0"
<Label Grid.Column="0"
Grid.ColumnSpan="3"
Grid.Row="2"
Content="Uri*"
Margin="10,10,5,10"/>
<UI:TextBoxWithPlaceholder Grid.Column="1"
Grid.Row="2"
Grid.Row="2"
Text="{Binding Uri}"
Text="{Binding CommitMessage, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="{Binding IsEditable, Converter={StaticResource InvertBool}}"
IsValidInput="{Binding IsUriValid}"
Placeholder="URI"
MinWidth="400"
Margin="5,10,10,10"/>
<Label Grid.Column="0"
Grid.Row="3"
Content="Commit message*"
Margin="10,10,5,10"/>
<UI:TextBoxWithPlaceholder Grid.Column="1"
Grid.Row="3"
Text="{Binding CommitMessage}"
IsReadOnly="{Binding IsEditable, Converter={StaticResource InvertBool}}"
IsValidInput="{Binding IsCommitMessageValid}"
IsValidInput="{Binding IsCommitMessageValid}"
Placeholder="Commit message"
Placeholder="Commit message"
MinWidth="400"
Margin="5,10,10,10"
Margin="5,10,10,10"/>
Visibility="{Binding IsEditable, Converter={StaticResource BoolToVisibility}}"/>
<Label Grid.Column="0"
<ui:TextBoxWithPlaceholder Grid.Column="0"
Grid.Row="4"
Grid.ColumnSpan="3"
Content="Tag"
Grid.Row="3"
Margin="10,10,5,10"/>
Text="{Binding Tag, UpdateSourceTrigger=PropertyChanged}"
<UI:TextBoxWithPlaceholder Grid.Column="1"
Grid.Row="4"
Text="{Binding Tag}"
IsReadOnly="{Binding IsEditable, Converter={StaticResource InvertBool}}"
Placeholder="Tag (optional)"
Placeholder="Tag (optional)"
M
inWidth="40
0"
M
argin="5,10,10,1
0"
Margin="5,10,10,10
"/>
Visibility="{Binding IsEditable, Converter={StaticResource BoolToVisibility}}
"/>
<StackPanel Grid.Column="0"
<StackPanel Grid.Column="0"
Grid.ColumnSpan="
2
"
Grid.ColumnSpan="
3
"
Grid.Row="
5
"
Grid.Row="
4
"
Orientation="Horizontal"
Orientation="Horizontal"
HorizontalAlignment="Center">
HorizontalAlignment="Center"
Margin="10">
<Button Content="{Binding OKButtonText}"
<Button Content="{Binding OKButtonText}"
Command="{Binding OKButtonCommand}"
Command="{Binding OKButtonCommand}"
IsDefault="True"
IsEnabled="{Binding IsValid}"
Visibility="{Binding IsOKButtonVisible, Converter={StaticResource BoolToVisibility}}"
Margin="10"
Style="{StaticResource StyleButtonGray}"
Style="{StaticResource StyleButtonGray}"/>
Margin="10" />
<Button Content="{Binding RejectButtonText}"
Command="{Binding RejectButtonCommand}"
Visibility="{Binding IsRejectButtonVisible, Converter={StaticResource BoolToVisibility}}"
Style="{StaticResource StyleButtonGray}"
Margin="10" />
<Button Content="{Binding CancelButtonText}"
<Button Content="{Binding CancelButtonText}"
Margin="10"
Command="{Binding CancelButtonCommand}"
Command="{Binding CancelButtonCommand}"
Visibility="{Binding IsCancelButtonVisible, Converter={StaticResource BoolToVisibility}}"
Style="{StaticResource StyleButtonGray}"/>
Style="{StaticResource StyleButtonGray}"
Margin="10"/>
</StackPanel>
</StackPanel>
</Grid>
</Grid>
</UserControl>
</UserControl>
pEpForOutlook.csproj
View file @
0cdb38d0
...
@@ -251,6 +251,9 @@
...
@@ -251,6 +251,9 @@
-->
-->
<ItemGroup>
<ItemGroup>
<Reference
Include=
"Accessibility"
/>
<Reference
Include=
"Accessibility"
/>
<Reference
Include=
"DiffPlex, Version=1.7.0.0, Culture=neutral, PublicKeyToken=1d35e91d1bd7bc0f, processorArchitecture=MSIL"
>
<HintPath>
..\packages\DiffPlex.1.7.0\lib\net40\DiffPlex.dll
</HintPath>
</Reference>
<Reference
Include=
"Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
>
<Reference
Include=
"Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
>
<EmbedInteropTypes>
True
</EmbedInteropTypes>
<EmbedInteropTypes>
True
</EmbedInteropTypes>
</Reference>
</Reference>
...
...
packages.config
View file @
0cdb38d0
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
packages
>
<
package
id
=
"DiffPlex"
version
=
"1.7.0"
targetFramework
=
"net45"
/>
<
package
id
=
"Microsoft.VisualStudio.OLE.Interop"
version
=
"16.7.30328.74"
targetFramework
=
"net45"
/>
<
package
id
=
"Microsoft.VisualStudio.OLE.Interop"
version
=
"16.7.30328.74"
targetFramework
=
"net45"
/>
<
package
id
=
"MimeKitLite"
version
=
"2.10.1"
targetFramework
=
"net45"
/>
<
package
id
=
"MimeKitLite"
version
=
"2.10.1"
targetFramework
=
"net45"
/>
<
package
id
=
"Newtonsoft.Json"
version
=
"13.0.1"
targetFramework
=
"net45"
/>
<
package
id
=
"Newtonsoft.Json"
version
=
"13.0.1"
targetFramework
=
"net45"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment