@ -47,7 +47,7 @@ namespace Ombi.Notifications.Agents
return false ;
}
}
if ( string . IsNullOrEmpty ( settings . Host ) | | string . IsNullOrEmpty ( settings . AdminEmail) | | string . IsNullOrEmpty ( settings . Port. ToString ( ) ) )
if ( string . IsNullOrEmpty ( settings . Host ) | | string . IsNullOrEmpty ( settings . Port. ToString ( ) ) )
{
return false ;
}
@ -73,26 +73,6 @@ namespace Ombi.Notifications.Agents
Subject = parsed . Subject ,
} ;
if ( model . Substitutes . TryGetValue ( "AdminComment" , out var isAdminString ) )
{
var isAdmin = bool . Parse ( isAdminString ) ;
if ( isAdmin )
{
var user = _userManager . Users . FirstOrDefault ( x = > x . Id = = model . UserId ) ;
// Send to user
message . To = user . Email ;
}
else
{
// Send to admin
message . To = settings . AdminEmail ;
}
}
else
{
// Send to admin
message . To = settings . AdminEmail ;
}
return message ;
}
@ -138,9 +118,7 @@ namespace Ombi.Notifications.Agents
message . Other . Add ( "PlainTextBody" , plaintext ) ;
// Issues should be sent to admin
message . To = settings . AdminEmail ;
await Send ( message , settings ) ;
await SendToAdmins ( message , settings ) ;
}
protected override async Task IssueComment ( NotificationOptions model , EmailNotificationSettings settings )
@ -154,18 +132,16 @@ namespace Ombi.Notifications.Agents
var plaintext = await LoadPlainTextMessage ( NotificationType . IssueComment , model , settings ) ;
message . Other . Add ( "PlainTextBody" , plaintext ) ;
if ( model . Substitutes . TryGetValue ( "AdminComment" , out var isAdminString ) )
if ( model . Substitutes . TryGetValue ( "AdminComment" , out var isAdminString ) & & ! bool . Parse ( isAdminString ) )
{
var isAdmin = bool . Parse ( isAdminString ) ;
message . To = isAdmin ? model . Recipient : settings . AdminEmail ;
await SendToAdmins ( message , settings ) ;
}
else
{
message . To = model . Recipient ;
await Send ( message , settings ) ;
}
await Send ( message , settings ) ;
}
protected override async Task IssueResolved ( NotificationOptions model , EmailNotificationSettings settings )
@ -204,9 +180,7 @@ namespace Ombi.Notifications.Agents
var plaintext = await LoadPlainTextMessage ( NotificationType . ItemAddedToFaultQueue , model , settings ) ;
message . Other . Add ( "PlainTextBody" , plaintext ) ;
// Issues resolved should be sent to the user
message . To = settings . AdminEmail ;
await Send ( message , settings ) ;
await SendToAdmins ( message , settings ) ;
}
protected override async Task RequestDeclined ( NotificationOptions model , EmailNotificationSettings settings )
@ -305,6 +279,19 @@ namespace Ombi.Notifications.Agents
{
await EmailProvider . Send ( model , settings ) ;
}
protected async Task SendToAdmins ( NotificationMessage message , EmailNotificationSettings settings )
{
foreach ( var recipient in ( await GetAdminUsers ( ) ) . DistinctBy ( x = > x . Email ) )
{
if ( recipient . Email . IsNullOrEmpty ( ) )
{
continue ;
}
message . To = recipient . Email ;
await Send ( message , settings ) ;
}
}
protected override async Task Test ( NotificationOptions model , EmailNotificationSettings settings )
{
@ -316,12 +303,11 @@ namespace Ombi.Notifications.Agents
{
Message = html ,
Subject = $"Ombi: Test" ,
To = settings . AdminEmail ,
} ;
message . Other . Add ( "PlainTextBody" , "This is just a test! Success!" ) ;
await Send ( message , settings ) ;
await Send ToAdmins ( message , settings ) ;
}
}
}