Skip to content
Merged
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
16 changes: 14 additions & 2 deletions api/src/Feature.MonitoringObservers/Add/Endpoint.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Authorization.Policies;
using Feature.MonitoringObservers.Specifications;
using Job.Contracts;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Options;
using Vote.Monitor.Core.Extensions;
using Vote.Monitor.Core.Options;
using Vote.Monitor.Core.Services.EmailTemplating;
using Vote.Monitor.Core.Services.EmailTemplating.Props;
using Vote.Monitor.Domain.Entities.ApplicationUserAggregate;
Expand All @@ -18,9 +21,12 @@ public class Endpoint(
IRepository<ElectionRoundAggregate> repository,
IRepository<MonitoringNgoAggregate> monitoringNgoRepository,
IReadRepository<Observer> observerRepository,
IRepository<MonitoringObserver> monitoringObserverRepository)
IRepository<MonitoringObserver> monitoringObserverRepository,
IOptions<ApiConfiguration> options)
: Endpoint<Request, Results<Ok<Response>, NotFound<string>, Conflict<ProblemDetails>, ValidationProblem>>
{

private readonly ApiConfiguration _apiConfiguration = options.Value;
public override void Configure()
{
Post("/api/election-rounds/{electionRoundId}/monitoring-ngos/{monitoringNgoId}/monitoring-observers");
Expand Down Expand Up @@ -83,8 +89,14 @@ public override async Task<Results<Ok<Response>, NotFound<string>, Conflict<Prob

await monitoringObserverRepository.AddAsync(monitoringObserver, ct);

var invitationExistingUserEmailProps = new InvitationExistingUserEmailProps(
FullName: observer.ApplicationUser.FirstName + " " + observer.ApplicationUser.LastName,
CdnUrl: _apiConfiguration.WebAppUrl,
NgoName: monitoringNgo.Ngo.Name,
ElectionRoundDetails: electionRound.Title);

var email = emailFactory.GenerateEmail(EmailTemplateType.InvitationExistingUser,
new InvitationExistingUserEmailProps("", monitoringNgo.Ngo.Name, electionRound.Title));
invitationExistingUserEmailProps);
jobService.SendEmail(observer.ApplicationUser.Email!, email.Subject, email.Body);

return TypedResults.Ok(new Response
Expand Down
28 changes: 22 additions & 6 deletions api/src/Feature.MonitoringObservers/Import/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ private async Task HandleParsingSucceedAsync(Request req, List<MonitoringObserve

var monitoringNgo = await context
.MonitoringNgos
.Include(x=>x.Ngo)
.Include(x => x.Ngo)
.Where(x => x.NgoId == req.NgoId && x.ElectionRoundId == req.ElectionRoundId)
.FirstAsync(ct);

var ngoName = monitoringNgo.Ngo.Name;

var electionRoundName = await context.ElectionRounds
Expand All @@ -106,6 +106,8 @@ private async Task HandleParsingSucceedAsync(Request req, List<MonitoringObserve

foreach (var observer in observers)
{
var fullName = GetFullName(observer);

var normalizedEmail = observer.Email.ToUpperInvariant();
// Has account in our system
var existingAccount = existingAccounts.FirstOrDefault(x => x.NormalizedEmail == normalizedEmail);
Expand Down Expand Up @@ -145,18 +147,26 @@ private async Task HandleParsingSucceedAsync(Request req, List<MonitoringObserve
var endpointUri = new Uri(Path.Combine($"{_apiConfig.WebAppUrl}", "accept-invite"));
string acceptInviteUrl = QueryHelpers.AddQueryString(endpointUri.ToString(), "invitationToken", existingAccount.InvitationToken!);

var email = emailFactory.GenerateEmail(EmailTemplateType.InvitationNewUser, new InvitationNewUserEmailProps("", acceptInviteUrl, ngoName, electionRoundName));
var invitationNewUserEmailProps = new InvitationNewUserEmailProps(FullName: fullName,
CdnUrl: _apiConfig.WebAppUrl,
AcceptUrl: acceptInviteUrl,
NgoName: ngoName,
ElectionRoundDetails: electionRoundName);
var email = emailFactory.GenerateEmail(EmailTemplateType.InvitationNewUser, invitationNewUserEmailProps);
jobService.SendEmail(observer.Email, email.Subject, email.Body);
}
else
{
var newMonitoringObserver = MonitoringObserverAggregate.CreateForExisting(req.ElectionRoundId,
monitoringNgo.Id, existingObserver.Id,
monitoringNgo.Id,
existingObserver.Id,
observer.Tags);

await context.MonitoringObservers.AddAsync(newMonitoringObserver, ct);
var invitationExistingUserEmailProps = new InvitationExistingUserEmailProps(FullName: fullName, CdnUrl: _apiConfig.WebAppUrl, NgoName: ngoName, ElectionRoundDetails: electionRoundName);

var email = emailFactory.GenerateEmail(EmailTemplateType.InvitationExistingUser,
new InvitationExistingUserEmailProps("", ngoName, electionRoundName));
invitationExistingUserEmailProps);
jobService.SendEmail(observer.Email, email.Subject, email.Body);
}
}
Expand All @@ -177,14 +187,20 @@ private async Task HandleParsingSucceedAsync(Request req, List<MonitoringObserve
var endpointUri = new Uri(Path.Combine($"{_apiConfig.WebAppUrl}", "accept-invite"));
string acceptInviteUrl = QueryHelpers.AddQueryString(endpointUri.ToString(), "invitationToken", user.InvitationToken!);

var email = emailFactory.GenerateEmail(EmailTemplateType.InvitationNewUser, new InvitationNewUserEmailProps("", acceptInviteUrl, ngoName, electionRoundName));
var invitationNewUserEmailProps = new InvitationNewUserEmailProps(FullName: fullName, CdnUrl: _apiConfig.WebAppUrl, AcceptUrl: acceptInviteUrl, NgoName: ngoName, ElectionRoundDetails: electionRoundName);
var email = emailFactory.GenerateEmail(EmailTemplateType.InvitationNewUser, invitationNewUserEmailProps);
jobService.SendEmail(observer.Email, email.Subject, email.Body);
}
}
await context.SaveChangesAsync(ct);
await SendNoContentAsync(ct);
}

private static string GetFullName(MonitoringObserverImportModel observer)
{
return observer.FirstName + " " + observer.LastName;
}

private async Task HandleParsingFailedAsync(string fileName, ParsingResult<MonitoringObserverImportModel>.Fail failedResult, CancellationToken ct)
{
string csv = failedResult.Items.ConstructErrorFileContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override async Task<Results<Ok, ProblemHttpResult>> ExecuteAsync(Request
var endpointUri = new Uri(Path.Combine($"{_apiConfig.WebAppUrl}", "reset-password"));
string passwordResetUrl = QueryHelpers.AddQueryString(endpointUri.ToString(), "token", code);

var emailProps = new ResetPasswordEmailProps(string.Empty, passwordResetUrl);
var emailProps = new ResetPasswordEmailProps(FullName: user.FirstName + " " + user.LastName, CdnUrl: _apiConfig.WebAppUrl, ResetPasswordUrl: passwordResetUrl);
var mail = emailFactory.GenerateEmail(EmailTemplateType.ResetPassword, emailProps);

jobService.SendEmail(request.Email, mail.Subject, mail.Body);
Expand Down
15 changes: 0 additions & 15 deletions api/src/Vote.Monitor.Api/DummyHealth/Endpoint.cs

This file was deleted.

2 changes: 1 addition & 1 deletion api/src/Vote.Monitor.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
});
app.UseResponseCompression();
app.UseSentryMiddleware();
app.MapHealthChecks("/healthz");
app.MapHealthChecks("/health");

app.Run();

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" lang="en"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/></head><div style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0">Confirm your email on VoteMonitor platform.<div> ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏</div></div><body style="background-color:#ffffff;font-family:-apple-system,BlinkMacSystemFont,&quot;Segoe UI&quot;,Roboto,Oxygen-Sans,Ubuntu,Cantarell,&quot;Helvetica Neue&quot;,sans-serif"><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="max-width:37.5em;margin:0 auto;padding:20px 25px 48px;background-image:url(&quot;/assets/raycast-bg.png&quot;);background-position:bottom;background-repeat:no-repeat, no-repeat"><tbody><tr style="width:100%"><td><h1 style="font-size:28px;font-weight:bold;margin-top:48px">Confirm your email on VoteMonitor platform.</h1><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin:24px 0"><tbody><tr><td><p style="font-size:16px;line-height:26px;margin:16px 0">Hello!</p><p style="font-size:16px;line-height:26px;margin:16px 0">This is an automatic email that was sent to confirm your account.</p><p style="font-size:16px;line-height:26px;margin:16px 0">Please follow<a href="~$confirmUrl$~" style="color:#FF6363;text-decoration:none" target="_blank">👉 this link👈</a>to complete your registration in order to use the application.</p></td></tr></tbody></table><p style="font-size:16px;line-height:26px;margin:16px 0">Thank you,<br/>- Vote Monitor Team</p><hr style="width:100%;border:none;border-top:1px solid #eaeaea;border-color:#dddddd;margin-top:48px"/><p style="font-size:12px;line-height:24px;margin:16px 0;color:#8898aa;margin-left:4px">Commit Global.</p></td></tr></tbody></table></body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" lang="en"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/><meta name="x-apple-disable-message-reformatting"/><style>@media(min-width:640px){.sm_my-40px{margin-top:40px!important;margin-bottom:40px!important}.sm_w-64{width:16rem!important}.sm_p-20px{padding:20px!important}.sm_px-10{padding-left:2.5rem!important;padding-right:2.5rem!important}.sm_px-12{padding-left:3rem!important;padding-right:3rem!important}.sm_pb-12{padding-bottom:3rem!important}.sm_pt-14{padding-top:3.5rem!important}}</style></head><div style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0">Confirm your email on VoteMonitor platform<div> ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏</div></div><body style="padding-left:0.5rem;padding-right:0.5rem;margin-left:auto;margin-right:auto;margin-top:auto;margin-bottom:auto;font-family:ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, &quot;Helvetica Neue&quot;, Arial, &quot;Noto Sans&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;;background-color:rgb(255,255,255)"><table align="center" width="100%" class="sm_my-40px sm_p-20px" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="max-width:640px;margin-top:20px;margin-bottom:20px;margin-left:auto;margin-right:auto;padding:10px"><tbody><tr style="width:100%"><td><table align="center" width="100%" class="sm_pb-12 sm_px-10 sm_pt-14" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="display:flex;padding-left:1.5rem;padding-right:1.5rem;padding-top:2rem;padding-bottom:2rem;background-color:rgb(107,33,168)"><tbody><tr><td><img class="sm_w-64" src="~$cdnUrl$~/logo.png" style="display:block;outline:none;border:none;text-decoration:none;width:12rem"/></td></tr></tbody></table><table align="center" width="100%" class="sm_px-12 sm_pt-14" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="padding-left:1.5rem;padding-right:1.5rem;padding-top:2rem;padding-bottom:2rem"><tbody><tr><td><h2>Hello, <!-- -->~$name$~</h2><p style="font-size:1rem;line-height:1.5rem;margin:16px 0">This is an automatic email that was sent to confirm your account. Please follow <a href="~$confirmUrl$~" style="color:#067df7;text-decoration:none" target="_blank">this link</a> to complete your registration and to set your password in order to use the application.</p><p style="font-size:1rem;line-height:1.5rem;margin:16px 0">Thank you.</p><p style="font-size:14px;line-height:24px;margin:16px 0;margin-top:2.5rem;color:rgb(107,114,128)">If you have any questions, reach out to us at <a href="mailto:info@commitglobal.org" style="color:#067df7;text-decoration:none" target="_blank">info@commitglobal.org</a>.</p></td></tr></tbody></table><hr style="width:100%;border:none;border-top:1px solid #eaeaea"/><p style="font-size:0.875rem;line-height:1.25rem;margin:16px 0;color:rgb(107,114,128)">© <!-- -->2024<!-- --> Commit Global. All rights reserved.</p></td></tr></tbody></table></body></html>
Binary file not shown.
Binary file not shown.
Loading