mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-04 16:09:40 +00:00
Added an option for mandatory terms of use dialogs (#725)
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,deb,updater, appimage,deb) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,deb,updater, appimage,deb) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,deb,updater, appimage,deb) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,deb,updater, appimage,deb) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
This commit is contained in:
1 parent
09258c7548
commit
8b11e2317b
29 files changed
+836
-21
No files matched your search
@@ -114,6 +114,8 @@ public sealed class Data
|
||||
|
||||
public DataDocumentAnalysis DocumentAnalysis { get; init; } = new();
|
||||
|
||||
public DataMandatoryInformation MandatoryInformation { get; init; } = new();
|
||||
|
||||
public DataTextSummarizer TextSummarizer { get; init; } = new();
|
||||
|
||||
public DataTextContentCleaner TextContentCleaner { get; init; } = new();
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Lua;
|
||||
|
||||
namespace AIStudio.Settings.DataModel;
|
||||
|
||||
public sealed record DataMandatoryInfo
|
||||
{
|
||||
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger<DataMandatoryInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// The stable ID of the mandatory info.
|
||||
/// </summary>
|
||||
public string Id { get; private init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the enterprise configuration plugin that provides this info.
|
||||
/// </summary>
|
||||
public Guid EnterpriseConfigurationPluginId { get; private init; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The title shown to the user.
|
||||
/// </summary>
|
||||
public string Title { get; private init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The configured version string shown to the user. A changed version triggers re-acceptance
|
||||
/// and allows the UI to distinguish a new version from a content-only change.
|
||||
/// </summary>
|
||||
public string VersionText { get; private init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The Markdown content shown to the user.
|
||||
/// </summary>
|
||||
public string Markdown { get; private init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The label of the acceptance button.
|
||||
/// </summary>
|
||||
public string AcceptButtonText { get; private init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The label of the reject button.
|
||||
/// </summary>
|
||||
public string RejectButtonText { get; private init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The current hash used to determine whether the user needs to re-accept the info.
|
||||
/// </summary>
|
||||
public string AcceptanceHash { get; private init; } = string.Empty;
|
||||
|
||||
private static string CreateAcceptanceHash(string versionText, string title, string markdown)
|
||||
{
|
||||
var content = $"Version:{versionText}\nTitle:{title}\nMarkdown:{markdown}";
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
var hash = SHA256.HashData(bytes);
|
||||
|
||||
return Convert.ToHexString(hash);
|
||||
}
|
||||
|
||||
public static bool TryParseConfiguration(int idx, LuaTable table, Guid configPluginId, out DataMandatoryInfo mandatoryInfo)
|
||||
{
|
||||
mandatoryInfo = new DataMandatoryInfo();
|
||||
if (!table.TryGetValue("Id", out var idValue) || !idValue.TryRead<string>(out var idText) || !Guid.TryParse(idText, out var id))
|
||||
{
|
||||
LOG.LogWarning("The configured mandatory info {InfoIndex} does not contain a valid ID. The ID must be a valid GUID.", idx);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!table.TryGetValue("Title", out var titleValue) || !titleValue.TryRead<string>(out var title) || string.IsNullOrWhiteSpace(title))
|
||||
{
|
||||
LOG.LogWarning("The configured mandatory info {InfoIndex} does not contain a valid Title field.", idx);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!table.TryGetValue("Version", out var versionValue) || !versionValue.TryRead<string>(out var versionText) || string.IsNullOrWhiteSpace(versionText))
|
||||
{
|
||||
LOG.LogWarning("The configured mandatory info {InfoIndex} does not contain a valid Version field.", idx);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!table.TryGetValue("Markdown", out var markdownValue) || !markdownValue.TryRead<string>(out var markdown) || string.IsNullOrWhiteSpace(markdown))
|
||||
{
|
||||
LOG.LogWarning("The configured mandatory info {InfoIndex} does not contain a valid Markdown field.", idx);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!table.TryGetValue("AcceptButtonText", out var acceptButtonValue) || !acceptButtonValue.TryRead<string>(out var acceptButtonText) || string.IsNullOrWhiteSpace(acceptButtonText))
|
||||
{
|
||||
LOG.LogWarning("The configured mandatory info {InfoIndex} does not contain a valid AcceptButtonText field.", idx);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!table.TryGetValue("RejectButtonText", out var rejectButtonValue) || !rejectButtonValue.TryRead<string>(out var rejectButtonText) || string.IsNullOrWhiteSpace(rejectButtonText))
|
||||
{
|
||||
LOG.LogWarning("The configured mandatory info {InfoIndex} does not contain a valid RejectButtonText field.", idx);
|
||||
return false;
|
||||
}
|
||||
|
||||
var normalizedMarkdown = AIStudio.Tools.Markdown.RemoveSharedIndentation(markdown);
|
||||
var acceptanceHash = CreateAcceptanceHash(versionText, title, normalizedMarkdown);
|
||||
mandatoryInfo = new DataMandatoryInfo
|
||||
{
|
||||
Id = id.ToString(),
|
||||
Title = title,
|
||||
VersionText = versionText,
|
||||
Markdown = normalizedMarkdown,
|
||||
AcceptButtonText = acceptButtonText,
|
||||
RejectButtonText = rejectButtonText,
|
||||
EnterpriseConfigurationPluginId = configPluginId,
|
||||
AcceptanceHash = acceptanceHash,
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace AIStudio.Settings.DataModel;
|
||||
|
||||
public sealed record DataMandatoryInfoAcceptance
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the mandatory info that was accepted.
|
||||
/// </summary>
|
||||
public string InfoId { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The accepted version string.
|
||||
/// </summary>
|
||||
public string AcceptedVersion { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The accepted hash of the mandatory info content.
|
||||
/// </summary>
|
||||
public string AcceptedHash { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The UTC time of the acceptance.
|
||||
/// </summary>
|
||||
public DateTimeOffset AcceptedAtUtc { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The plugin that provided the accepted info at the time of acceptance.
|
||||
/// </summary>
|
||||
public Guid EnterpriseConfigurationPluginId { get; init; } = Guid.Empty;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace AIStudio.Settings.DataModel;
|
||||
|
||||
public sealed class DataMandatoryInformation
|
||||
{
|
||||
/// <summary>
|
||||
/// Persisted user acceptances for configured mandatory infos.
|
||||
/// </summary>
|
||||
public List<DataMandatoryInfoAcceptance> Acceptances { get; set; } = [];
|
||||
|
||||
public DataMandatoryInfoAcceptance? FindAcceptance(string infoId)
|
||||
{
|
||||
return this.Acceptances.LastOrDefault(acceptance => string.Equals(acceptance.InfoId, infoId, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public bool RemoveLeftOverAcceptances(IEnumerable<DataMandatoryInfo> mandatoryInfos)
|
||||
{
|
||||
var validInfoIds = mandatoryInfos
|
||||
.Select(info => info.Id)
|
||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var removedCount = this.Acceptances.RemoveAll(acceptance => !validInfoIds.Contains(acceptance.InfoId));
|
||||
return removedCount > 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user