Skip to content

Commit

Permalink
Refactor audit log deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
tomahg committed Oct 28, 2024
1 parent ac61627 commit 7c7e4e5
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 127 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ Or add a group that should be able to delete the audit logs for all users.
})
```

Audit logs are stored in Dynamic Data Store (DSS), and when they are deleted from the UI (with the button «Clear all logs»), the entire DSS store is deleted.
Audit logs are stored in Dynamic Data Store (DSS), and when they are deleted from the UI (with the button «Delete all logs»), the entire DSS store is deleted.

By default audit logs are deleted automatically after a 30 day retention time, but this can be changed with this appsetting.

Expand Down
57 changes: 0 additions & 57 deletions src/Gulla.Episerver.SqlStudio/Controllers/AdminController.cs

This file was deleted.

22 changes: 20 additions & 2 deletions src/Gulla.Episerver.SqlStudio/Controllers/AuditLogController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Linq;
using System.Net;
using Gulla.Episerver.SqlStudio.Configuration;
using Gulla.Episerver.SqlStudio.Dds;
using Gulla.Episerver.SqlStudio.ViewModels;
Expand Down Expand Up @@ -38,10 +39,27 @@ public ActionResult Index()

var model = new AuditLogViewModel
{
Logs = _configurationService.CanUserViewAllAuditLogs() ? _sqlStudioDdsRepository.ListAll() : _sqlStudioDdsRepository.ListAll(User.Identity.Name)
Logs = _configurationService.CanUserViewAllAuditLogs() ? _sqlStudioDdsRepository.ListAll() : _sqlStudioDdsRepository.ListAll(User.Identity.Name),
LogsCount = _configurationService.CanUserDeleteAuditLogs() ? _sqlStudioDdsRepository.ListAll().Count() : 0,
ShowDeleteButton = _configurationService.CanUserDeleteAuditLogs()
};

return View(model);
}

[HttpPost]
public ActionResult Index(string delete)
{
if (!_configurationService.Enabled() || !_configurationService.CanUserDeleteAuditLogs())
{
return new ObjectResult("Unauthorized")
{
StatusCode = (int?)HttpStatusCode.Unauthorized
};
}

_sqlStudioDdsRepository.DeleteAll();
return RedirectToAction("Index");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ private List<SelectListItem> GetConnectionStringList(DataAccessOptions dataAcces
{
if (!string.IsNullOrEmpty(configuration.ConnectionString))
{
return new List<SelectListItem>
{
return
[
new SelectListItem
{
Text = "Default",
Value = configuration.ConnectionString
}
};
];
}
else
{
Expand All @@ -267,7 +267,7 @@ private static string AnonymizeConnectionString(string connectionString)
try
{
var connection = new SqlConnectionStringBuilder(connectionString);
output = connection.UserID + " @ " + connection.InitialCatalog;
output = connection.UserID + "@" + connection.InitialCatalog;
}
catch
{
Expand Down
10 changes: 5 additions & 5 deletions src/Gulla.Episerver.SqlStudio/Gulla.Episerver.SqlStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>2.10.0</Version>
<PackageVersion>2.10.0</PackageVersion>
<AssemblyVersion>2.10.0</AssemblyVersion>
<FileVersion>2.10.0</FileVersion>
<Version>2.11.0</Version>
<PackageVersion>2.11.0</PackageVersion>
<AssemblyVersion>2.11.0</AssemblyVersion>
<FileVersion>2.11.0</FileVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PackageId>Gulla.Episerver.SqlStudio</PackageId>
Expand All @@ -21,7 +21,7 @@
<RepositoryUrl>https://github.com/tomahg/Gulla.Episerver.SqlStudio/</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>Update to .NET8</PackageReleaseNotes>
<PackageReleaseNotes>Refactor audit log deletion</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 3 additions & 9 deletions src/Gulla.Episerver.SqlStudio/Menu/MenuProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public SqlStudioMenuProvider(ConfigurationService configurationService)

public IEnumerable<MenuItem> GetMenuItems()
{
return new MenuItem[]
{
return
[
new UrlMenuItem("SQL", MenuPaths.Global + "/cms/sqlstudio", "/SqlStudio")
{
IsAvailable = context => _configurationService.Enabled()
Expand All @@ -30,17 +30,11 @@ public IEnumerable<MenuItem> GetMenuItems()
IsAvailable = context => _configurationService.Enabled(),
SortIndex = 1
},
new UrlMenuItem("Audit log", MenuPaths.Global + "/cms/sqlstudio/auditlog", "/SqlStudio/AuditLog")
new UrlMenuItem("Audit Log", MenuPaths.Global + "/cms/sqlstudio/auditlog", "/SqlStudio/AuditLog")
{
IsAvailable = context => _configurationService.Enabled() && _configurationService.IsAuditLogEnabled(),
SortIndex = 2
},
new UrlMenuItem("Admin", MenuPaths.Global + "/cms/sqlstudio/admin", "/SqlStudio/Admin")
{
IsAvailable = context => _configurationService.Enabled() && _configurationService.CanUserDeleteAuditLogs(),
SortIndex = 3
},
};
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/Gulla.Episerver.SqlStudio/ViewModels/AdminViewModel.cs

This file was deleted.

2 changes: 2 additions & 0 deletions src/Gulla.Episerver.SqlStudio/ViewModels/AuditLogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public class AuditLogViewModel
{
public IEnumerable<SqlStudioDdsLogItem> Logs { get; set; }
public bool HasResults => Logs?.Any() == true;
public bool ShowDeleteButton { get; set; }
public int LogsCount { get; set; }
}
}
41 changes: 0 additions & 41 deletions src/Gulla.Episerver.SqlStudio/Views/Admin/Index.cshtml

This file was deleted.

14 changes: 13 additions & 1 deletion src/Gulla.Episerver.SqlStudio/Views/AuditLog/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<html>
<head>
<title>SqlStudio Log</title>
<title>SqlStudio Audit Log</title>

<style>
body {
Expand Down Expand Up @@ -64,6 +64,18 @@
</div>
}
</div>
@if (Model.HasResults && Model.ShowDeleteButton)
{
<hr />
<div class="inputcontainer" style="margin-left: 30px; margin-bottom: 20px; margin-top: 20px">
<h4 style="margin-bottom: 5px">Danger Zone</h4>
<p>Number of logs in DDS: @Model.LogsCount</p>
@using (Html.BeginForm())
{
<input type="submit" id="btnDelete" name="Delete" value="Delete all logs" class="epi-cmsButton-text epi-cmsButton-tools epi-cmsButton-Delete" style="color: #d1242f; font-weight: bold;" />
}
</div>
}
</div>
</div>

Expand Down

0 comments on commit 7c7e4e5

Please sign in to comment.