Skip to content

Commit

Permalink
APIView changes to send emails using logic app service (#5408)
Browse files Browse the repository at this point in the history
* APIView changes to send emails using logic app service
  • Loading branch information
praveenkuttappan authored Feb 16, 2023
1 parent 11661e3 commit 36fcb58
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
10 changes: 1 addition & 9 deletions src/dotnet/APIView/APIViewIntegrationTests/TestsBaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
using Microsoft.AspNetCore.Authorization;
using Moq;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using System.Security.Claims;
using SendGrid;
using SendGrid.Helpers.Mail;
using System.Threading;
using Azure.Storage.Blobs.Models;
using APIView.Identity;
using APIViewWeb.Managers;
Expand Down Expand Up @@ -83,11 +79,7 @@ public TestsBaseFixture()
authorizationServiceMoq.Setup(_ => _.AuthorizeAsync(It.IsAny<ClaimsPrincipal>(), It.IsAny<Object>(), It.IsAny<IEnumerable<IAuthorizationRequirement>>()))
.ReturnsAsync(AuthorizationResult.Success);

var sendGridClientMock = new Mock<ISendGridClient>();
sendGridClientMock.Setup(_ => _.SendEmailAsync(It.IsAny<SendGridMessage>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new Response(HttpStatusCode.OK, null, null));

var notificationManager = new NotificationManager(config, cosmosReviewRepository, cosmosUserProfileRepository, sendGridClientMock.Object);
var notificationManager = new NotificationManager(config, cosmosReviewRepository, cosmosUserProfileRepository);

var devopsArtifactRepositoryMoq = new Mock<IDevopsArtifactRepository>();
devopsArtifactRepositoryMoq.Setup(_ => _.DownloadPackageArtifact(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet/APIView/APIViewUnitTests/APIViewUnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -18,7 +18,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.26.1" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Moq" Version="4.18.1" />
Expand Down
6 changes: 2 additions & 4 deletions src/dotnet/APIView/APIViewWeb/APIViewWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<PackageReference Include="ColorCode.Portable" Version="1.0.3">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.12.0-beta4" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.2.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.26.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.0" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.170.0" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.7.2">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -50,8 +50,6 @@
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.9" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
<PackageReference Include="Octokit" Version="3.0.0" />
<PackageReference Include="Sendgrid" Version="9.28.1" />
<PackageReference Include="SendGrid.Extensions.DependencyInjection" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public async Task<ActionResult> Add(string reviewId, string revisionId, string e
foreach(string user in taggedUsers)
{
comment.TaggedUsers.Add(user);
await _notificationManager.NotifyUserOnCommentTag(user, comment);
}

await _commentsManager.AddCommentAsync(User, comment);
Expand Down
10 changes: 5 additions & 5 deletions src/dotnet/APIView/APIViewWeb/Managers/CommentsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json;
using Microsoft.Extensions.Options;
using Microsoft.TeamFoundation.Common;

namespace APIViewWeb.Managers
{
Expand Down Expand Up @@ -91,6 +92,7 @@ public async Task AddCommentAsync(ClaimsPrincipal user, CommentModel comment)
await _commentsRepository.UpsertCommentAsync(comment);
if (!comment.IsResolve)
{
await _notificationManager.NotifyUserOnCommentTag(comment);
await _notificationManager.NotifySubscribersOnComment(user, comment);
}
}
Expand All @@ -103,18 +105,16 @@ public async Task<CommentModel> UpdateCommentAsync(ClaimsPrincipal user, string
comment.Comment = commentText;
comment.Username = user.GetGitHubLogin();

var newTaggedUsers = new HashSet<string>();
foreach (var taggedUser in taggedUsers)
{
if (!comment.TaggedUsers.Contains(taggedUser))
if (!string.IsNullOrEmpty(taggedUser))
{
await _notificationManager.NotifyUserOnCommentTag(taggedUser, comment);
comment.TaggedUsers.Add(taggedUser);
}
newTaggedUsers.Add(taggedUser);
}
comment.TaggedUsers = newTaggedUsers;

await _commentsRepository.UpsertCommentAsync(comment);
await _notificationManager.NotifyUserOnCommentTag(comment);
await _notificationManager.NotifySubscribersOnComment(user, comment);
return comment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace APIViewWeb.Managers
public interface INotificationManager
{
public Task NotifySubscribersOnComment(ClaimsPrincipal user, CommentModel comment);
public Task NotifyUserOnCommentTag(string username, CommentModel comment);
public Task NotifyUserOnCommentTag(CommentModel comment);
public Task NotifyApproversOfReview(ClaimsPrincipal user, string reviewId, HashSet<string> reviewers);
public Task NotifySubscribersOnNewRevisionAsync(ReviewRevisionModel revision, ClaimsPrincipal user);
public Task ToggleSubscribedAsync(ClaimsPrincipal user, string reviewId);
Expand Down
Loading

0 comments on commit 36fcb58

Please sign in to comment.