-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(App&Service)! : email notification fix for offerSubscriptions (#239)
* fix(App&Service)! : email notification fix for offerSubscriptions * added mail service * chore: Added SubscriptionMangerRoles in IntegrationTests.json files * chore: adjust and extend unit-tests CPLP-3111 --------- Co-authored-by: Norbert Truchsess <norbert.truchsess@t-online.de> Reviewed-By: Norbert Truchsess <norbert.truchsess@t-online.de>
- Loading branch information
1 parent
fcef047
commit 5ae0519
Showing
27 changed files
with
679 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/mailing/Mailing.Service/DependencyInjection/MailingServiceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Org.Eclipse.TractusX.Portal.Backend.Mailing.Service; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Mailing.Service.DependencyInjection; | ||
|
||
public static class MailingServiceExtensions | ||
{ | ||
public static IServiceCollection AddMailingService(this IServiceCollection services) | ||
{ | ||
return services | ||
.AddTransient<IRoleBaseMailService, RoleBaseMailService>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 BMW Group AG | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Mailing.Service; | ||
|
||
public interface IRoleBaseMailService | ||
{ | ||
Task RoleBaseSendMail(IEnumerable<UserRoleConfig> receiverRoles, IEnumerable<(string ParameterName, string ParameterValue)> parameters, (string ParameterName, string ParameterValue)? userNameParameter, IEnumerable<string> template, Guid companyId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- | ||
- Copyright (c) 2021, 2023 BMW Group AG | ||
- Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
- | ||
- See the NOTICE file(s) distributed with this work for additional | ||
- information regarding copyright ownership. | ||
- | ||
- This program and the accompanying materials are made available under the | ||
- terms of the Apache License, Version 2.0 which is available at | ||
- https://www.apache.org/licenses/LICENSE-2.0. | ||
- | ||
- Unless required by applicable law or agreed to in writing, software | ||
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
- License for the specific language governing permissions and limitations | ||
- under the License. | ||
- | ||
- SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\portalbackend\PortalBackend.DBAccess\PortalBackend.DBAccess.csproj" /> | ||
<ProjectReference Include="..\..\portalbackend\PortalBackend.PortalEntities\PortalBackend.PortalEntities.csproj" /> | ||
<ProjectReference Include="..\..\framework\Framework.Models\Framework.Models.csproj" /> | ||
<ProjectReference Include="..\Mailing.SendMail\Mailing.SendMail.csproj" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.Mailing.Service</AssemblyName> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 BMW Group AG | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; | ||
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; | ||
using Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; | ||
using System.Collections.Immutable; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Mailing.Service; | ||
|
||
public class RoleBaseMailService : IRoleBaseMailService | ||
{ | ||
|
||
private readonly IPortalRepositories _portalRepositories; | ||
private readonly IMailingService _mailingService; | ||
|
||
public RoleBaseMailService(IPortalRepositories portalRepositories, IMailingService mailingService) | ||
{ | ||
_portalRepositories = portalRepositories; | ||
_mailingService = mailingService; | ||
} | ||
public async Task RoleBaseSendMail(IEnumerable<UserRoleConfig> receiverRoles, IEnumerable<(string ParameterName, string ParameterValue)> parameters, (string ParameterName, string ParameterValue)? userNameParameter, IEnumerable<string> template, Guid companyId) | ||
{ | ||
var receiverUserRoles = receiverRoles; | ||
var userRolesRepository = _portalRepositories.GetInstance<IUserRolesRepository>(); | ||
var roleData = await userRolesRepository | ||
.GetUserRoleIdsUntrackedAsync(receiverUserRoles) | ||
.ToListAsync() | ||
.ConfigureAwait(false); | ||
if (roleData.Count < receiverUserRoles.Sum(clientRoles => clientRoles.UserRoleNames.Count())) | ||
{ | ||
throw new ConfigurationException( | ||
$"invalid configuration, at least one of the configured roles does not exist in the database: {string.Join(", ", receiverUserRoles.Select(clientRoles => $"client: {clientRoles.ClientId}, roles: [{string.Join(", ", clientRoles.UserRoleNames)}]"))}"); | ||
} | ||
|
||
var companyUserWithRoleIdForCompany = _portalRepositories.GetInstance<IUserRepository>() | ||
.GetCompanyUserEmailForCompanyAndRoleId(roleData, companyId); | ||
|
||
await foreach (var (receiver, firstName, lastName) in companyUserWithRoleIdForCompany) | ||
{ | ||
IEnumerable<(string ParameterName, string ParameterValue)> ParametersWithUserName() | ||
{ | ||
if (userNameParameter.HasValue) | ||
{ | ||
var userName = string.Join(" ", new[] { firstName, lastName }.Where(item => !string.IsNullOrWhiteSpace(item))); | ||
return parameters.Append( | ||
string.IsNullOrWhiteSpace(userName) | ||
? userNameParameter.Value | ||
: new(userNameParameter.Value.ParameterName, userName)); | ||
} | ||
return parameters; | ||
} | ||
|
||
await _mailingService.SendMails(receiver, ParametersWithUserName().ToImmutableDictionary(x => x.ParameterName, x => x.ParameterValue), template).ConfigureAwait(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.