Skip to content

Commit

Permalink
SEBWIN-593, #431: Implemented new configuration option to show or hid…
Browse files Browse the repository at this point in the history
…e the path of file system elements.
  • Loading branch information
dbuechel committed Mar 9, 2023
1 parent 669b51d commit 0cdffd8
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 328 deletions.
3 changes: 2 additions & 1 deletion SafeExamBrowser.Browser/BrowserWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ private void DialogHandler_DialogRequested(DialogRequestedEventArgs args)
initialPath,
title: args.Title,
parent: window,
restrictNavigation: !settings.AllowCustomDownAndUploadLocation);
restrictNavigation: !settings.AllowCustomDownAndUploadLocation,
showElementPath: settings.ShowFileSystemElementPath);

if (result.Success)
{
Expand Down
2 changes: 2 additions & 0 deletions SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ public void Operations_MustAskForApplicationPath()
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<IWindow>(),
It.IsAny<bool>(),
It.IsAny<bool>())).Returns(result);
text.SetReturnsDefault(string.Empty);

Expand All @@ -636,6 +637,7 @@ public void Operations_MustAbortAskingForApplicationPath()
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<IWindow>(),
It.IsAny<bool>(),
It.IsAny<bool>())).Returns(result);
text.SetReturnsDefault(string.Empty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,18 @@ internal override void Map(string key, object value, AppSettings settings)
case Keys.Browser.ResetOnQuitUrl:
MapResetOnQuitUrl(settings, value);
break;
case Keys.Browser.SendCustomHeaders:
MapSendCustomHeaders(settings, value);
break;
case Keys.Browser.ShowFileSystemElementPath:
MapShowFileSystemElementPath(settings, value);
break;
case Keys.Browser.ShowReloadButton:
MapShowReloadButton(settings, value);
break;
case Keys.Browser.ShowToolbar:
MapShowToolbar(settings, value);
break;
case Keys.Browser.SendCustomHeaders:
MapSendCustomHeaders(settings, value);
break;
case Keys.Browser.StartUrl:
MapStartUrl(settings, value);
break;
Expand Down Expand Up @@ -476,29 +479,37 @@ private void MapShowReloadWarning(AppSettings settings, object value)
}
}

private void MapShowReloadWarningAdditionalWindow(AppSettings settings, object value)
private void MapSendCustomHeaders(AppSettings settings, object value)
{
if (value is bool send)
{
settings.Browser.SendConfigurationKey = send;
settings.Browser.SendBrowserExamKey = send;
}
}

private void MapShowFileSystemElementPath(AppSettings settings, object value)
{
if (value is bool show)
{
settings.Browser.AdditionalWindow.ShowReloadWarning = show;
settings.Browser.ShowFileSystemElementPath = show;
}
}

private void MapShowToolbar(AppSettings settings, object value)
private void MapShowReloadWarningAdditionalWindow(AppSettings settings, object value)
{
if (value is bool show)
{
settings.Browser.AdditionalWindow.ShowToolbar = show;
settings.Browser.MainWindow.ShowToolbar = show;
settings.Browser.AdditionalWindow.ShowReloadWarning = show;
}
}

private void MapSendCustomHeaders(AppSettings settings, object value)
private void MapShowToolbar(AppSettings settings, object value)
{
if (value is bool send)
if (value is bool show)
{
settings.Browser.SendConfigurationKey = send;
settings.Browser.SendBrowserExamKey = send;
settings.Browser.AdditionalWindow.ShowToolbar = show;
settings.Browser.MainWindow.ShowToolbar = show;
}
}

Expand Down
3 changes: 3 additions & 0 deletions SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ internal AppSettings LoadDefaultSettings()
settings.Browser.PopupPolicy = PopupPolicy.Allow;
settings.Browser.Proxy.Policy = ProxyPolicy.System;
settings.Browser.ResetOnQuitUrl = false;
settings.Browser.SendBrowserExamKey = false;
settings.Browser.SendConfigurationKey = false;
settings.Browser.ShowFileSystemElementPath = true;
settings.Browser.StartUrl = "https://www.safeexambrowser.org/start";
settings.Browser.UseCustomUserAgent = false;
settings.Browser.UseQueryParameter = false;
Expand Down
3 changes: 2 additions & 1 deletion SafeExamBrowser.Configuration/ConfigurationData/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ internal static class Browser
internal const string QuitUrl = "quitURL";
internal const string QuitUrlConfirmation = "quitURLConfirm";
internal const string ResetOnQuitUrl = "quitURLRestart";
internal const string SendCustomHeaders = "sendBrowserExamKey";
internal const string ShowFileSystemElementPath = "browserShowFileSystemElementPath";
internal const string ShowReloadButton = "showReloadButton";
internal const string ShowToolbar = "enableBrowserWindowToolbar";
internal const string SendCustomHeaders = "sendBrowserExamKey";
internal const string StartUrl = "startURL";
internal const string UserAgentModeDesktop = "browserUserAgentWinDesktopMode";
internal const string UserAgentModeMobile = "browserUserAgentWinTouchMode";
Expand Down
5 changes: 5 additions & 0 deletions SafeExamBrowser.Settings/Browser/BrowserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public class BrowserSettings
/// </summary>
public bool SendBrowserExamKey { get; set; }

/// <summary>
/// Determines whether the user will be able to see the path of a file system element in the file system dialog (e.g. when down- or uploading a file).
/// </summary>
public bool ShowFileSystemElementPath { get; set; }

/// <summary>
/// The URL with which the main browser window will be loaded.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ public interface IFileSystemDialog
FileSystemDialogResult Show(
FileSystemElement element,
FileSystemOperation operation,
string initialPath = default(string),
string message = default(string),
string title = default(string),
IWindow parent = default(IWindow),
bool restrictNavigation = false);
string initialPath = default,
string message = default,
string title = default,
IWindow parent = default,
bool restrictNavigation = false,
bool showElementPath = true);
}
}
17 changes: 9 additions & 8 deletions SafeExamBrowser.UserInterface.Desktop/FileSystemDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace SafeExamBrowser.UserInterface.Desktop
{
public class FileSystemDialogFactory : IFileSystemDialog
{
private IText text;
private readonly IText text;

public FileSystemDialogFactory(IText text)
{
Expand All @@ -26,19 +26,20 @@ public FileSystemDialogFactory(IText text)
public FileSystemDialogResult Show(
FileSystemElement element,
FileSystemOperation operation,
string initialPath = default(string),
string message = null,
string title = null,
IWindow parent = null,
bool restrictNavigation = false)
string initialPath = default,
string message = default,
string title = default,
IWindow parent = default,
bool restrictNavigation = false,
bool showElementPath = true)
{
if (parent is Window window)
{
return window.Dispatcher.Invoke(() => new FileSystemDialog(element, operation, text, initialPath, message, title, parent, restrictNavigation).Show());
return window.Dispatcher.Invoke(() => new FileSystemDialog(element, operation, text, initialPath, message, title, parent, restrictNavigation, showElementPath).Show());
}
else
{
return new FileSystemDialog(element, operation, text, initialPath, message, title, restrictNavigation: restrictNavigation).Show();
return new FileSystemDialog(element, operation, text, initialPath, message, title, restrictNavigation: restrictNavigation, showElementPath: showElementPath).Show();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,34 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows
{
internal partial class FileSystemDialog : Window
{
private FileSystemElement element;
private string initialPath;
private string message;
private FileSystemOperation operation;
private IWindow parent;
private bool restrictNavigation;
private IText text;
private string title;
private readonly FileSystemElement element;
private readonly string initialPath;
private readonly string message;
private readonly FileSystemOperation operation;
private readonly IWindow parent;
private readonly bool restrictNavigation;
private readonly bool showElementPath;
private readonly IText text;
private readonly string title;

internal FileSystemDialog(
FileSystemElement element,
FileSystemOperation operation,
IText text,
string initialPath = default(string),
string message = default(string),
string title = default(string),
IWindow parent = default(IWindow),
bool restrictNavigation = false)
string initialPath = default,
string message = default,
string title = default,
IWindow parent = default,
bool restrictNavigation = false,
bool showElementPath = true)
{
this.element = element;
this.initialPath = initialPath;
this.message = message;
this.operation = operation;
this.parent = parent;
this.restrictNavigation = restrictNavigation;
this.showElementPath = showElementPath;
this.text = text;
this.title = title;

Expand Down Expand Up @@ -284,6 +287,7 @@ private void InitializeDialog()
OperationIcon.Icon = operation == FileSystemOperation.Save ? FontAwesomeIcon.Download : FontAwesomeIcon.Search;
SelectButton.Click += SelectButton_Click;
SelectButton.Content = text.Get(TextKey.FileSystemDialog_Select);
SelectedElement.Visibility = showElementPath ? Visibility.Visible : Visibility.Hidden;

InitializeText();
InitializeFileSystem();
Expand Down Expand Up @@ -364,7 +368,7 @@ private void SelectInitialPath(ItemCollection items, List<string> segments)
{
var segment = segments.FirstOrDefault();

if (segment != default(string))
if (segment != default)
{
foreach (var item in items)
{
Expand Down
17 changes: 9 additions & 8 deletions SafeExamBrowser.UserInterface.Mobile/FileSystemDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace SafeExamBrowser.UserInterface.Mobile
{
public class FileSystemDialogFactory : IFileSystemDialog
{
private IText text;
private readonly IText text;

public FileSystemDialogFactory(IText text)
{
Expand All @@ -26,19 +26,20 @@ public FileSystemDialogFactory(IText text)
public FileSystemDialogResult Show(
FileSystemElement element,
FileSystemOperation operation,
string initialPath = default(string),
string message = null,
string title = null,
IWindow parent = null,
bool restrictNavigation = false)
string initialPath = default,
string message = default,
string title = default,
IWindow parent = default,
bool restrictNavigation = false,
bool showElementPath = true)
{
if (parent is Window window)
{
return window.Dispatcher.Invoke(() => new FileSystemDialog(element, operation, text, initialPath, message, title, parent, restrictNavigation).Show());
return window.Dispatcher.Invoke(() => new FileSystemDialog(element, operation, text, initialPath, message, title, parent, restrictNavigation, showElementPath).Show());
}
else
{
return new FileSystemDialog(element, operation, text, initialPath, message, title, restrictNavigation: restrictNavigation).Show();
return new FileSystemDialog(element, operation, text, initialPath, message, title, restrictNavigation: restrictNavigation, showElementPath: showElementPath).Show();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,34 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows
{
internal partial class FileSystemDialog : Window
{
private FileSystemElement element;
private string initialPath;
private string message;
private FileSystemOperation operation;
private IText text;
private string title;
private IWindow parent;
private bool restrictNavigation;
private readonly FileSystemElement element;
private readonly string initialPath;
private readonly string message;
private readonly FileSystemOperation operation;
private readonly IWindow parent;
private readonly bool restrictNavigation;
private readonly bool showElementPath;
private readonly IText text;
private readonly string title;

internal FileSystemDialog(
FileSystemElement element,
FileSystemOperation operation,
IText text,
string initialPath = default(string),
string message = default(string),
string title = default(string),
IWindow parent = default(IWindow),
bool restrictNavigation = false)
string initialPath = default,
string message = default,
string title = default,
IWindow parent = default,
bool restrictNavigation = false,
bool showElementPath = true)
{
this.element = element;
this.initialPath = initialPath;
this.message = message;
this.operation = operation;
this.parent = parent;
this.restrictNavigation = restrictNavigation;
this.showElementPath = showElementPath;
this.text = text;
this.title = title;

Expand Down Expand Up @@ -284,6 +287,7 @@ private void InitializeDialog()
OperationIcon.Icon = operation == FileSystemOperation.Save ? FontAwesomeIcon.Download : FontAwesomeIcon.Search;
SelectButton.Click += SelectButton_Click;
SelectButton.Content = text.Get(TextKey.FileSystemDialog_Select);
SelectedElement.Visibility = showElementPath ? Visibility.Visible : Visibility.Hidden;

InitializeText();
InitializeFileSystem();
Expand Down Expand Up @@ -364,7 +368,7 @@ private void SelectInitialPath(ItemCollection items, List<string> segments)
{
var segment = segments.FirstOrDefault();

if (segment != default(string))
if (segment != default)
{
foreach (var item in items)
{
Expand Down
2 changes: 2 additions & 0 deletions SebWindowsConfig/SEBSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public class SEBSettings
public const String KeyDownloadAndOpenSebConfig = "downloadAndOpenSebConfig";
public const String KeyBackgroundOpenSEBConfig = "backgroundOpenSEBConfig";
public const String KeyUseTemporaryDownUploadDirectory = "useTemporaryDownUploadDirectory";
public const String KeyShowFileSystemElementPath = "browserShowFileSystemElementPath";

// Group "Exam"
public const String KeyExamKeySalt = "examKeySalt";
Expand Down Expand Up @@ -713,6 +714,7 @@ public static void CreateDefaultAndCurrentSettingsFromScratch()
SEBSettings.settingsDefault.Add(SEBSettings.KeyDownloadAndOpenSebConfig, true);
SEBSettings.settingsDefault.Add(SEBSettings.KeyBackgroundOpenSEBConfig, false);
SEBSettings.settingsDefault.Add(SEBSettings.KeyUseTemporaryDownUploadDirectory, false);
SEBSettings.settingsDefault.Add(SEBSettings.KeyShowFileSystemElementPath, true);

// Default settings for group "Exam"
SEBSettings.settingsDefault.Add(SEBSettings.KeyExamKeySalt, new Byte[] { });
Expand Down
Loading

0 comments on commit 0cdffd8

Please sign in to comment.