Fixed the issue comment issue #1914 also added another variable for issues {IssueUser} which is the user that reported the issue

pull/1959/head
Jamie 7 years ago
parent 2df80913c4
commit 2fbde15c40

@ -150,6 +150,10 @@ namespace Ombi.Notifications.Agents
var isAdmin = bool.Parse(isAdminString);
message.To = isAdmin ? model.Recipient : settings.AdminEmail;
}
else
{
message.To = model.Recipient;
}
await Send(message, settings);

@ -81,6 +81,7 @@ namespace Ombi.Notifications
IssueStatus = opts.Substitutes.TryGetValue("IssueStatus", out val) ? val : string.Empty;
IssueSubject = opts.Substitutes.TryGetValue("IssueSubject", out val) ? val : string.Empty;
NewIssueComment = opts.Substitutes.TryGetValue("NewIssueComment", out val) ? val : string.Empty;
IssueUser = opts.Substitutes.TryGetValue("IssueUser", out val) ? val : string.Empty;
}
// User Defined
@ -101,6 +102,7 @@ namespace Ombi.Notifications
public string IssueStatus { get; set; }
public string IssueSubject { get; set; }
public string NewIssueComment { get; set; }
public string IssueUser { get; set; }
// System Defined
private string LongDate => DateTime.Now.ToString("D");
@ -131,6 +133,7 @@ namespace Ombi.Notifications
{nameof(IssueStatus),IssueStatus},
{nameof(IssueSubject),IssueSubject},
{nameof(NewIssueComment),NewIssueComment},
{nameof(IssueUser),IssueUser},
};
}
}

@ -35,16 +35,17 @@ export enum NotificationAgent {
}
export enum NotificationType {
NewRequest,
Issue,
RequestAvailable,
RequestApproved,
AdminNote,
Test,
RequestDeclined,
ItemAddedToFaultQueue,
WelcomeEmail,
IssueResolved,
NewRequest = 0,
Issue = 1,
RequestAvailable = 2,
RequestApproved = 3,
AdminNote = 4,
Test = 5,
RequestDeclined = 6,
ItemAddedToFaultQueue = 7,
WelcomeEmail = 8,
IssueResolved = 9,
IssueComment = 10,
}
export interface IDiscordNotifcationSettings extends INotificationSettings {

@ -145,7 +145,7 @@ namespace Ombi.Controllers
UserId = i.UserReportedId
};
AddIssueNotificationSubstitutes(notificationModel, i);
AddIssueNotificationSubstitutes(notificationModel, i, User.Identity.Name);
BackgroundJob.Enqueue(() => _notification.Publish(notificationModel));
@ -195,7 +195,7 @@ namespace Ombi.Controllers
{
var user = await _userManager.Users.Where(x => User.Identity.Name == x.UserName)
.FirstOrDefaultAsync();
var issue = await _issues.Find(comment.IssueId ?? 0);
var issue = await _issues.GetAll().Include(x => x.UserReported).FirstOrDefaultAsync(x => x.Id == comment.IssueId);
if (issue == null)
{
return null;
@ -214,15 +214,24 @@ namespace Ombi.Controllers
DateTime = DateTime.Now,
NotificationType = NotificationType.IssueComment,
RequestType = issue.RequestType,
Recipient = user.Email,
UserId = user.Id
};
var isAdmin = await _userManager.IsInRoleAsync(user, OmbiRoles.Admin);
AddIssueNotificationSubstitutes(notificationModel, issue);
AddIssueNotificationSubstitutes(notificationModel, issue, issue.UserReported.UserAlias);
notificationModel.Substitutes.Add("NewIssueComment", comment.Comment);
notificationModel.Substitutes.Add("AdminComment", isAdmin.ToString());
if (isAdmin)
{
// Send to user
notificationModel.Recipient = issue.UserReported.Email;
}
else
{
notificationModel.Recipient = user.Email;
}
BackgroundJob.Enqueue(() => _notification.Publish(notificationModel));
return await _issueComments.Add(newComment);
@ -257,7 +266,7 @@ namespace Ombi.Controllers
UserId = user.Id,
};
AddIssueNotificationSubstitutes(notificationModel, issue);
AddIssueNotificationSubstitutes(notificationModel, issue, issue.UserReported?.UserAlias ?? string.Empty);
BackgroundJob.Enqueue(() => _notification.Publish(notificationModel));
}
@ -266,13 +275,14 @@ namespace Ombi.Controllers
return true;
}
private static void AddIssueNotificationSubstitutes(NotificationOptions notificationModel, Issues issue)
private static void AddIssueNotificationSubstitutes(NotificationOptions notificationModel, Issues issue, string issueReportedUsername)
{
notificationModel.Substitutes.Add("Title", issue.Title);
notificationModel.Substitutes.Add("IssueDescription", issue.Description);
notificationModel.Substitutes.Add("IssueCategory", issue.IssueCategory?.Value);
notificationModel.Substitutes.Add("IssueStatus", issue.Status.ToString());
notificationModel.Substitutes.Add("IssueSubject", issue.Subject);
notificationModel.Substitutes.Add("IssueUser", issueReportedUsername);
}
}
}
Loading…
Cancel
Save