Skip to content

Commit 61af13d

Browse files
Fix/UI stablility (#468)
* Fix double click on view manifest button check the manifest hash on upload ballots * updated version number
1 parent 36c0be3 commit 61af13d

7 files changed

Lines changed: 56 additions & 6 deletions

File tree

src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<ApplicationIdGuid>c0679a79-bc22-46ad-9c49-93de983e3fa2</ApplicationIdGuid>
1919

2020
<!-- Versions -->
21-
<ApplicationDisplayVersion>1.91.16</ApplicationDisplayVersion>
22-
<ApplicationVersion>14</ApplicationVersion>
21+
<ApplicationDisplayVersion>1.91.17</ApplicationDisplayVersion>
22+
<ApplicationVersion>17</ApplicationVersion>
2323

2424
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.3</SupportedOSPlatformVersion>
2525
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</SupportedOSPlatformVersion>

src/electionguard-ui/ElectionGuard.UI/Platforms/Windows/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
55
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap rescap">
66

7-
<Identity Name="ElectionGuard.Admin" Publisher="CN=Microsoft" Version="1.91.16.0" />
7+
<Identity Name="ElectionGuard.Admin" Publisher="CN=Microsoft" Version="1.91.17.0" />
88

99
<mp:PhoneIdentity PhoneProductId="F7E69798-9268-43DC-A51E-3A95FA4992AD" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
1010

src/electionguard-ui/ElectionGuard.UI/Resx/AppResources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/electionguard-ui/ElectionGuard.UI/Resx/AppResources.es.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,4 +648,7 @@
648648
<data name="NetworkIssueText" xml:space="preserve">
649649
<value>Hubo un problema con la red que causó un problema con lo que estabas haciendo. ¡Vuelve a iniciar sesión cuando se haya restablecido la conexión de red!</value>
650650
</data>
651+
<data name="WrongElectionText" xml:space="preserve">
652+
<value>Drive contiene papeletas para una elección diferente.!</value>
653+
</data>
651654
</root>

src/electionguard-ui/ElectionGuard.UI/Resx/AppResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,4 +645,7 @@
645645
<data name="NetworkIssueText" xml:space="preserve">
646646
<value>There was an issue with the network that caused an issue with what you were doing. Please log back in when the network connection has been restored</value>
647647
</data>
648+
<data name="WrongElectionText" xml:space="preserve">
649+
<value>Drive contains ballots for a different election.</value>
650+
</data>
648651
</root>

src/electionguard-ui/ElectionGuard.UI/ViewModels/BallotUploadViewModel.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public partial class BallotUploadViewModel : BaseViewModel
1212
{
1313
public const string ElectionIdParam = "ElectionId";
1414
private const string _artifactSubFolder = "artifacts";
15+
private const string _contextFilename = "context.json";
1516
private const string _ballotSubFolder = "encrypted_ballots";
1617
private readonly string[] _deviceFolderNames = { "devices", "encryption_devices" };
1718

@@ -403,6 +404,17 @@ await Shell.Current.CurrentPage.Dispatcher.DispatchAsync(async () =>
403404
return;
404405
}
405406

407+
if (await ValidateElectionId(drive, _manifestHash!) == false)
408+
{
409+
ErrorMessage = AppResources.WrongElectionText;
410+
_importing = false;
411+
return;
412+
}
413+
else
414+
{
415+
ErrorMessage = string.Empty;
416+
}
417+
406418
// find device file
407419
var devices = Directory.GetFiles(devicePath);
408420
foreach (var device in devices)
@@ -466,6 +478,18 @@ private string GetDevicesPath(DriveInfo drive)
466478
return string.Empty;
467479
}
468480

481+
private async Task<bool> ValidateElectionId(DriveInfo drive, ElementModQ electionHash)
482+
{
483+
var filePath = Path.Combine(drive.Name, _artifactSubFolder, _contextFilename);
484+
if (File.Exists(filePath))
485+
{
486+
var contextData = await ReadFileAsync(filePath);
487+
var context = new CiphertextElectionContext(contextData);
488+
return context.ManifestHash.Equals(electionHash);
489+
}
490+
return false;
491+
}
492+
469493
public override async Task OnAppearing()
470494
{
471495
await base.OnAppearing();

src/electionguard-ui/ElectionGuard.UI/ViewModels/ElectionViewModel.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public ElectionViewModel(
4848
[NotifyCanExecuteChangedFor(nameof(AddBallotsCommand))]
4949
private Election? _currentElection;
5050

51+
[ObservableProperty]
52+
[NotifyCanExecuteChangedFor(nameof(ViewCommand))]
53+
private bool _isViewing;
54+
5155
[ObservableProperty]
5256
private string _electionId;
5357

@@ -315,14 +319,21 @@ private async Task MarkCurrentElectionAsExported()
315319
Step1Complete = true;
316320
}
317321

318-
[RelayCommand]
322+
[RelayCommand(CanExecute = nameof(CanView))]
319323
private async Task View()
320324
{
325+
IsViewing = true;
321326
var vm = (ManifestViewModel)Ioc.Default.GetService(typeof(ManifestViewModel));
322327
vm.Manifest = new Manifest(Manifest.ToJson());
323328

324-
await NavigationService.GoToModal(typeof(ManifestViewModel));
329+
await NavigationService.GoToModal(typeof(ManifestViewModel));
330+
IsViewing = false;
325331
}
332+
333+
private bool CanView()
334+
{
335+
return !IsViewing;
336+
}
326337

327338
partial void OnManifestRecordChanged(ManifestRecord value)
328339
{

0 commit comments

Comments
 (0)