Commit 55d0b4ad authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Merge branch 'Product/1089-htmlEmail' into 'Sprint/2020-20'

Product/1089 html email

See merge request coscine/api/notification!11
parents 38e7c735 55a922ea
using Coscine.ApiCommons;
using Coscine.ApiCommons.Factories;
using Coscine.Configuration;
using Coscine.Configuration;
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.NotificationChannelBase;
using Coscine.NotificationConfiguration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Stubble.Core.Builders;
using Stubble.Core.Loaders;
using System;
using System.Collections.Generic;
using System.Reflection;
......@@ -47,15 +45,14 @@ namespace Coscine.Api.NotificationBus.Controllers
}
[HttpPost("[controller]/sendAsync")]
public IActionResult SendAsync([FromBody] NotificationParameterObject notificationParameterObject)
public async Task<IActionResult> SendAsync([FromBody] NotificationParameterObject notificationParameterObject)
{
SendNotifications(notificationParameterObject);
await SendNotifications(notificationParameterObject);
return Ok();
}
private async Task SendNotifications(NotificationParameterObject notificationParameterObject)
{
List<User> users = GetUsers(notificationParameterObject.UserIds);
Project project = GetProject(notificationParameterObject.ProjectId);
var action = notificationParameterObject.Action;
ActionObject actionObject = _notificationConfiguration.GetAction(action);
......@@ -84,7 +81,7 @@ namespace Coscine.Api.NotificationBus.Controllers
}
// for every available user
foreach (User user in users)
foreach (User user in notificationParameterObject.Users)
{
JObject messageData = FillTemplate(channelName, actionObject, notificationParameterObject.Args, user, project);
......@@ -114,7 +111,11 @@ namespace Coscine.Api.NotificationBus.Controllers
}
var template = (JObject)(action.Template[channelName][language]);
var stubble = new StubbleBuilder().Build();
var stubble = new StubbleBuilder()
.Configure(settings =>
{
settings.SetPartialTemplateLoader(new DictionaryLoader(_notificationConfiguration.GetPartialsForChannel(channelName, language)));
}).Build();
var dict = new Dictionary<string, object>();
if (requestArgs["placeholder"] != null)
......@@ -130,7 +131,6 @@ namespace Coscine.Api.NotificationBus.Controllers
}
return template;
}
private List<User> GetUsers(List<string> userIds)
......
......@@ -63,8 +63,8 @@
<Reference Include="Coscine.NotificationChannelBase, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.NotificationChannelBase.1.1.0\lib\net461\Coscine.NotificationChannelBase.dll</HintPath>
</Reference>
<Reference Include="Coscine.NotificationConfiguration, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.NotificationConfiguration.1.3.0\lib\net461\Coscine.NotificationConfiguration.dll</HintPath>
<Reference Include="Coscine.NotificationConfiguration, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.NotificationConfiguration.1.4.0-topic-1127-email0008\lib\net461\Coscine.NotificationConfiguration.dll</HintPath>
</Reference>
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
......
using Newtonsoft.Json.Linq;
using System;
using Coscine.Database.DataModel;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.NotificationBus
{
public class NotificationParameterObject
{
public List<string> UserIds { get; set; }
public List<User> Users { get; set; }
public string Action { get; set; }
......@@ -24,10 +21,10 @@ namespace Coscine.Api.NotificationBus
}
public NotificationParameterObject(string action, List<string> userIds, string projectId, JObject args, string href)
public NotificationParameterObject(string action, List<User> users, string projectId, JObject args, string href)
{
Action = action;
UserIds = userIds;
Users = users;
ProjectId = projectId;
Args = args;
Href = href;
......
using Coscine.ApiCommons;
using Coscine.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.NotificationBus
{
......
using Coscine.ApiCommons;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.NotificationBus
{
......
......@@ -6,7 +6,7 @@
<package id="Coscine.Database" version="1.22.2" targetFramework="net461" />
<package id="Coscine.Logging" version="1.2.0" targetFramework="net461" />
<package id="Coscine.NotificationChannelBase" version="1.1.0" targetFramework="net461" />
<package id="Coscine.NotificationConfiguration" version="1.3.0" targetFramework="net461" />
<package id="Coscine.NotificationConfiguration" version="1.4.0-topic-1127-email0008" targetFramework="net461" />
<package id="Costura.Fody" version="4.1.0" targetFramework="net461" />
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
<package id="Fody" version="6.0.0" targetFramework="net461" developmentDependency="true" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment