Skip to content

Commit

Permalink
Company Communicator v4.1.2 (#445)
Browse files Browse the repository at this point in the history
* handling null case for user type.

* adding fallback incase userType is null

* handling user type null and adding existing guest user count to messages

* adding UTs

* Fix warnings

* moving to extension

* localized strings

* adding comment for usage of GetUserType

* handle 502 status code from graph.

* handle 502 bad gateway graph response

Co-authored-by: Priyank Saxena <priyank.saxena@microsoft.com>
  • Loading branch information
priyank29 and Priyank Saxena authored Jun 25, 2021
1 parent 3869bdc commit 207013d
Show file tree
Hide file tree
Showing 38 changed files with 552 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Extensions
{
using System;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Services.MessageQueues.SendQueue;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Services.MicrosoftGraph;

/// <summary>
/// Extension class for <see cref="SendQueueMessageContent"/>.
Expand Down Expand Up @@ -44,5 +45,28 @@ public static string GetConversationId(this SendQueueMessageContent message)
_ => throw new ArgumentException("Invalid recipient type"),
};
}

/// <summary>
/// Check if recipient guest user.
/// </summary>
/// <param name="message">Send Queue message.</param>
/// <returns>Boolean indicating if it is a guest user.</returns>
public static bool IsRecipientGuestUser(this SendQueueMessageContent message)
{
var recipient = message.RecipientData;
if (recipient.RecipientType == RecipientDataType.User)
{
if (string.IsNullOrEmpty(recipient.UserData.UserType))
{
throw new ArgumentNullException(nameof(recipient.UserData.UserType));
}
else if (recipient.UserData.UserType.Equals(UserType.Guest, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}

return false;
}
}
}
23 changes: 22 additions & 1 deletion Source/CompanyCommunicator.Common/Extensions/UserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Extensions
{
using System;
using System.Collections.Generic;
using Microsoft.Graph;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Repositories.UserData;
using Microsoft.Teams.Apps.CompanyCommunicator.Common.Services.MicrosoftGraph;

Expand Down Expand Up @@ -45,7 +46,7 @@ public static IEnumerable<IEnumerable<string>> AsGroups(this IList<string> userI
}

/// <summary>
/// Get the user type for a user.
/// Get the userType for a user.
/// </summary>
/// <param name="userPrincipalName">the user principal name.</param>
/// <returns>the user type such as Member or Guest.</returns>
Expand All @@ -58,5 +59,25 @@ public static string GetUserType(this string userPrincipalName)

return userPrincipalName.ToLower().Contains("#ext#") ? UserType.Guest : UserType.Member;
}

/// <summary>
/// Get the userType for a user.
/// </summary>
/// <param name="user">the microsoft graph user.</param>
/// <returns>the user type such as Member or Guest.</returns>
public static string GetUserType(this User user)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}

if (!string.IsNullOrEmpty(user.UserType))
{
return user.UserType;
}

return user.UserPrincipalName.GetUserType();
}
}
}
37 changes: 37 additions & 0 deletions Source/CompanyCommunicator.Common/Policies/PollyPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// <copyright file="PollyPolicy.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// </copyright>

namespace Microsoft.Teams.Apps.CompanyCommunicator.Common.Policies
{
using System;
using System.Net;
using Microsoft.Graph;
using Polly;
using Polly.Contrib.WaitAndRetry;
using Polly.Retry;

/// <summary>
/// Polly policies.
/// </summary>
public class PollyPolicy
{
/// <summary>
/// Get the graph retry policy.
/// </summary>
/// <param name="maxAttempts">the number of max attempts.</param>
/// <returns>A retry policy that can be applied to async delegates.</returns>
public static AsyncRetryPolicy GetGraphRetryPolicy(int maxAttempts)
{
var delay = Backoff.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromSeconds(1), retryCount: maxAttempts);

// Only Handling 502 Bad Gateway Exception
// Other exception such as 429, 503, 504 is handled by default by Graph SDK.
return Policy
.Handle<ServiceException>(e =>
e.StatusCode == HttpStatusCode.BadGateway)
.WaitAndRetryAsync(delay);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public class SentNotificationDataEntity : TableEntity
/// </summary>
public static readonly int FinalFaultedStatusCode = -2;

/// <summary>
/// This value indicates that operation is not supported by Azure Function and will
/// not be processed further.
/// </summary>
public static readonly int NotSupportedStatusCode = -3;

/// <summary>
/// String indicating the recipient type for the given notification was a user.
/// </summary>
Expand Down Expand Up @@ -169,6 +175,11 @@ public class SentNotificationDataEntity : TableEntity
/// </summary>
public string TenantId { get; set; }

/// <summary>
/// Gets or sets the user type for the recipient.
/// </summary>
public string UserType { get; set; }

/// <summary>
/// Gets or sets the user id for the recipient.
/// </summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,15 @@
<value>مقيّد</value>
</data>
<data name="ColumnName_UserType" xml:space="preserve">
<value>User Type</value>
<value>نوع المستخدم</value>
</data>
<data name="Guest" xml:space="preserve">
<value>Guest</value>
<value>الضيف</value>
</data>
<data name="Member" xml:space="preserve">
<value>Member</value>
<value>العضو</value>
</data>
<data name="GuestUserNotSupported" xml:space="preserve">
<value>المستخدم الضيف غير مدعم</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<value>{0} (kopieren)</value>
</data>
<data name="ExportFailureText" xml:space="preserve">
<value>Da hat etwas nicht geklappt. Versuchen Sie noch Mal, die Ergebnisse zu exportieren.</value>
<value>Etwas ist schief gegangen. Versuchen Sie noch Mal, die Ergebnisse zu exportieren.</value>
</data>
<data name="Failed" xml:space="preserve">
<value>Fehlgeschlagen</value>
Expand Down Expand Up @@ -221,7 +221,7 @@
<value>Ihre Datei kann jetzt herunter geladen werden. Eine Kopie ist auch auf OneDrive verfügbar.</value>
</data>
<data name="FileUploadErrorText" xml:space="preserve">
<value>Da hat etwas nicht geklappt. Versuchen Sie noch Mal, die Ergebnisse zu exportieren.</value>
<value>Etwas ist schief gegangen. Versuchen Sie noch Mal, die Ergebnisse zu exportieren.</value>
</data>
<data name="NumberOfGroupsExceededLimitWarningFormat" xml:space="preserve">
<value>Die Benachrichtigung hat {0} Gruppen als Ihre Empfänger. Sie sollte {1} Gruppen nicht über schreiten.</value>
Expand Down Expand Up @@ -256,4 +256,7 @@
<data name="Member" xml:space="preserve">
<value>Mitglied</value>
</data>
<data name="GuestUserNotSupported" xml:space="preserve">
<value>Gastbenutzer nicht unterstützt</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,15 @@
<value>Limitado</value>
</data>
<data name="ColumnName_UserType" xml:space="preserve">
<value>User Type</value>
<value>Tipo de usuario</value>
</data>
<data name="Guest" xml:space="preserve">
<value>Guest</value>
<value>Invitado</value>
</data>
<data name="Member" xml:space="preserve">
<value>Member</value>
<value>Miembro</value>
</data>
<data name="GuestUserNotSupported" xml:space="preserve">
<value>No se admite el usuario invitado</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,7 @@
<data name="Member" xml:space="preserve">
<value>Membre</value>
</data>
<data name="GuestUserNotSupported" xml:space="preserve">
<value>Utilisateur invité non pris en charge</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,7 @@
<data name="Member" xml:space="preserve">
<value>חבר</value>
</data>
<data name="GuestUserNotSupported" xml:space="preserve">
<value>משתמש אורח אינו נתמך</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,7 @@
<data name="Member" xml:space="preserve">
<value>メンバー</value>
</data>
<data name="GuestUserNotSupported" xml:space="preserve">
<value>ゲスト ユーザーはサポートされていません</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,7 @@
<data name="Member" xml:space="preserve">
<value>구성원</value>
</data>
<data name="GuestUserNotSupported" xml:space="preserve">
<value>게스트 사용자가 지원되지 않음</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,15 @@
<value>Limitado</value>
</data>
<data name="ColumnName_UserType" xml:space="preserve">
<value>User Type</value>
<value>Tipo de Usuário</value>
</data>
<data name="Guest" xml:space="preserve">
<value>Guest</value>
<value>Convidado</value>
</data>
<data name="Member" xml:space="preserve">
<value>Member</value>
<value>Membro</value>
</data>
<data name="GuestUserNotSupported" xml:space="preserve">
<value>Não há suporte para o Usuário Convidado</value>
</data>
</root>
Loading

0 comments on commit 207013d

Please sign in to comment.