1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Parse enqueued mail message model to object (#1742)

* Parse enqueued mail message model to object

The model of an MailQueueMessage is of type object to enable enqueueing
of any message. However, this means the we are not able to parse a
serialized json object back into the original object.
Provide the model type to enable this deserialization

* Use ExpandoObject for deserialized queue message model
This commit is contained in:
Matt Gibson 2021-12-03 12:12:46 -06:00 committed by GitHub
parent 71229c2366
commit 9177ad1ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View File

@ -9,6 +9,6 @@ namespace Bit.Core.Models.Mail
IEnumerable<string> BccEmails { get; set; } IEnumerable<string> BccEmails { get; set; }
string Category { get; set; } string Category { get; set; }
string TemplateName { get; set; } string TemplateName { get; set; }
object Model { get; set; } dynamic Model { get; set; }
} }
} }

View File

@ -1,4 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Mail namespace Bit.Core.Models.Mail
{ {
@ -9,11 +11,12 @@ namespace Bit.Core.Models.Mail
public IEnumerable<string> BccEmails { get; set; } public IEnumerable<string> BccEmails { get; set; }
public string Category { get; set; } public string Category { get; set; }
public string TemplateName { get; set; } public string TemplateName { get; set; }
public object Model { get; set; } [JsonConverter(typeof(ExpandoObjectJsonConverter))]
public dynamic Model { get; set; }
public MailQueueMessage() { } public MailQueueMessage() { }
public MailQueueMessage(MailMessage message, string templateName, object model) public MailQueueMessage(MailMessage message, string templateName, dynamic model)
{ {
Subject = message.Subject; Subject = message.Subject;
ToEmails = message.ToEmails; ToEmails = message.ToEmails;

View File

@ -0,0 +1,19 @@
using System;
using System.Dynamic;
using Newtonsoft.Json;
namespace Bit.Core.Utilities
{
public class ExpandoObjectJsonConverter : JsonConverter
{
public override bool CanWrite => false;
public override bool CanConvert(Type objectType) => true;
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return serializer.Deserialize<ExpandoObject>(reader);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
}
}