Skip to content

Commit

Permalink
release(1.6.0-RC6): merge main to dev #200
Browse files Browse the repository at this point in the history
Reviewed-by: Norbert Truchsess <[email protected]>
  • Loading branch information
Phil91 authored Aug 11, 2023
2 parents 845991d + 1d48a09 commit 21f4ad8
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 66 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

New features, fixed bugs, known defects and other noteworthy changes to each release of the Catena-X Portal Backend.

## 1.6.0-RC6

### Change
* App Service
* add single app subscription activation
* change the endpoint subscription/{offerSubscriptionId}/activate-single-instance from post to put

### Technical Support
* update of the portal_welcome_email template
* adjust naming of the technical user which is taken for the process worker runs

### Bugfix
* Process Worker
* fixed the logging of the wallet creation response to save the did in the database
* SSI
* change the value of SUSTAINABILITY_CREDENTIAL which is send to custodian
* Authentication
* changed case sensitive check for 'Bearer xxx' to 'bearer' xxx'

## 1.6.0-RC5

### Change
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>1.6.0</VersionPrefix>
<VersionSuffix>RC5</VersionSuffix>
<VersionSuffix>RC6</VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\framework\Framework.DateTimeProvider\Framework.DateTimeProvider.csproj" />
<ProjectReference Include="..\..\framework\Framework.HttpClient\Framework.HttpClient.csproj" />
<ProjectReference Include="..\..\framework\Framework.Logging\Framework.Logging.csproj" />
<ProjectReference Include="..\..\framework\Framework.Token\Framework.Token.csproj" />
Expand Down
7 changes: 5 additions & 2 deletions src/externalsystems/Custodian.Library/CustodianService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Custodian.Library.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions;
using Org.Eclipse.TractusX.Portal.Backend.Framework.IO;
Expand All @@ -36,11 +37,13 @@ public class CustodianService : ICustodianService
{
private static readonly JsonSerializerOptions Options = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
private readonly ITokenService _tokenService;
private readonly IDateTimeProvider _dateTimeProvider;
private readonly CustodianSettings _settings;

public CustodianService(ITokenService tokenService, IOptions<CustodianSettings> settings)
public CustodianService(ITokenService tokenService, IDateTimeProvider dateTimeProvider, IOptions<CustodianSettings> settings)
{
_tokenService = tokenService;
_dateTimeProvider = dateTimeProvider;
_settings = settings.Value;
}

Expand Down Expand Up @@ -89,7 +92,7 @@ public async Task<string> CreateWalletAsync(string bpn, string name, Cancellatio
return "Service Response for custodian-post is null";
}

return JsonSerializer.Serialize(walletResponse, Options);
return JsonSerializer.Serialize(new WalletCreationLogData(walletResponse.Did, _dateTimeProvider.OffsetNow), Options);
}
catch (JsonException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public record WalletErrorResponse([property: JsonPropertyName("message")] string

public record MembershipErrorResponse([property: JsonPropertyName("title")] string Title);

public record WalletCreationResponse([property: JsonPropertyName("DID")] string Did, [property: JsonPropertyName("CreatedAt")] DateTimeOffset CreatedAt);
public record WalletCreationResponse([property: JsonPropertyName("did")] string Did);

public record WalletCreationLogData([property: JsonPropertyName("did")] string Did, [property: JsonPropertyName("createdAt")] DateTimeOffset CreatedAt);
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IdentityData GetIdentityData(this ClaimsPrincipal user)
private static string GetBearerToken(this ControllerBase controller)
{
var authorization = controller.Request.Headers.Authorization.FirstOrDefault();
if (authorization == null || !authorization.StartsWith("Bearer "))
if (authorization == null || !authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
{
throw new ControllerArgumentException("Request does not contain a Bearer-token in authorization-header",
nameof(authorization));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
style="Margin:0;padding-top:20px;padding-bottom:20px;padding-left:30px;padding-right:30px;text-align: left;">
<p
style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:21px;color:#333333;font-size:14px">
Dear {userName} <br /> Your company registration application for {companyName} has
Dear {userName} {bpn} <br /> Your company registration application for {companyName} has
been successfully approved. <br /> You can now start to participate in the Catena-X
Network.</p>
<p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ public Task<OfferAutoSetupResponseData> AutoSetupAppAsync(OfferAutoSetupData dat
public Task StartAutoSetupAsync(OfferAutoSetupData data, Guid companyId) =>
_offerSetupService.StartAutoSetupAsync(data, companyId, OfferTypeId.APP);

/// <inheritdoc />
public Task ActivateSingleInstance(Guid offerSubscriptionId, Guid companyId) =>
_offerSetupService.CreateSingleInstanceSubscriptionDetail(offerSubscriptionId, companyId);

/// <inheritdoc />
public IAsyncEnumerable<AgreementData> GetAppAgreement(Guid appId) =>
_offerService.GetOfferAgreementsAsync(appId, OfferTypeId.APP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,15 @@ public interface IAppsBusinessLogic
/// </summary>
/// <param name="data">The offer subscription id and url for the service</param>
/// <param name="companyId">Id of the company</param>
/// <returns>Returns the response data</returns>
Task StartAutoSetupAsync(OfferAutoSetupData data, Guid companyId);

/// <summary>
/// Triggers the activation of a single instance app subscription.
/// </summary>
/// <param name="offerSubscriptionId">The offer subscription id</param>
/// <param name="companyId">Id of the company</param>
Task ActivateSingleInstance(Guid offerSubscriptionId, Guid companyId);

/// <summary>
/// Gets the app agreement data
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions src/marketplace/Apps.Service/Controllers/AppsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,26 @@ public async Task<NoContentResult> StartAutoSetupAppProcess([FromBody] OfferAuto
return NoContent();
}

/// <summary>
/// Triggers the activation of a single instance app subscription
/// </summary>
/// <remarks>Example: PUT: /api/apps/subscription/{offerSubscriptionId}/activate-single-instance</remarks>
/// <response code="204">The activation of the subscription has successfully been started.</response>
/// <response code="400">Offer Subscription is pending or not the providing company.</response>
/// <response code="404">Offer Subscription not found.</response>
[HttpPut]
[Route("subscription/{offerSubscriptionId}/activate-single-instance")]
[Authorize(Roles = "activate_subscription")]
[Authorize(Policy = PolicyTypes.ValidCompany)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
public async Task<NoContentResult> ActivateSingleInstance([FromRoute] Guid offerSubscriptionId)
{
await this.WithCompanyId(companyId => _appsBusinessLogic.ActivateSingleInstance(offerSubscriptionId, companyId)).ConfigureAwait(false);
return NoContent();
}

/// <summary>
/// Retrieve Document Content for document type "App Lead Image" and "App Image" by ID
/// </summary>
Expand Down
9 changes: 6 additions & 3 deletions src/marketplace/Offers.Library/Service/IOfferSetupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ public interface IOfferSetupService
/// <param name="data">The offer subscription id and url for the service</param>
/// <param name="companyId">Id of the company</param>
/// <param name="offerTypeId">OfferTypeId of offer to be created</param>
/// <returns>Returns the response data</returns>
Task StartAutoSetupAsync(OfferAutoSetupData data, Guid companyId, OfferTypeId offerTypeId);

/// <inheritdoc />
Task<(IEnumerable<ProcessStepTypeId>? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateSingleInstanceSubscriptionDetail(Guid offerSubscriptionId);
/// <summary>
/// Creates the single instance subscription detail and creates the activation step.
/// </summary>
/// <param name="offerSubscriptionId">The offer subscription id and url for the service</param>
/// <param name="companyId">Id of the company</param>
Task CreateSingleInstanceSubscriptionDetail(Guid offerSubscriptionId, Guid companyId);

Task<(IEnumerable<ProcessStepTypeId>? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateClient(Guid offerSubscriptionId);

Expand Down
24 changes: 15 additions & 9 deletions src/marketplace/Offers.Library/Service/OfferSetupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public async Task StartAutoSetupAsync(OfferAutoSetupData data, Guid companyId, O
}

/// <inheritdoc />
public async Task<(IEnumerable<ProcessStepTypeId>? nextStepTypeIds, ProcessStepStatusId stepStatusId, bool modified, string? processMessage)> CreateSingleInstanceSubscriptionDetail(Guid offerSubscriptionId)
public async Task CreateSingleInstanceSubscriptionDetail(Guid offerSubscriptionId, Guid companyId)
{
var offerSubscriptionRepository = _portalRepositories.GetInstance<IOfferSubscriptionsRepository>();
var offerDetails = await offerSubscriptionRepository.GetSubscriptionActivationDataByIdAsync(offerSubscriptionId).ConfigureAwait(false);
Expand All @@ -424,21 +424,27 @@ public async Task StartAutoSetupAsync(OfferAutoSetupData data, Guid companyId, O
case true when offerDetails.AppInstanceIds.Count() != 1:
throw new ConflictException("There must only be one app instance for single instance apps");
default:
if (offerDetails.ProviderCompanyId != companyId)
{
throw new ConflictException("Subscription can only be activated by the provider of the offer");
}

_portalRepositories.GetInstance<IAppSubscriptionDetailRepository>()
.CreateAppSubscriptionDetail(offerSubscriptionId, appSubscriptionDetail =>
{
appSubscriptionDetail.AppInstanceId = offerDetails.AppInstanceIds.Single();
appSubscriptionDetail.AppSubscriptionUrl = offerDetails.InstanceData.InstanceUrl;
});

return new ValueTuple<IEnumerable<ProcessStepTypeId>?, ProcessStepStatusId, bool, string?>(
new[]
{
ProcessStepTypeId.ACTIVATE_SUBSCRIPTION
},
ProcessStepStatusId.DONE,
true,
null);
var context = await _offerSubscriptionProcessService.VerifySubscriptionAndProcessSteps(offerSubscriptionId,
ProcessStepTypeId.SINGLE_INSTANCE_SUBSCRIPTION_DETAILS_CREATION, null, true).ConfigureAwait(false);

_offerSubscriptionProcessService.FinalizeProcessSteps(context, new[]
{
ProcessStepTypeId.ACTIVATE_SUBSCRIPTION
});
await _portalRepositories.SaveAsync().ConfigureAwait(false);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ public record SubscriptionActivationData(
(bool IsSingleInstance, string? InstanceUrl) InstanceData,
IEnumerable<Guid> AppInstanceIds,
bool HasOfferSubscriptionProcessData,
Guid? SalesManagerId
Guid? SalesManagerId,
Guid? ProviderCompanyId
);
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ public Task<Guid> GetOfferSubscriptionDataForProcessIdAsync(Guid processId) =>
: new ValueTuple<bool, string?>(x.Offer.AppInstanceSetup.IsSingleInstance, x.Offer.AppInstanceSetup.InstanceUrl),
x.Offer.AppInstances.Select(ai => ai.Id),
x.OfferSubscriptionProcessData != null,
x.Offer.SalesManagerId
x.Offer.SalesManagerId,
x.Offer.ProviderCompanyId
))
.SingleOrDefaultAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
},
{
"id": "d21d2e8a-fe35-483c-b2b8-4100ed7f0953",
"name": "sa-cl2-04",
"name": "system-internal",
"description": "Technical User for Portal ProccessWorker",
"company_service_account_type_id": 2,
"client_id": "c5709899-0415-4385-be80-76d2bfd31724",
"client_client_id": "sa-cl2-04"
"client_client_id": "system-internal"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public enum VerifiedCredentialExternalTypeId
[EnumMember(Value = "vehicleDismantle")]
VEHICLE_DISMANTLE = 4,

[EnumMember(Value = "Sustainability_Credential")]
[EnumMember(Value = "SustainabilityCredential")]
SUSTAINABILITY_CREDENTIAL = 5,
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class OfferSubscriptionProcessTypeExecutor : IProcessTypeExecutor

private readonly IEnumerable<ProcessStepTypeId> _executableProcessSteps = ImmutableArray.Create(
ProcessStepTypeId.TRIGGER_PROVIDER,
ProcessStepTypeId.SINGLE_INSTANCE_SUBSCRIPTION_DETAILS_CREATION,
ProcessStepTypeId.OFFERSUBSCRIPTION_CLIENT_CREATION,
ProcessStepTypeId.OFFERSUBSCRIPTION_TECHNICALUSER_CREATION,
ProcessStepTypeId.ACTIVATE_SUBSCRIPTION,
Expand Down Expand Up @@ -106,9 +105,6 @@ public OfferSubscriptionProcessTypeExecutor(
ProcessStepTypeId.TRIGGER_PROVIDER => await _offerProviderBusinessLogic
.TriggerProvider(_offerSubscriptionId, cancellationToken)
.ConfigureAwait(false),
ProcessStepTypeId.SINGLE_INSTANCE_SUBSCRIPTION_DETAILS_CREATION => await _offerSetupService
.CreateSingleInstanceSubscriptionDetail(_offerSubscriptionId)
.ConfigureAwait(false),
ProcessStepTypeId.OFFERSUBSCRIPTION_CLIENT_CREATION => await _offerSetupService
.CreateClient(_offerSubscriptionId)
.ConfigureAwait(false),
Expand Down
Loading

0 comments on commit 21f4ad8

Please sign in to comment.