Gets send to publish emails working for variants
This commit is contained in:
@@ -467,8 +467,10 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
base.ResetDirtyProperties(rememberDirty);
|
||||
|
||||
Template.ResetDirtyProperties(rememberDirty);
|
||||
ContentType.ResetDirtyProperties(rememberDirty);
|
||||
if (Template != null)
|
||||
Template.ResetDirtyProperties(rememberDirty);
|
||||
if (ContentType != null)
|
||||
ContentType.ResetDirtyProperties(rememberDirty);
|
||||
|
||||
// take care of the published state
|
||||
_publishedState = _published ? PublishedState.Published : PublishedState.Unpublished;
|
||||
|
||||
@@ -21,6 +21,10 @@ namespace Umbraco.Core.Models
|
||||
public string ItemName { get; }
|
||||
public string ItemId { get; }
|
||||
public string ItemUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This will either be an HTML or text based summary depending on the email type being sent
|
||||
/// </summary>
|
||||
public string Summary { get; }
|
||||
public string EditedUser { get; }
|
||||
public string SiteUrl { get; }
|
||||
|
||||
@@ -24,12 +24,13 @@ namespace Umbraco.Core.Services.Implement
|
||||
private readonly IScopeProvider _uowProvider;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IContentService _contentService;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly INotificationsRepository _notificationsRepository;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IContentSection _contentSection;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService,
|
||||
public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService,
|
||||
ILogger logger, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, IContentSection contentSection)
|
||||
{
|
||||
_notificationsRepository = notificationsRepository;
|
||||
@@ -38,6 +39,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
_uowProvider = provider ?? throw new ArgumentNullException(nameof(provider));
|
||||
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
|
||||
_contentService = contentService ?? throw new ArgumentNullException(nameof(contentService));
|
||||
_localizationService = localizationService;
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
@@ -279,7 +281,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
/// <param name="siteUri"></param>
|
||||
/// <param name="createSubject">Callback to create the mail subject</param>
|
||||
/// <param name="createBody">Callback to create the mail body</param>
|
||||
private NotificationRequest CreateNotificationRequest(IUser performingUser, IUser mailingUser, IContentBase content, IContentBase oldDoc,
|
||||
private NotificationRequest CreateNotificationRequest(IUser performingUser, IUser mailingUser, IContent content, IContentBase oldDoc,
|
||||
string actionName,
|
||||
Uri siteUri,
|
||||
Func<(IUser user, NotificationEmailSubjectParams subject), string> createSubject,
|
||||
@@ -294,34 +296,88 @@ namespace Umbraco.Core.Services.Implement
|
||||
|
||||
// build summary
|
||||
var summary = new StringBuilder();
|
||||
var props = content.Properties.ToArray();
|
||||
foreach (var p in props)
|
||||
|
||||
if (content.ContentType.VariesByNothing())
|
||||
{
|
||||
//fixme doesn't take into account variants
|
||||
|
||||
var newText = p.GetValue() != null ? p.GetValue().ToString() : "";
|
||||
var oldText = newText;
|
||||
|
||||
// check if something was changed and display the changes otherwise display the fields
|
||||
if (oldDoc.Properties.Contains(p.PropertyType.Alias))
|
||||
if (!_contentSection.DisableHtmlEmail)
|
||||
{
|
||||
var oldProperty = oldDoc.Properties[p.PropertyType.Alias];
|
||||
oldText = oldProperty.GetValue() != null ? oldProperty.GetValue().ToString() : "";
|
||||
//create the html summary for invariant content
|
||||
|
||||
// replace html with char equivalent
|
||||
ReplaceHtmlSymbols(ref oldText);
|
||||
ReplaceHtmlSymbols(ref newText);
|
||||
//list all of the property values like we used to
|
||||
summary.Append("<table style=\"width: 100 %; \">");
|
||||
foreach (var p in content.Properties)
|
||||
{
|
||||
//fixme doesn't take into account variants
|
||||
|
||||
var newText = p.GetValue() != null ? p.GetValue().ToString() : "";
|
||||
var oldText = newText;
|
||||
|
||||
// check if something was changed and display the changes otherwise display the fields
|
||||
if (oldDoc.Properties.Contains(p.PropertyType.Alias))
|
||||
{
|
||||
var oldProperty = oldDoc.Properties[p.PropertyType.Alias];
|
||||
oldText = oldProperty.GetValue() != null ? oldProperty.GetValue().ToString() : "";
|
||||
|
||||
// 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())
|
||||
{
|
||||
//it's variant, so detect what cultures have changed
|
||||
|
||||
//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>");
|
||||
if (!_contentSection.DisableHtmlEmail)
|
||||
{
|
||||
//Create the html based summary (ul of culture names)
|
||||
|
||||
var culturesChanged = content.CultureInfos.Where(x => x.Value.WasDirty())
|
||||
.Select(x => x.Key)
|
||||
.Select(_localizationService.GetLanguageByIsoCode)
|
||||
.WhereNotNull()
|
||||
.Select(x => x.CultureName);
|
||||
summary.Append("<ul>");
|
||||
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.Where(x => x.Value.WasDirty())
|
||||
.Select(x => x.Key)
|
||||
.Select(_localizationService.GetLanguageByIsoCode)
|
||||
.WhereNotNull()
|
||||
.Select(x => x.CultureName));
|
||||
|
||||
summary.Append("'");
|
||||
summary.Append(culturesChanged);
|
||||
summary.Append("'");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//not supported yet...
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
var protocol = _globalSettings.UseHttps ? "https" : "http";
|
||||
|
||||
@@ -160,10 +160,11 @@ namespace Umbraco.Tests.TestHelpers
|
||||
var runtimeState = Mock.Of<IRuntimeState>();
|
||||
var idkMap = new IdkMap(scopeProvider);
|
||||
|
||||
var localizationService = GetLazyService<ILocalizationService>(container, c => new LocalizationService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDictionaryRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<ILanguageRepository>(c)));
|
||||
var userService = GetLazyService<IUserService>(container, c => new UserService(scopeProvider, logger, eventMessagesFactory, runtimeState, GetRepo<IUserRepository>(c), GetRepo<IUserGroupRepository>(c),globalSettings));
|
||||
var dataTypeService = GetLazyService<IDataTypeService>(container, c => new DataTypeService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDataTypeRepository>(c), GetRepo<IDataTypeContainerRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IEntityRepository>(c), GetRepo<IContentTypeRepository>(c)));
|
||||
var contentService = GetLazyService<IContentService>(container, c => new ContentService(scopeProvider, logger, eventMessagesFactory, mediaFileSystem, GetRepo<IDocumentRepository>(c), GetRepo<IEntityRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IContentTypeRepository>(c), GetRepo<IDocumentBlueprintRepository>(c), GetRepo<ILanguageRepository>(c)));
|
||||
var notificationService = GetLazyService<INotificationService>(container, c => new NotificationService(scopeProvider, userService.Value, contentService.Value, logger, GetRepo<INotificationsRepository>(c), globalSettings, umbracoSettings.Content));
|
||||
var notificationService = GetLazyService<INotificationService>(container, c => new NotificationService(scopeProvider, userService.Value, contentService.Value, localizationService.Value, logger, GetRepo<INotificationsRepository>(c), globalSettings, umbracoSettings.Content));
|
||||
var serverRegistrationService = GetLazyService<IServerRegistrationService>(container, c => new ServerRegistrationService(scopeProvider, logger, eventMessagesFactory, GetRepo<IServerRegistrationRepository>(c)));
|
||||
var memberGroupService = GetLazyService<IMemberGroupService>(container, c => new MemberGroupService(scopeProvider, logger, eventMessagesFactory, GetRepo<IMemberGroupRepository>(c)));
|
||||
var memberService = GetLazyService<IMemberService>(container, c => new MemberService(scopeProvider, logger, eventMessagesFactory, memberGroupService.Value, mediaFileSystem, GetRepo<IMemberRepository>(c), GetRepo<IMemberTypeRepository>(c), GetRepo<IMemberGroupRepository>(c), GetRepo<IAuditRepository>(c)));
|
||||
@@ -171,7 +172,6 @@ namespace Umbraco.Tests.TestHelpers
|
||||
var contentTypeService = GetLazyService<IContentTypeService>(container, c => new ContentTypeService(scopeProvider, logger, eventMessagesFactory, contentService.Value, GetRepo<IContentTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IDocumentTypeContainerRepository>(c), GetRepo<IEntityRepository>(c)));
|
||||
var mediaTypeService = GetLazyService<IMediaTypeService>(container, c => new MediaTypeService(scopeProvider, logger, eventMessagesFactory, mediaService.Value, GetRepo<IMediaTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IMediaTypeContainerRepository>(c), GetRepo<IEntityRepository>(c)));
|
||||
var fileService = GetLazyService<IFileService>(container, c => new FileService(scopeProvider, logger, eventMessagesFactory, GetRepo<IStylesheetRepository>(c), GetRepo<IScriptRepository>(c), GetRepo<ITemplateRepository>(c), GetRepo<IPartialViewRepository>(c), GetRepo<IPartialViewMacroRepository>(c), GetRepo<IAuditRepository>(c)));
|
||||
var localizationService = GetLazyService<ILocalizationService>(container, c => new LocalizationService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDictionaryRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<ILanguageRepository>(c)));
|
||||
|
||||
var memberTypeService = GetLazyService<IMemberTypeService>(container, c => new MemberTypeService(scopeProvider, logger, eventMessagesFactory, memberService.Value, GetRepo<IMemberTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IEntityRepository>(c)));
|
||||
var entityService = GetLazyService<IEntityService>(container, c => new EntityService(
|
||||
|
||||
@@ -943,10 +943,13 @@ To manage your website, simply open the Umbraco back office and start adding con
|
||||
|
||||
Go to http://%4%/#/content/content/edit/%5% to edit.
|
||||
|
||||
%6%
|
||||
|
||||
Have a nice day!
|
||||
|
||||
Cheers from the Umbraco robot
|
||||
]]></key>
|
||||
<key alias="mailBodyVariantSummary">The following languages have been modified %0%</key>
|
||||
<key alias="mailBodyHtml"><![CDATA[
|
||||
<html>
|
||||
<head>
|
||||
@@ -1002,9 +1005,7 @@ To manage your website, simply open the Umbraco back office and start adding con
|
||||
</table>
|
||||
<p style='color: #392F54; font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0 0 15px;'>
|
||||
<h3>Update summary:</h3>
|
||||
<table style="width: 100%;">
|
||||
%6%
|
||||
</table>
|
||||
%6%
|
||||
</p>
|
||||
<p style='color: #392F54; font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0 0 15px;'>
|
||||
Have a nice day!<br /><br />
|
||||
@@ -1025,6 +1026,9 @@ To manage your website, simply open the Umbraco back office and start adding con
|
||||
</body>
|
||||
</html>
|
||||
]]></key>
|
||||
<key alias="mailBodyVariantHtmlSummary"><![CDATA[<p>The following languages have been modified:</p>
|
||||
%0%
|
||||
]]></key>
|
||||
<key alias="mailSubject">[%0%] Notification about %1% performed on %2%</key>
|
||||
<key alias="notifications">Notifications</key>
|
||||
</area>
|
||||
|
||||
@@ -963,10 +963,13 @@ To manage your website, simply open the Umbraco back office and start adding con
|
||||
|
||||
Go to http://%4%/#/content/content/edit/%5% to edit.
|
||||
|
||||
%6%
|
||||
|
||||
Have a nice day!
|
||||
|
||||
Cheers from the Umbraco robot
|
||||
]]></key>
|
||||
<key alias="mailBodyVariantSummary">The following languages have been modified %0%</key>
|
||||
<key alias="mailBodyHtml"><![CDATA[
|
||||
<html>
|
||||
<head>
|
||||
@@ -1022,9 +1025,7 @@ To manage your website, simply open the Umbraco back office and start adding con
|
||||
</table>
|
||||
<p style='color: #392F54; font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0 0 15px;'>
|
||||
<h3>Update summary:</h3>
|
||||
<table style="width: 100%;">
|
||||
%6%
|
||||
</table>
|
||||
%6%
|
||||
</p>
|
||||
<p style='color: #392F54; font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0 0 15px;'>
|
||||
Have a nice day!<br /><br />
|
||||
@@ -1045,6 +1046,9 @@ To manage your website, simply open the Umbraco back office and start adding con
|
||||
</body>
|
||||
</html>
|
||||
]]></key>
|
||||
<key alias="mailBodyVariantHtmlSummary"><![CDATA[<p>The following languages have been modified:</p>
|
||||
%0%
|
||||
]]></key>
|
||||
<key alias="mailSubject">[%0%] Notification about %1% performed on %2%</key>
|
||||
<key alias="notifications">Notifications</key>
|
||||
</area>
|
||||
|
||||
@@ -150,22 +150,42 @@ namespace Umbraco.Web.Components
|
||||
if (sender == null) throw new ArgumentNullException(nameof(sender));
|
||||
if (siteUri == null) throw new ArgumentNullException(nameof(siteUri));
|
||||
|
||||
_notificationService.SendNotifications(
|
||||
sender,
|
||||
entities,
|
||||
action.Letter.ToString(CultureInfo.InvariantCulture),
|
||||
_textService.Localize("actions", action.Alias),
|
||||
siteUri,
|
||||
((IUser user, NotificationEmailSubjectParams subject) x)
|
||||
=> _textService.Localize(
|
||||
"notifications/mailSubject",
|
||||
x.user.GetUserCulture(_textService, _globalSettings),
|
||||
new[] { x.subject.SiteUrl, x.subject.Action, x.subject.ItemName }),
|
||||
((IUser user, NotificationEmailBodyParams body, bool isHtml) x)
|
||||
=> _textService.Localize(
|
||||
x.isHtml ? "notifications/mailBodyHtml" : "notifications/mailBody",
|
||||
x.user.GetUserCulture(_textService, _globalSettings),
|
||||
new[] { x.body.RecipientName, x.body.Action, x.body.ItemName, x.body.EditedUser, x.body.SiteUrl, x.body.ItemId, x.body.Summary, x.body.ItemUrl }));
|
||||
//group by the content type variation since the emails will be different
|
||||
foreach(var contentVariantGroup in entities.GroupBy(x => x.ContentType.Variations))
|
||||
{
|
||||
if (contentVariantGroup.Key == ContentVariation.CultureAndSegment || contentVariantGroup.Key == ContentVariation.Segment)
|
||||
throw new NotSupportedException("Segments are not yet supported in Umbraco");
|
||||
|
||||
_notificationService.SendNotifications(
|
||||
sender,
|
||||
contentVariantGroup,
|
||||
action.Letter.ToString(CultureInfo.InvariantCulture),
|
||||
_textService.Localize("actions", action.Alias),
|
||||
siteUri,
|
||||
((IUser user, NotificationEmailSubjectParams subject) x)
|
||||
=> _textService.Localize(
|
||||
"notifications/mailSubject",
|
||||
x.user.GetUserCulture(_textService, _globalSettings),
|
||||
new[] { x.subject.SiteUrl, x.subject.Action, x.subject.ItemName }),
|
||||
((IUser user, NotificationEmailBodyParams body, bool isHtml) x)
|
||||
=> _textService.Localize(
|
||||
x.isHtml ? "notifications/mailBodyHtml" : "notifications/mailBody",
|
||||
x.user.GetUserCulture(_textService, _globalSettings),
|
||||
new[]
|
||||
{
|
||||
x.body.RecipientName,
|
||||
x.body.Action,
|
||||
x.body.ItemName,
|
||||
x.body.EditedUser,
|
||||
x.body.SiteUrl,
|
||||
x.body.ItemId,
|
||||
//format the summary depending on if it's variant or not
|
||||
contentVariantGroup.Key == ContentVariation.Culture
|
||||
? (x.isHtml ? _textService.Localize("notifications/mailBodyVariantHtmlSummary", new[]{ x.body.Summary }) : _textService.Localize("notifications/mailBodyVariantSummary", new []{ x.body.Summary }))
|
||||
: x.body.Summary,
|
||||
x.body.ItemUrl
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user