Skip to content

Commit

Permalink
Add backward compatability for old FCE types
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed Feb 3, 2025
1 parent 76a00a1 commit f3c2878
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public ContentValueDtoValidator(DialogTransmissionContentType contentType)
{
RuleFor(x => x.MediaType)
.NotEmpty()
.Must(value => value is not null && contentType.AllowedMediaTypes.Contains(value))
.Must(value => value is not null && contentType.AllowedMediaTypes
// Manually adding this for backwards compatibility, until correspondence is updated and deployed
.Append(MediaTypes.EmbeddableMarkdownDeprecated).Contains(value))
.WithMessage($"{{PropertyName}} '{{PropertyValue}}' is not allowed for content type {contentType.Name}. " +
$"Allowed media types are {string.Join(", ", contentType.AllowedMediaTypes.Select(x => $"'{x}'"))}");

Expand Down Expand Up @@ -73,7 +75,12 @@ private static string[] GetAllowedMediaTypes(DialogContentType contentType, IUse
DialogContentType.Values.AdditionalInfo when UserHasLegacyHtmlScope(user)
=> contentType.AllowedMediaTypes.Append(MediaTypes.LegacyHtml).ToArray(),
DialogContentType.Values.MainContentReference when UserHasLegacyHtmlScope(user)
=> contentType.AllowedMediaTypes.Append(MediaTypes.LegacyEmbeddableHtml).ToArray(),
=> contentType.AllowedMediaTypes.Append(MediaTypes.LegacyEmbeddableHtml)
// Manually adding this for backwards compatibility, until correspondence is updated and deployed
.Append(MediaTypes.EmbeddableMarkdownDeprecated)
.Append(MediaTypes.LegacyEmbeddableHtmlDeprecated).ToArray(),
DialogContentType.Values.MainContentReference
=> contentType.AllowedMediaTypes.Append(MediaTypes.EmbeddableMarkdownDeprecated).ToArray(),
_ => contentType.AllowedMediaTypes
};
private static bool UserHasLegacyHtmlScope(IUser? user)
Expand Down
4 changes: 4 additions & 0 deletions src/Digdir.Domain.Dialogporten.Domain/MediaTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ namespace Digdir.Domain.Dialogporten.Domain;
public static class MediaTypes
{
public const string EmbeddablePrefix = "application/vnd.dialogporten.frontchannelembed";

public const string EmbeddableMarkdown = $"{EmbeddablePrefix}-url;type=text/markdown";
public const string EmbeddableMarkdownDeprecated = $"{EmbeddablePrefix}+json;type=markdown";

public const string LegacyEmbeddableHtml = $"{EmbeddablePrefix}-url;type=text/html";
public const string LegacyEmbeddableHtmlDeprecated = $"{EmbeddablePrefix}+json;type=html";

public const string LegacyHtml = "text/html";
public const string Markdown = "text/markdown";
Expand Down

0 comments on commit f3c2878

Please sign in to comment.