Skip to content

User/omolemo/notifications framework #2479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,51 +1,34 @@
using Abp.Domain.Repositories;
using Shesha.Domain;
using Shesha.Domain.Enums;
using Shesha.DynamicEntities.Dtos;
using Shesha.NotificationMessages.Dto;
using Shesha.Notifications;
using System;
using System.Threading.Tasks;

namespace Shesha.NotificationMessages;

/// <summary>
/// Notifications audit service
/// </summary>
public class NotificationMessageAppService : SheshaCrudServiceBase<NotificationMessage, NotificationMessageDto, Guid>
namespace Shesha.NotificationMessages
{
private readonly IShaNotificationDistributer _distributer;

public NotificationMessageAppService(IRepository<NotificationMessage, Guid> repository, IShaNotificationDistributer distributer) : base(repository)
{
_distributer = distributer;
}

/// <summary>
/// Resend notification message with specified <paramref name="id"/>
/// Notifications audit service
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<bool> Resend(Guid id)
public class NotificationMessageAppService : SheshaCrudServiceBase<NotificationMessage, DynamicDto<NotificationMessage, Guid>, Guid>
{
var notificationMessage = await Repository.GetAsync(id);

var dto = ObjectMapper.Map<NotificationMessageDto>(notificationMessage);
await _distributer.ResendMessageAsync(dto);

return true;
}

public async Task<DynamicDto<NotificationMessage, Guid>> MarkAsReadAsync(Guid id)
{
if (id == Guid.Empty)
throw new ArgumentNullException(nameof(id));
public NotificationMessageAppService(IRepository<NotificationMessage, Guid> repository) : base(repository)
{
}

var entity = await SaveOrUpdateEntityAsync<NotificationMessage>(id, item =>
public async Task<DynamicDto<NotificationMessage, Guid>> MarkAsReadAsync(Guid id)
{
item.Opened = true;
item.LastOpened = DateTime.UtcNow;
});
if (id == Guid.Empty)
throw new ArgumentNullException(nameof(id));

var entity = await SaveOrUpdateEntityAsync(id, (Action<NotificationMessage>)(item =>
{
item.ReadStatus = RefListNotificationReadStatus.Read;
item.FirstDateRead = DateTime.UtcNow;
}));

return await MapToDynamicDtoAsync<NotificationMessage, Guid>(entity);
return await MapToDynamicDtoAsync<NotificationMessage, Guid>(entity);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Shesha.Domain;

namespace Shesha.Notifications.Configuration.Email
{
/// <summary>
/// Email settings
/// </summary>
public class EmailSettings
{
/// <summary>
/// If true, all emails are enabled
/// </summary>
public bool EmailsEnabled { get; set; }

/// <summary>
///
/// </summary>
public NotificationGatewayConfig PreferredGateway { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmailSettings is a settings class and it should be serializable, but NotificationGatewayConfig is an entity, it can't be serialized and saved as a setting. We can save only some kind of unique identifier here.
Please check naming of the property as well. Preferred means that we have some default implementation which are used when a gateway is not specified explicitly.
Most probably the property should be GatewayName, GatewayTypeName or GatewayUid


/// <summary>
/// If not null or empty the all outgoing emails will be sent to this email address, is used for testing only
/// </summary>
public string RedirectAllMessagesTo { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace Shesha.Notifications.Configuration.Email.Gateways
{
/// <summary>
/// SMTP settings
/// </summary>
public class SmtpSettings
{
/// <summary>
/// SMTP Host name/IP.
/// </summary>
public string Host { get; set; }

/// <summary>
/// SMTP Port.
/// </summary>
public int Port { get; set; }

/// <summary>
/// User name to login to SMTP server.
/// </summary>
public string UserName { get; set; }

/// <summary>
/// Password to login to SMTP server.
/// </summary>
public string Password { get; set; }

/// <summary>
/// Domain name to login to SMTP server.
/// </summary>
public string Domain { get; set; }

/// <summary>
/// Domain name to login to Incoming server.
/// </summary>
public string IncomingServer { get; set; }

/// <summary>
/// Is SSL enabled?
/// </summary>
public bool EnableSsl { get; set; }

/// <summary>
/// Default from address.
/// </summary>
public string DefaultFromAddress { get; set; }

/// <summary>
/// Default display name.
/// </summary>
public string DefaultFromDisplayName { get; set; }

/// <summary>
/// Use SMTP relay
/// If true, indicate that SMTP relay service will be used where it's needed (e.g. if the application needs to notify one person about the action that was performed by another person then real person's email address will be used for the 'from' address, otherwise 'Site Email' will be used)
/// </summary>
public bool UseSmtpRelay { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Shesha.Notifications.Configuration.Email.Gateways;
using Shesha.Notifications.Configuration.Sms.Gateways;
using Shesha.Settings;
using Shesha.Sms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shesha.Notifications.Configuration.Email
{
[Category("Email Gateways")]
public interface IEmailGatewaySettings: ISettingAccessors
{
/// <summary>
/// SMS Settings
/// </summary>
[Display(Name = "SMTP Gateway")]
[Setting(NotificationGatewaySettingNames.SmtpGatewaySettings, EditorFormName = "smtp-gateway-settings")]
ISettingAccessor<SmtpSettings> SmtpSettings { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Shesha.Notifications.Configuration.Email;
using Shesha.Notifications.Configuration.Sms;
using Shesha.Settings;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace Shesha.Notifications.Configuration
{
/// <summary>
/// SMS Settings
/// </summary>
[Category("Notifications")]
public interface INotificationSettings : ISettingAccessors
{
/// <summary>
/// SMS Settings
/// </summary>
[Display(Name = "Notifications Channels")]
[Setting(NotificationSettingNames.NotificationSettings, EditorFormName = "notification-settings")]
ISettingAccessor<NotificationSettings> NotificationSettings { get; }

/// <summary>
/// SMS Settings
/// </summary>
[Display(Name = "SMS Settings")]
[Setting(NotificationSettingNames.SmsSettings, EditorFormName = "sms-settings")]
ISettingAccessor<SmsSettings> SmsSettings { get; }

/// <summary>
/// SMTP Settings
/// </summary>
[Display(Name = "Email Settings")]
[Setting(NotificationSettingNames.EmailSettings, EditorFormName = "email-settings")]
ISettingAccessor<EmailSettings> EmailSettings { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shesha.Notifications.Configuration
{
public static class NotificationGatewaySettingNames
{
public const string ClickatellGatewaySettings = "Shesha.Notifications.Sms.Clickatell.Settings";

public const string SmtpGatewaySettings = "Shesha.Notifications.Email.Smtp.Settings";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shesha.Notifications.Configuration
{
public static class NotificationSettingNames
{
public const string NotificationSettings = "Shesha.Notification.Settings";

public const string SmsSettings = "Shesha.Notification.SMS.Settings";

public const string EmailSettings = "Shesha.Notification.Email.Settings";
}
}
Loading