Skip to content

Commit

Permalink
Merge branch 'dev' into feature/CPLP-3087-Get-appChange-documents
Browse files Browse the repository at this point in the history
  • Loading branch information
VPrasannaK94 authored Sep 13, 2023
2 parents aff39b8 + 5a83901 commit 6933905
Show file tree
Hide file tree
Showing 28 changed files with 7,862 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,7 @@ private async ValueTask<IdentityProviderDetails> CreateOwnCompanyIdentityProvide
}

var alias = await _provisioningManager.CreateOwnIdpAsync(displayName ?? result.CompanyName, result.CompanyName, protocol).ConfigureAwait(false);
var identityProviderId = identityProviderRepository.CreateIdentityProvider(identityProviderCategory, typeId, idp =>
{
if (typeId == IdentityProviderTypeId.MANAGED)
{
idp.OwnerId = companyId;
}
}).Id;
var identityProviderId = identityProviderRepository.CreateIdentityProvider(identityProviderCategory, typeId, companyId, null).Id;
if (typeId == IdentityProviderTypeId.OWN)
{
identityProviderRepository.CreateCompanyIdentityProvider(companyId, identityProviderId);
Expand Down Expand Up @@ -219,10 +213,10 @@ public async ValueTask<IdentityProviderDetails> SetOwnCompanyIdentityProviderSta
{
throw new NotFoundException($"identityProvider {identityProviderId} does not exist");
}
var (isOwnOrOwner, alias, identityProviderCategory, identityProviderTypeId, companyIdAliase) = result;
if (!isOwnOrOwner)
var (isOwner, alias, identityProviderCategory, identityProviderTypeId, companyIdAliase) = result;
if (!isOwner)
{
throw new ConflictException($"identityProvider {identityProviderId} is not associated with company {companyId}");
throw new ForbiddenException($"company {companyId} is not the owner of identityProvider {identityProviderId}");
}
if (alias == null)
{
Expand Down Expand Up @@ -268,8 +262,8 @@ public async ValueTask<IdentityProviderDetails> UpdateOwnCompanyIdentityProvider
{
throw new NotFoundException($"identityProvider {identityProviderId} does not exist");
}
var (isOwnOrOwner, alias, identityProviderCategory, identityProviderTypeId, _) = result;
if (!isOwnOrOwner)
var (isOwner, alias, identityProviderCategory, identityProviderTypeId, _) = result;
if (!isOwner)
{
throw new ForbiddenException($"User not allowed to run the change for identity provider {identityProviderId}");
}
Expand Down Expand Up @@ -357,7 +351,7 @@ public async ValueTask DeleteCompanyIdentityProviderAsync(Guid identityProviderI
}
await _provisioningManager.DeleteCentralIdentityProviderAsync(alias).ConfigureAwait(false);
}
_portalRepositories.Remove(_portalRepositories.Attach(new IdentityProvider(identityProviderId, default, default, default)));
_portalRepositories.Remove(_portalRepositories.Attach(new IdentityProvider(identityProviderId, default, default, default, default)));

await _portalRepositories.SaveAsync().ConfigureAwait(false);
}
Expand All @@ -369,10 +363,10 @@ public async ValueTask DeleteCompanyIdentityProviderAsync(Guid identityProviderI
{
throw new NotFoundException($"identityProvider {identityProviderId} does not exist");
}
var (isOwnOrOwner, alias, _, typeId, aliase) = result;
if (!isOwnOrOwner)
var (isOwner, alias, _, typeId, aliase) = result;
if (!isOwner)
{
throw new ConflictException($"identityProvider {identityProviderId} is not associated with company {companyId}");
throw new ForbiddenException($"company {companyId} is not the owner of identityProvider {identityProviderId}");
}

if (typeId == IdentityProviderTypeId.MANAGED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private async Task ExecuteInvitationInternalAsync(CompanyInvitationData invitati
var company = _portalRepositories.GetInstance<ICompanyRepository>().CreateCompany(invitationData.organisationName);

var identityProviderRepository = _portalRepositories.GetInstance<IIdentityProviderRepository>();
var identityProvider = identityProviderRepository.CreateIdentityProvider(IdentityProviderCategoryId.KEYCLOAK_OIDC, IdentityProviderTypeId.SHARED, null);
var identityProvider = identityProviderRepository.CreateIdentityProvider(IdentityProviderCategoryId.KEYCLOAK_OIDC, IdentityProviderTypeId.SHARED, company.Id, null);
identityProvider.Companies.Add(company);
identityProviderRepository.CreateIamIdentityProvider(identityProvider.Id, idpName);

Expand Down
14 changes: 13 additions & 1 deletion src/mailing/Mailing.Template/Enums/EmailTemplateType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ public enum EmailTemplateType
/// Email template for credential rejection
/// </summary>
[Path("verified_credential_declined.html")]
CredentialRejected
CredentialRejected,

/// <summary>
/// Email template for app release activation approval
/// </summary>
[Path("appactivation_offer_release_approval.html")]
AppReleaseActivationApproval,

/// <summary>
/// Email template for service release activation approval
/// </summary>
[Path("serviceactivation_offer_release_approval.html")]
ServiceReleaseActivationApproval
}
}
6 changes: 6 additions & 0 deletions src/mailing/Mailing.Template/Mailing.Template.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<None Update="EmailTemplates\verified_credential_declined.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EmailTemplates\appactivation_offer_release_approval.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EmailTemplates\serviceactivation_offer_release_approval.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public Task SubmitAppReleaseRequestAsync(Guid appId, Guid userId) =>

/// <inheritdoc/>
public Task ApproveAppRequestAsync(Guid appId, Guid userId) =>
_offerService.ApproveOfferRequestAsync(appId, userId, OfferTypeId.APP, _settings.ApproveAppNotificationTypeIds, _settings.ApproveAppUserRoles, _settings.SubmitAppNotificationTypeIds, _settings.CatenaAdminRoles);
_offerService.ApproveOfferRequestAsync(appId, userId, OfferTypeId.APP, _settings.ApproveAppNotificationTypeIds, _settings.ApproveAppUserRoles, _settings.SubmitAppNotificationTypeIds, _settings.CatenaAdminRoles, _settings.BasePortalAddress, _settings.ActivationUserRoles);

private IEnumerable<OfferStatusId> GetOfferStatusIds(OfferStatusIdFilter? offerStatusIdFilter)
{
Expand Down
8 changes: 8 additions & 0 deletions src/marketplace/Apps.Service/BusinessLogic/AppsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,21 @@ public class AppsSettings
[DistinctValues("x => x.ClientId")]
public IEnumerable<UserRoleConfig> SubscriptionManagerRoles { get; set; } = null!;

/// <summary>
/// Roles to notify when a new Activation was created
/// </summary>
[Required]
[DistinctValues("x => x.ClientId")]
public IEnumerable<UserRoleConfig> ActivationUserRoles { get; init; } = null!;

/// <summary>
/// Active Document Types
/// </summary>
[Required]
[EnumEnumeration]
[DistinctValues]
public IEnumerable<DocumentTypeId> ActiveAppDocumentTypeIds { get; set; } = null!;

}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions src/marketplace/Apps.Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
"Subject": "Decline of app {offerName}",
"EmailTemplateType": "AppRequestDecline"
}
},
{
"Name": "offer-release-activation",
"Setting": {
"Subject": "Activation of app {offerName}",
"EmailTemplateType": "AppReleaseActivationApproval"
}
}
],
"Mail": {
Expand Down
2 changes: 1 addition & 1 deletion src/marketplace/Offers.Library/Service/IOfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Task CreateOrUpdateOfferSubscriptionAgreementConsentAsync(Guid subscriptionId,
/// <param name="submitOfferNotificationTypeIds"></param>
/// <param name="catenaAdminRoles"></param>
/// <returns></returns>
Task ApproveOfferRequestAsync(Guid offerId, Guid userId, OfferTypeId offerTypeId, IEnumerable<NotificationTypeId> approveOfferNotificationTypeIds, IEnumerable<UserRoleConfig> approveOfferRoles, IEnumerable<NotificationTypeId> submitOfferNotificationTypeIds, IEnumerable<UserRoleConfig> catenaAdminRoles);
Task ApproveOfferRequestAsync(Guid offerId, Guid userId, OfferTypeId offerTypeId, IEnumerable<NotificationTypeId> approveOfferNotificationTypeIds, IEnumerable<UserRoleConfig> approveOfferRoles, IEnumerable<NotificationTypeId> submitOfferNotificationTypeIds, IEnumerable<UserRoleConfig> catenaAdminRoles, string basePortalAddress, IEnumerable<UserRoleConfig> notificationRecipients);

/// <summary>
/// Update offer status and create notification for App
Expand Down
17 changes: 16 additions & 1 deletion src/marketplace/Offers.Library/Service/OfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ offerDetails.ProviderCompanyId is not null &&
}

/// <inheritdoc/>
public async Task ApproveOfferRequestAsync(Guid offerId, Guid userId, OfferTypeId offerTypeId, IEnumerable<NotificationTypeId> approveOfferNotificationTypeIds, IEnumerable<UserRoleConfig> approveOfferRoles, IEnumerable<NotificationTypeId> submitOfferNotificationTypeIds, IEnumerable<UserRoleConfig> catenaAdminRoles)
public async Task ApproveOfferRequestAsync(Guid offerId, Guid userId, OfferTypeId offerTypeId, IEnumerable<NotificationTypeId> approveOfferNotificationTypeIds, IEnumerable<UserRoleConfig> approveOfferRoles, IEnumerable<NotificationTypeId> submitOfferNotificationTypeIds, IEnumerable<UserRoleConfig> catenaAdminRoles, string basePortalAddress, IEnumerable<UserRoleConfig> notificationRecipients)
{
var offerRepository = _portalRepositories.GetInstance<IOfferRepository>();
var offerDetails = await offerRepository.GetOfferStatusDataByIdAsync(offerId, offerTypeId).ConfigureAwait(false);
Expand Down Expand Up @@ -509,6 +509,21 @@ public async Task ApproveOfferRequestAsync(Guid offerId, Guid userId, OfferTypeI
await _notificationService.SetNotificationsForOfferToDone(catenaAdminRoles, submitOfferNotificationTypeIds, offerId).ConfigureAwait(false);

await _portalRepositories.SaveAsync().ConfigureAwait(false);

await _roleBaseMailService.RoleBaseSendMail(
notificationRecipients,
new[]
{
("offerName", offerDetails.OfferName),
("portalBaseUrl", basePortalAddress),
(offerTypeId == OfferTypeId.APP ? "appId" : "serviceId", offerId.ToString())
},
("offerProviderName", "User"),
new[]
{
"offer-release-activation"
},
offerDetails.ProviderCompanyId.Value).ConfigureAwait(false);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public Task SubmitServiceAsync(Guid serviceId, Guid userId) =>

/// <inheritdoc/>
public Task ApproveServiceRequestAsync(Guid appId, Guid userId) =>
_offerService.ApproveOfferRequestAsync(appId, userId, OfferTypeId.SERVICE, _settings.ApproveServiceNotificationTypeIds, _settings.ApproveServiceUserRoles, _settings.SubmitServiceNotificationTypeIds, _settings.CatenaAdminRoles);
_offerService.ApproveOfferRequestAsync(appId, userId, OfferTypeId.SERVICE, _settings.ApproveServiceNotificationTypeIds, _settings.ApproveServiceUserRoles, _settings.SubmitServiceNotificationTypeIds, _settings.CatenaAdminRoles, _settings.BasePortalAddress, _settings.ActivationUserRoles);

/// <inheritdoc />
public Task DeclineServiceRequestAsync(Guid serviceId, Guid userId, OfferDeclineRequest data) =>
Expand Down
7 changes: 7 additions & 0 deletions src/marketplace/Services.Service/ServiceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ public class ServiceSettings
[DistinctValues("x => x.ClientId")]
public IEnumerable<UserRoleConfig> SubscriptionManagerRoles { get; init; } = null!;

/// <summary>
/// Roles to notify when a new Activation was created
/// </summary>
[Required]
[DistinctValues("x => x.ClientId")]
public IEnumerable<UserRoleConfig> ActivationUserRoles { get; init; } = null!;

}

public static class ServiceSettingsExtension
Expand Down
7 changes: 7 additions & 0 deletions src/marketplace/Services.Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@
"Subject": "Decline of service {offerName}",
"EmailTemplateType": "ServiceRequestDecline"
}
},
{
"Name": "offer-release-activation",
"Setting": {
"Subject": "Activation of service {offerName}",
"EmailTemplateType": "ServiceReleaseActivationApproval"
}
}
],
"Mail": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositorie
/// </summary>
public interface IIdentityProviderRepository
{
IdentityProvider CreateIdentityProvider(IdentityProviderCategoryId identityProviderCategory, IdentityProviderTypeId identityProviderTypeId, Action<IdentityProvider>? setOptionalFields);
IdentityProvider CreateIdentityProvider(IdentityProviderCategoryId identityProviderCategory, IdentityProviderTypeId identityProviderTypeId, Guid owner, Action<IdentityProvider>? setOptionalFields);
IamIdentityProvider CreateIamIdentityProvider(Guid identityProviderId, string idpAlias);
CompanyIdentityProvider CreateCompanyIdentityProvider(Guid companyId, Guid identityProviderId);
Task<string?> GetSharedIdentityProviderIamAliasDataUntrackedAsync(Guid companyId);
Task<IdpUser?> GetIdpCategoryIdByUserIdAsync(Guid companyUserId, Guid userCompanyId);
Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnOrOwnerCompany, IdentityProviderTypeId TypeId)> GetOwnCompanyIdentityProviderAliasUntrackedAsync(Guid identityProviderId, Guid companyId);
Task<(bool IsOwnOrOwner, string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)>? CompanyIdAliase)> GetOwnCompanyIdentityProviderUpdateDataUntrackedAsync(Guid identityProviderId, Guid companyId, bool queryAliase);
Task<(bool IsOwner, string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)>? CompanyIdAliase)> GetOwnCompanyIdentityProviderUpdateDataUntrackedAsync(Guid identityProviderId, Guid companyId, bool queryAliase);
IAsyncEnumerable<(Guid IdentityProviderId, IdentityProviderCategoryId CategoryId, string Alias, IdentityProviderTypeId TypeId)> GetCompanyIdentityProviderCategoryDataUntracked(Guid companyId);
IAsyncEnumerable<(Guid IdentityProviderId, string Alias)> GetOwnCompanyIdentityProviderAliasDataUntracked(Guid companyId, IEnumerable<Guid> identityProviderIds);
Task<(string? UserEntityId, string? Alias, bool IsSameCompany)> GetIamUserIsOwnCompanyIdentityProviderAliasAsync(Guid companyUserId, Guid identityProviderId, Guid companyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ public IdentityProviderRepository(PortalDbContext portalDbContext)
}

/// <inheritdoc/>
public IdentityProvider CreateIdentityProvider(IdentityProviderCategoryId identityProviderCategory, IdentityProviderTypeId identityProviderTypeId, Action<IdentityProvider>? setOptionalFields)
public IdentityProvider CreateIdentityProvider(IdentityProviderCategoryId identityProviderCategory, IdentityProviderTypeId identityProviderTypeId, Guid owner, Action<IdentityProvider>? setOptionalFields)
{
var idp = new IdentityProvider(
Guid.NewGuid(),
identityProviderCategory,
identityProviderTypeId,
owner,
DateTimeOffset.UtcNow);
setOptionalFields?.Invoke(idp);
return _context.IdentityProviders
Expand Down Expand Up @@ -100,12 +101,12 @@ public IamIdentityProvider CreateIamIdentityProvider(Guid identityProviderId, st
identityProvider.IdentityProviderTypeId))
.SingleOrDefaultAsync();

public Task<(bool IsOwnOrOwner, string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)>? CompanyIdAliase)> GetOwnCompanyIdentityProviderUpdateDataUntrackedAsync(Guid identityProviderId, Guid companyId, bool queryAliase) =>
public Task<(bool IsOwner, string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)>? CompanyIdAliase)> GetOwnCompanyIdentityProviderUpdateDataUntrackedAsync(Guid identityProviderId, Guid companyId, bool queryAliase) =>
_context.IdentityProviders
.Where(identityProvider => identityProvider.Id == identityProviderId)
.Select(identityProvider =>
new ValueTuple<bool, string?, IdentityProviderCategoryId, IdentityProviderTypeId, IEnumerable<(Guid, IEnumerable<string>)>?>(
identityProvider.Owner == null && identityProvider.Companies.Any(c => c.Id == companyId) && identityProvider.Companies.Count == 1 || identityProvider.OwnerId == companyId,
identityProvider.OwnerId == companyId,
identityProvider.IamIdentityProvider!.IamIdpAlias,
identityProvider.IdentityProviderCategoryId,
identityProvider.IdentityProviderTypeId,
Expand All @@ -118,7 +119,7 @@ public IamIdentityProvider CreateIamIdentityProvider(Guid identityProviderId, st
public IAsyncEnumerable<(Guid IdentityProviderId, IdentityProviderCategoryId CategoryId, string Alias, IdentityProviderTypeId TypeId)> GetCompanyIdentityProviderCategoryDataUntracked(Guid companyId) =>
_context.IdentityProviders
.AsNoTracking()
.Where(identityProvider => identityProvider.OwnerId == companyId || identityProvider.Companies.Any(company => company.Id == companyId) && identityProvider.OwnerId == null)
.Where(identityProvider => identityProvider.OwnerId == companyId || identityProvider.Companies.Any(company => company.Id == companyId))
.Select(identityProvider => new ValueTuple<Guid, IdentityProviderCategoryId, string, IdentityProviderTypeId>(
identityProvider.Id,
identityProvider.IdentityProviderCategoryId,
Expand Down
Loading

0 comments on commit 6933905

Please sign in to comment.