Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 38 additions & 44 deletions src/Umbraco.Core/Services/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,88 +385,82 @@
// build summary
var summary = new StringBuilder();

if (content.ContentType.VariesByNothing())
{
if (!_contentSettings.Notifications.DisableHtmlEmail)
{
// create the HTML summary for invariant content

// list all of the property values like we used to
summary.Append("<table style=\"width: 100 %; \">");
foreach (IProperty p in content.Properties)
{
// TODO: doesn't take into account variants
var newText = p.GetValue() != null ? p.GetValue()?.ToString() : string.Empty;
var oldText = newText;

// check if something was changed and display the changes otherwise display the fields
if (oldDoc?.Properties.Contains(p.PropertyType.Alias) ?? false)
{
IProperty? oldProperty = oldDoc.Properties[p.PropertyType.Alias];
oldText = oldProperty?.GetValue() != null ? oldProperty.GetValue()?.ToString() : string.Empty;

// replace HTML with char equivalent
ReplaceHtmlSymbols(ref oldText);
ReplaceHtmlSymbols(ref newText);
}

// show the values
summary.Append("<tr>");
summary.Append(
"<th style='text-align: left; vertical-align: top; width: 25%;border-bottom: 1px solid #CCC'>");
summary.Append(p.PropertyType.Name);
summary.Append("</th>");
summary.Append("<td style='text-align: left; vertical-align: top;border-bottom: 1px solid #CCC'>");
summary.Append(newText);
summary.Append("</td>");
summary.Append("</tr>");
}

summary.Append("</table>");
}
}
else if (content.ContentType.VariesByCulture())
{
if (content.ContentType.VariesByCulture()) {
// it's variant, so detect what cultures have changed
if (!_contentSettings.Notifications.DisableHtmlEmail)
{
// Create the HTML based summary (ul of culture names)
IEnumerable<string>? culturesChanged = content.CultureInfos?.Values.Where(x => x.WasDirty())
.Select(x => x.Culture)
.Select(_localizationService.GetLanguageByIsoCode)
.WhereNotNull()
.Select(x => x.CultureName);
summary.Append("<ul>");
if (culturesChanged is not null)
{
foreach (var culture in culturesChanged)
{
summary.Append("<li>");
summary.Append(culture);
summary.Append("</li>");
}
}

summary.Append("</ul>");
}
else
{
// Create the text based summary (csv of culture names)
var culturesChanged = string.Join(", ", content.CultureInfos!.Values.Where(x => x.WasDirty())
.Select(x => x.Culture)
.Select(_localizationService.GetLanguageByIsoCode)
.WhereNotNull()
.Select(x => x.CultureName));

summary.Append("'");
summary.Append(culturesChanged);
summary.Append("'");
}
}
else
{
// not supported yet...
throw new NotSupportedException();
if (!_contentSettings.Notifications.DisableHtmlEmail)
{
// create the HTML summary for invariant content

// list all of the property values like we used to
summary.Append("<table style=\"width: 100 %; \">");
foreach (IProperty p in content.Properties)
{
// TODO: doesn't take into account variants
var newText = p.GetValue() != null ? p.GetValue()?.ToString() : string.Empty;
var oldText = newText;

// check if something was changed and display the changes otherwise display the fields
if (oldDoc?.Properties.Contains(p.PropertyType.Alias) ?? false)
{
IProperty? oldProperty = oldDoc.Properties[p.PropertyType.Alias];
oldText = oldProperty?.GetValue() != null ? oldProperty.GetValue()?.ToString() : string.Empty;

// replace HTML with char equivalent
ReplaceHtmlSymbols(ref oldText);
ReplaceHtmlSymbols(ref newText);
}

// show the values
summary.Append("<tr>");
summary.Append(
"<th style='text-align: left; vertical-align: top; width: 25%;border-bottom: 1px solid #CCC'>");
summary.Append(p.PropertyType.Name);
summary.Append("</th>");
summary.Append("<td style='text-align: left; vertical-align: top;border-bottom: 1px solid #CCC'>");
summary.Append(newText);
summary.Append("</td>");
summary.Append("</tr>");
}

summary.Append("</table>");
}

Check notice on line 463 in src/Umbraco.Core/Services/NotificationService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

✅ Getting better: Complex Method

CreateNotificationRequest decreases in cyclomatic complexity from 23 to 22, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}

var protocol = _globalSettings.UseHttps ? "https" : "http";
Expand Down
Loading