Skip to content

Commit

Permalink
Merge pull request #22 from IliyanIlievPH/21
Browse files Browse the repository at this point in the history
Closes #21
  • Loading branch information
starkmsu committed Jun 11, 2020
2 parents 8fc3217 + d417a35 commit 4f1a6f0
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 14 deletions.
7 changes: 7 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ AdminManagementService:
settings-key: AdminManagementService-PasswordResetEmail-EmailTemplateId
SubjectTemplateId:
settings-key: AdminManagementService-PasswordResetEmail-SubjectTemplateId
PartnerAdminWelcomeEmail:
EmailTemplateId:
settings-key: AdminManagementService-PartnerAdminWelcomeEmail-EmailTemplateId
SubjectTemplateId:
settings-key: AdminManagementService-PartnerAdminWelcomeEmail-SubjectTemplateId
VerificationLinkPath:
settings-key: AdminManagementService-PartnerAdminWelcomeEmail-VerificationLinkPath

SessionsService:
ServiceUrl:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace MAVN.Service.AdminManagement.Domain.Services
public interface INotificationsService
{
Task NotifyAdminCreatedAsync(AdminCreatedEmailDto model);
Task NotifyPartnerAdminWelcomeAsync(AdminCreatedEmailDto model);
Task NotifyAdminPasswordResetAsync(string adminUserId, string email, string login, string password, string name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace MAVN.Service.AdminManagement.DomainServices
{
public class AdminUserService : IAdminUserService
{
private const string PartnerPermissionsName = "ProgramPartners";

private readonly IAdminUsersRepository _adminUsersRepository;
private readonly INotificationsService _notificationsService;
private readonly ICredentialsClient _credentialsClient;
Expand Down Expand Up @@ -271,15 +273,7 @@ public async Task<RegistrationResultModel> RegisterAsync(RegistrationRequestDto

#endregion

await _notificationsService.NotifyAdminCreatedAsync(new AdminCreatedEmailDto
{
AdminUserId = adminId,
Email = model.Email,
EmailVerificationCode = emailVerificationCode.ToBase64(),
Password = model.Password,
Name = $"{model.FirstName} {model.LastName}",
Localization = model.Localization
});
await SendNotification(model, adminId, emailVerificationCode, model.Permissions);

_log.Info(message: "Successfully generated AdminCreatedEmail", context: adminId);

Expand Down Expand Up @@ -384,6 +378,27 @@ public async Task<List<Permission>> GetPermissionsAsync(string adminId)
return permissions;
}

private async Task SendNotification(RegistrationRequestDto model, string adminId, string emailVerificationCode, IReadOnlyList<Permission> permissions)
{
var adminCreatedDto = new AdminCreatedEmailDto
{
AdminUserId = adminId,
Email = model.Email,
EmailVerificationCode = emailVerificationCode.ToBase64(),
Password = model.Password,
Name = $"{model.FirstName} {model.LastName}",
Localization = model.Localization
};

var partnersPermissions = permissions.FirstOrDefault(x => x.Type == PartnerPermissionsName);

//check if it is program partner
if (partnersPermissions != null && partnersPermissions.Level == PermissionLevel.PartnerEdit)
await _notificationsService.NotifyPartnerAdminWelcomeAsync(adminCreatedDto);
else
await _notificationsService.NotifyAdminCreatedAsync(adminCreatedDto);
}

private async Task<IReadOnlyList<AdminUser>> LoadSensitiveDataAsync(
IReadOnlyList<AdminUserEncrypted> adminUsersEncrypted)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class NotificationsService : INotificationsService
private readonly string _adminCreatedVerificationLinkPath;
private readonly string _adminPasswordResetEmailTemplateId;
private readonly string _adminPasswordResetEmailSubjectTemplateId;
private readonly string _partnerAdminWelcomeEmailTemplateId;
private readonly string _partnerAdminWelcomeEmailSubjectTemplateId;
private readonly string _partnerAdminCreatedVerificationLinkPath;

public NotificationsService(
IRabbitPublisher<EmailMessageEvent> emailsPublisher,
Expand All @@ -26,7 +29,10 @@ public class NotificationsService : INotificationsService
string adminCreatedEmailSubjectTemplateId,
string adminCreatedVerificationLinkPath,
string adminPasswordResetEmailTemplateId,
string adminPasswordResetEmailSubjectTemplateId)
string adminPasswordResetEmailSubjectTemplateId,
string partnerAdminWelcomeEmailTemplateId,
string partnerAdminWelcomeEmailSubjectTemplateId,
string partnerAdminCreatedVerificationLinkPath)
{
_emailsPublisher = emailsPublisher;
_backOfficeUrl = backOfficeUrl;
Expand All @@ -35,6 +41,9 @@ public class NotificationsService : INotificationsService
_adminCreatedVerificationLinkPath = adminCreatedVerificationLinkPath;
_adminPasswordResetEmailTemplateId = adminPasswordResetEmailTemplateId;
_adminPasswordResetEmailSubjectTemplateId = adminPasswordResetEmailSubjectTemplateId;
_partnerAdminWelcomeEmailTemplateId = partnerAdminWelcomeEmailTemplateId;
_partnerAdminWelcomeEmailSubjectTemplateId = partnerAdminWelcomeEmailSubjectTemplateId;
_partnerAdminCreatedVerificationLinkPath = partnerAdminCreatedVerificationLinkPath;
}

public async Task NotifyAdminCreatedAsync(AdminCreatedEmailDto model)
Expand All @@ -55,6 +64,24 @@ public async Task NotifyAdminCreatedAsync(AdminCreatedEmailDto model)
_adminCreatedEmailSubjectTemplateId);
}

public async Task NotifyPartnerAdminWelcomeAsync(AdminCreatedEmailDto model)
{
var url = GetLocalizedPath(_backOfficeUrl, model.Localization);

var values = new Dictionary<string, string>
{
{nameof(model.Name), model.Name},
{"BackOfficeUrl", url},
{"PartnersUrl", url + _partnerAdminCreatedVerificationLinkPath.TrimStart('/').Replace("{0}", model.EmailVerificationCode)},
{"Login", model.Email},
{nameof(model.Password), model.Password},
{nameof(model.Localization), model.Localization.ToString()}
};

await SendEmailAsync(model.AdminUserId, model.Email, values, _partnerAdminWelcomeEmailTemplateId,
_partnerAdminWelcomeEmailSubjectTemplateId);
}

public async Task NotifyAdminPasswordResetAsync(string adminUserId, string email, string login, string password, string name)
{
var values = new Dictionary<string, string>
Expand Down
3 changes: 3 additions & 0 deletions src/MAVN.Service.AdminManagement/Modules/ServiceModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ protected override void Load(ContainerBuilder builder)
.WithParameter("adminCreatedVerificationLinkPath", _appSettings.CurrentValue.AdminManagementService.AdminCreatedEmail.VerificationLinkPath)
.WithParameter("adminPasswordResetEmailTemplateId", _appSettings.CurrentValue.AdminManagementService.PasswordResetEmail.EmailTemplateId)
.WithParameter("adminPasswordResetEmailSubjectTemplateId", _appSettings.CurrentValue.AdminManagementService.PasswordResetEmail.SubjectTemplateId)
.WithParameter("partnerAdminWelcomeEmailTemplateId", _appSettings.CurrentValue.AdminManagementService.PartnerAdminWelcomeEmail.EmailTemplateId)
.WithParameter("partnerAdminWelcomeEmailSubjectTemplateId", _appSettings.CurrentValue.AdminManagementService.PartnerAdminWelcomeEmail.SubjectTemplateId)
.WithParameter("partnerAdminCreatedVerificationLinkPath", _appSettings.CurrentValue.AdminManagementService.PartnerAdminWelcomeEmail.VerificationLinkPath)
.SingleInstance();

builder.RegisterType<StartupManager>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using JetBrains.Annotations;
using Lykke.SettingsReader.Attributes;

namespace MAVN.Service.AdminManagement.Settings
{
Expand All @@ -9,11 +8,9 @@ public class AdminManagementSettings
public DbSettings Db { get; set; }
public string BackOfficeLink { set; get; }
public AdminCreatedEmail AdminCreatedEmail { set; get; }

public PartnerAdminWelcomeEmail PartnerAdminWelcomeEmail { set; get; }
public PasswordResetEmail PasswordResetEmail { set; get; }

public RabbitMqSettings RabbitMq { get; set; }

public RedisSettings Redis { set; get; }
public LimitationSettings LimitationSettings { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MAVN.Service.AdminManagement.Settings
{
public class PartnerAdminWelcomeEmail
{
public string EmailTemplateId { set; get; }
public string SubjectTemplateId { set; get; }
public string VerificationLinkPath { set; get; }
}
}

0 comments on commit 4f1a6f0

Please sign in to comment.