From 4c000e50877261e44703439d37b28c674cdf48fd Mon Sep 17 00:00:00 2001 From: AnuragNagpure <145100366+AnuragNagpure@users.noreply.github.com> Date: Wed, 12 Feb 2025 21:20:03 +0530 Subject: [PATCH] fix(document): add check of documentTypeId (#1275) * add check for documentTypeId to Get-Document-endpoints * adjust unit-tests --------- Co-authored-by: Norbert Truchsess --- .../RegistrationBusinessLogic.cs | 2 +- .../Framework.Async/Directory.Build.props | 2 +- .../Framework.Cors/Directory.Build.props | 2 +- .../Framework.DBAccess/Directory.Build.props | 2 +- .../Directory.Build.props | 2 +- .../Directory.Build.props | 2 +- .../Directory.Build.props | 2 +- .../Directory.Build.props | 2 +- .../Directory.Build.props | 2 +- .../Service/IErrorMessageContainer.cs | 4 +- .../Service/IErrorMessageService.cs | 8 +-- .../Directory.Build.props | 2 +- .../Framework.IO/Directory.Build.props | 2 +- .../Framework.Identity/Directory.Build.props | 2 +- .../Framework.Linq/Directory.Build.props | 2 +- .../Framework.Logging/Directory.Build.props | 2 +- .../Framework.Models/Directory.Build.props | 2 +- .../Directory.Build.props | 2 +- .../Directory.Build.props | 2 +- .../Directory.Build.props | 2 +- .../IProcessIdentityDataDetermination.cs | 2 +- .../Directory.Build.props | 2 +- .../Framework.Seeding/Directory.Build.props | 2 +- .../Framework.Swagger/Directory.Build.props | 2 +- .../Framework.Token/Directory.Build.props | 2 +- .../Framework.Web/Directory.Build.props | 2 +- .../BusinessLogic/IRealmUpdater.cs | 2 +- .../BusinessLogic/IAppChangeBusinessLogic.cs | 2 +- .../BusinessLogic/IAppsBusinessLogic.cs | 24 ++++----- .../BusinessLogic/IServiceBusinessLogic.cs | 6 +-- .../IServiceChangeBusinessLogic.cs | 2 +- .../Repositories/DocumentRepository.cs | 6 ++- .../Repositories/IConnectorsRepository.cs | 2 +- .../Repositories/IDocumentRepository.cs | 2 +- .../Repositories/IInvitationRepository.cs | 2 +- .../Repositories/IOfferRepository.cs | 4 +- .../RegistrationBusinessLogic.cs | 2 +- .../RegistrationBusinessLogicTest.cs | 6 ++- .../DocumentRepositoryTests.cs | 54 +++++++++++++++++++ .../RegistrationBusinessLogicTest.cs | 3 +- 40 files changed, 118 insertions(+), 59 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index 32d3cb283e..76908fb009 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -568,7 +568,7 @@ private void PostRegistrationCancelEmailAsync(ICollection emailData, public async Task<(string fileName, byte[] content, string contentType)> GetDocumentAsync(Guid documentId) { var document = await portalRepositories.GetInstance() - .GetDocumentByIdAsync(documentId) + .GetDocumentByIdAsync(documentId, [DocumentTypeId.COMMERCIAL_REGISTER_EXTRACT]) .ConfigureAwait(ConfigureAwaitOptions.None); if (document == null) { diff --git a/src/framework/Framework.Async/Directory.Build.props b/src/framework/Framework.Async/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Async/Directory.Build.props +++ b/src/framework/Framework.Async/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Cors/Directory.Build.props b/src/framework/Framework.Cors/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Cors/Directory.Build.props +++ b/src/framework/Framework.Cors/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.DBAccess/Directory.Build.props b/src/framework/Framework.DBAccess/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.DBAccess/Directory.Build.props +++ b/src/framework/Framework.DBAccess/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.DateTimeProvider/Directory.Build.props b/src/framework/Framework.DateTimeProvider/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.DateTimeProvider/Directory.Build.props +++ b/src/framework/Framework.DateTimeProvider/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.DependencyInjection/Directory.Build.props b/src/framework/Framework.DependencyInjection/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.DependencyInjection/Directory.Build.props +++ b/src/framework/Framework.DependencyInjection/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.ErrorHandling.Controller/Directory.Build.props b/src/framework/Framework.ErrorHandling.Controller/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.ErrorHandling.Controller/Directory.Build.props +++ b/src/framework/Framework.ErrorHandling.Controller/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.ErrorHandling.Web/Directory.Build.props b/src/framework/Framework.ErrorHandling.Web/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.ErrorHandling.Web/Directory.Build.props +++ b/src/framework/Framework.ErrorHandling.Web/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.ErrorHandling/Directory.Build.props b/src/framework/Framework.ErrorHandling/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.ErrorHandling/Directory.Build.props +++ b/src/framework/Framework.ErrorHandling/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.ErrorHandling/Service/IErrorMessageContainer.cs b/src/framework/Framework.ErrorHandling/Service/IErrorMessageContainer.cs index d32e038bdb..00458b1afa 100644 --- a/src/framework/Framework.ErrorHandling/Service/IErrorMessageContainer.cs +++ b/src/framework/Framework.ErrorHandling/Service/IErrorMessageContainer.cs @@ -21,6 +21,6 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; public interface IErrorMessageContainer { - public Type Type { get; } - public IReadOnlyDictionary MessageContainer { get; } + Type Type { get; } + IReadOnlyDictionary MessageContainer { get; } } diff --git a/src/framework/Framework.ErrorHandling/Service/IErrorMessageService.cs b/src/framework/Framework.ErrorHandling/Service/IErrorMessageService.cs index 1996ede6c0..3172d20645 100644 --- a/src/framework/Framework.ErrorHandling/Service/IErrorMessageService.cs +++ b/src/framework/Framework.ErrorHandling/Service/IErrorMessageService.cs @@ -21,8 +21,8 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; public interface IErrorMessageService { - public string GetMessage(Type type, int code); - public IEnumerable GetAllMessageTexts(); - public record ErrorMessageType(string ErrorType, IEnumerable ErrorMessages); - public record ErrorMessageCode(string ErrorCode, string Message); + string GetMessage(Type type, int code); + IEnumerable GetAllMessageTexts(); + record ErrorMessageType(string ErrorType, IEnumerable ErrorMessages); + record ErrorMessageCode(string ErrorCode, string Message); } diff --git a/src/framework/Framework.HttpClientExtensions/Directory.Build.props b/src/framework/Framework.HttpClientExtensions/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.HttpClientExtensions/Directory.Build.props +++ b/src/framework/Framework.HttpClientExtensions/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.IO/Directory.Build.props b/src/framework/Framework.IO/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.IO/Directory.Build.props +++ b/src/framework/Framework.IO/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Identity/Directory.Build.props b/src/framework/Framework.Identity/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Identity/Directory.Build.props +++ b/src/framework/Framework.Identity/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Linq/Directory.Build.props b/src/framework/Framework.Linq/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Linq/Directory.Build.props +++ b/src/framework/Framework.Linq/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Logging/Directory.Build.props b/src/framework/Framework.Logging/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Logging/Directory.Build.props +++ b/src/framework/Framework.Logging/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Models/Directory.Build.props b/src/framework/Framework.Models/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Models/Directory.Build.props +++ b/src/framework/Framework.Models/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Processes.Library.Concrete/Directory.Build.props b/src/framework/Framework.Processes.Library.Concrete/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Processes.Library.Concrete/Directory.Build.props +++ b/src/framework/Framework.Processes.Library.Concrete/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Processes.Library/Directory.Build.props b/src/framework/Framework.Processes.Library/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Processes.Library/Directory.Build.props +++ b/src/framework/Framework.Processes.Library/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Processes.ProcessIdentity/Directory.Build.props b/src/framework/Framework.Processes.ProcessIdentity/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Processes.ProcessIdentity/Directory.Build.props +++ b/src/framework/Framework.Processes.ProcessIdentity/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Processes.ProcessIdentity/IProcessIdentityDataDetermination.cs b/src/framework/Framework.Processes.ProcessIdentity/IProcessIdentityDataDetermination.cs index c468220ec8..851353d1c8 100644 --- a/src/framework/Framework.Processes.ProcessIdentity/IProcessIdentityDataDetermination.cs +++ b/src/framework/Framework.Processes.ProcessIdentity/IProcessIdentityDataDetermination.cs @@ -24,5 +24,5 @@ public interface IProcessIdentityDataDetermination /// /// Initialize IdentityData /// - public Task GetIdentityData(); + Task GetIdentityData(); } diff --git a/src/framework/Framework.Processes.Worker.Library/Directory.Build.props b/src/framework/Framework.Processes.Worker.Library/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Processes.Worker.Library/Directory.Build.props +++ b/src/framework/Framework.Processes.Worker.Library/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Seeding/Directory.Build.props b/src/framework/Framework.Seeding/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Seeding/Directory.Build.props +++ b/src/framework/Framework.Seeding/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Swagger/Directory.Build.props b/src/framework/Framework.Swagger/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Swagger/Directory.Build.props +++ b/src/framework/Framework.Swagger/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Token/Directory.Build.props b/src/framework/Framework.Token/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Token/Directory.Build.props +++ b/src/framework/Framework.Token/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/framework/Framework.Web/Directory.Build.props b/src/framework/Framework.Web/Directory.Build.props index d0ed5f9db4..c1ac6ec0fa 100644 --- a/src/framework/Framework.Web/Directory.Build.props +++ b/src/framework/Framework.Web/Directory.Build.props @@ -19,7 +19,7 @@ - 3.4.0 + 3.6.0 diff --git a/src/keycloak/Keycloak.Seeding/BusinessLogic/IRealmUpdater.cs b/src/keycloak/Keycloak.Seeding/BusinessLogic/IRealmUpdater.cs index e924f10efc..9a510e7f6d 100644 --- a/src/keycloak/Keycloak.Seeding/BusinessLogic/IRealmUpdater.cs +++ b/src/keycloak/Keycloak.Seeding/BusinessLogic/IRealmUpdater.cs @@ -21,5 +21,5 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Keycloak.Seeding.BusinessLogic; public interface IRealmUpdater { - public Task UpdateRealm(string keycloakInstanceName, CancellationToken cancellationToken); + Task UpdateRealm(string keycloakInstanceName, CancellationToken cancellationToken); } diff --git a/src/marketplace/Apps.Service/BusinessLogic/IAppChangeBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/IAppChangeBusinessLogic.cs index 5ca57126fd..59901a0894 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/IAppChangeBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/IAppChangeBusinessLogic.cs @@ -62,7 +62,7 @@ public interface IAppChangeBusinessLogic /// Deactivate Offer Status by appId /// /// Id of the app - public Task DeactivateOfferByAppIdAsync(Guid appId); + Task DeactivateOfferByAppIdAsync(Guid appId); /// /// Updates the url of the subscription diff --git a/src/marketplace/Apps.Service/BusinessLogic/IAppsBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/IAppsBusinessLogic.cs index 3b8d1e122b..719970cd6b 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/IAppsBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/IAppsBusinessLogic.cs @@ -36,13 +36,13 @@ public interface IAppsBusinessLogic /// /// Optional two character language specifier for the app description. No description if not provided. /// List of active marketplace apps. - public IAsyncEnumerable GetAllActiveAppsAsync(string? languageShortName); + IAsyncEnumerable GetAllActiveAppsAsync(string? languageShortName); /// /// Get all apps that a user has been assigned roles in. /// /// List of available apps for user. - public IAsyncEnumerable GetAllUserUserBusinessAppsAsync(); + IAsyncEnumerable GetAllUserUserBusinessAppsAsync(); /// /// Get detailed application data for a single app by id. @@ -50,25 +50,25 @@ public interface IAppsBusinessLogic /// Persistence ID of the application to be retrieved. /// Optional two character language specifier for the localization of the app description. No description if not provided. /// AppDetailsViewModel of the requested application. - public Task GetAppDetailsByIdAsync(Guid appId, string? languageShortName = null); + Task GetAppDetailsByIdAsync(Guid appId, string? languageShortName = null); /// /// Get IDs of all favourite apps of the user by ID. /// /// List of IDs of user's favourite apps. - public IAsyncEnumerable GetAllFavouriteAppsForUserAsync(); + IAsyncEnumerable GetAllFavouriteAppsForUserAsync(); /// /// Adds an app to a user's favourites. /// /// ID of the app to add to user's favourites. - public Task AddFavouriteAppForUserAsync(Guid appId); + Task AddFavouriteAppForUserAsync(Guid appId); /// /// Removes an app from a user's favourites. /// /// ID of the app to remove from user's favourites. - public Task RemoveFavouriteAppForUserAsync(Guid appId); + Task RemoveFavouriteAppForUserAsync(Guid appId); /// /// Retrieves subscription statuses of subscribed apps of the provided user's company. @@ -78,7 +78,7 @@ public interface IAppsBusinessLogic /// /// /// Returns the details of the subscription status for App user - public Task> GetCompanySubscribedAppSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId, string? name); + Task> GetCompanySubscribedAppSubscriptionStatusesForUserAsync(int page, int size, OfferSubscriptionStatusId? statusId, string? name); /// /// Retrieves subscription statuses of provided apps of the provided user's company. @@ -90,32 +90,32 @@ public interface IAppsBusinessLogic /// /// /// Async enumberable of user's company's provided apps' statuses. - public Task> GetCompanyProvidedAppSubscriptionStatusesForUserAsync(int page, int size, SubscriptionStatusSorting? sorting, OfferSubscriptionStatusId? statusId, Guid? offerId, string? companyName); + Task> GetCompanyProvidedAppSubscriptionStatusesForUserAsync(int page, int size, SubscriptionStatusSorting? sorting, OfferSubscriptionStatusId? statusId, Guid? offerId, string? companyName); /// /// Adds a subscription relation between an application and a user's company. /// /// ID of the app to subscribe to. /// The agreement consent data - public Task AddOwnCompanyAppSubscriptionAsync(Guid appId, IEnumerable offerAgreementConsentData); + Task AddOwnCompanyAppSubscriptionAsync(Guid appId, IEnumerable offerAgreementConsentData); /// /// Declines a pending app subscription of an app, provided by the current user's company. /// /// ID of the pending app to be declined. - public Task DeclineAppSubscriptionAsync(Guid subscriptionId); + Task DeclineAppSubscriptionAsync(Guid subscriptionId); /// /// Activates a pending app subscription for an app provided by the current user's company. /// /// ID of the pending app to be activated. - public Task TriggerActivateOfferSubscription(Guid subscriptionId); + Task TriggerActivateOfferSubscription(Guid subscriptionId); /// /// Unsubscribes an app for the current users company. /// /// ID of the subscription to unsubscribe from. - public Task UnsubscribeOwnCompanyAppSubscriptionAsync(Guid subscriptionId); + Task UnsubscribeOwnCompanyAppSubscriptionAsync(Guid subscriptionId); /// /// Retrieve Company Owned App Data diff --git a/src/marketplace/Services.Service/BusinessLogic/IServiceBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/IServiceBusinessLogic.cs index abcafd48a0..b518882f81 100644 --- a/src/marketplace/Services.Service/BusinessLogic/IServiceBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/IServiceBusinessLogic.cs @@ -48,7 +48,7 @@ public interface IServiceBusinessLogic /// Declines a pending service subscription of a service, provided by the current user's company. /// /// ID of the pending service to be declined. - public Task DeclineServiceSubscriptionAsync(Guid subscriptionId); + Task DeclineServiceSubscriptionAsync(Guid subscriptionId); /// /// Gets the service detail data for the given service @@ -154,12 +154,12 @@ public interface IServiceBusinessLogic /// Unsubscribes an Service for the current users company. /// /// ID of the subscription to unsubscribe from. - public Task UnsubscribeOwnCompanyServiceSubscriptionAsync(Guid subscriptionId); + Task UnsubscribeOwnCompanyServiceSubscriptionAsync(Guid subscriptionId); /// /// Activates a pending service subscription for an service provided by the current user's company. /// /// ID of the pending service to be activated. - public Task TriggerActivateOfferSubscription(Guid subscriptionId); + Task TriggerActivateOfferSubscription(Guid subscriptionId); } diff --git a/src/marketplace/Services.Service/BusinessLogic/IServiceChangeBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/IServiceChangeBusinessLogic.cs index 6299579820..c632a78f49 100644 --- a/src/marketplace/Services.Service/BusinessLogic/IServiceChangeBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/IServiceChangeBusinessLogic.cs @@ -29,5 +29,5 @@ public interface IServiceChangeBusinessLogic /// Deactivate Offer Status by serviceId /// /// Id of the service - public Task DeactivateOfferByServiceIdAsync(Guid serviceId); + Task DeactivateOfferByServiceIdAsync(Guid serviceId); } diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/DocumentRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/DocumentRepository.cs index 128f8769cb..be0ed53ff7 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/DocumentRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/DocumentRepository.cs @@ -118,8 +118,10 @@ public void RemoveDocument(Guid documentId) => dbContext.Documents.Remove(new Document(documentId, null!, null!, null!, default, default, default, default, default)); /// - public Task GetDocumentByIdAsync(Guid documentId) => - dbContext.Documents.SingleOrDefaultAsync(x => x.Id == documentId); + public Task GetDocumentByIdAsync(Guid documentId, IEnumerable documentTypeIds) => + dbContext.Documents + .Where(x => x.Id == documentId && documentTypeIds.Contains(x.DocumentTypeId)) + .SingleOrDefaultAsync(); /// public Task<(Guid DocumentId, DocumentStatusId DocumentStatusId, bool IsSameApplicationUser, DocumentTypeId documentTypeId, bool IsQueriedApplicationStatus, IEnumerable applicationId)> GetDocumentDetailsForApplicationUntrackedAsync(Guid documentId, Guid userCompanyId, IEnumerable applicationStatusIds) => diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/IConnectorsRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/IConnectorsRepository.cs index b0e1b4750f..fdc99b57f6 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/IConnectorsRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/IConnectorsRepository.cs @@ -44,7 +44,7 @@ public interface IConnectorsRepository /// Pagination.Source of connectors that allows transformation. Func?>> GetManagedConnectorsForCompany(Guid companyId); - public Task<(ConnectorData ConnectorData, bool IsProvidingOrHostCompany)> GetConnectorByIdForCompany(Guid connectorId, Guid companyId); + Task<(ConnectorData ConnectorData, bool IsProvidingOrHostCompany)> GetConnectorByIdForCompany(Guid connectorId, Guid companyId); Task<(ConnectorInformationData ConnectorInformationData, bool IsProviderUser)> GetConnectorInformationByIdForIamUser(Guid connectorId, Guid userCompanyId); diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/IDocumentRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/IDocumentRepository.cs index 8f25265633..2504cea8ee 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/IDocumentRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/IDocumentRepository.cs @@ -47,7 +47,7 @@ public interface IDocumentRepository /// /// Id of the document /// Returns the document - Task GetDocumentByIdAsync(Guid documentId); + Task GetDocumentByIdAsync(Guid documentId, IEnumerable documentTypeIds); Task<(Guid DocumentId, DocumentStatusId DocumentStatusId, IEnumerable ConsentIds, bool IsSameUser)> GetDocumentDetailsForIdUntrackedAsync(Guid documentId, Guid companyUserId); diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/IInvitationRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/IInvitationRepository.cs index 9fb6041687..10ed5e51fc 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/IInvitationRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/IInvitationRepository.cs @@ -24,7 +24,7 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositorie public interface IInvitationRepository { - public IAsyncEnumerable<(InvitationStatusId InvitationStatus, string? EmailId, IEnumerable Roles)> GetInvitedUserDetailsUntrackedAsync(Guid applicationId); + IAsyncEnumerable<(InvitationStatusId InvitationStatus, string? EmailId, IEnumerable Roles)> GetInvitedUserDetailsUntrackedAsync(Guid applicationId); Task GetInvitationStatusAsync(Guid companyUserId); void AttachAndModifyInvitations(IEnumerable<(Guid InvitationId, Action? Initialize, Action Modify)> invitations); } diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/IOfferRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/IOfferRepository.cs index 1adce71409..44fe3febfb 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/IOfferRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/IOfferRepository.cs @@ -35,7 +35,7 @@ public interface IOfferRepository /// ID of the app. /// Id of the offer type. /// Tuple of provider company details. - public Task GetOfferProviderDetailsAsync(Guid offerId, OfferTypeId offerTypeId); + Task GetOfferProviderDetailsAsync(Guid offerId, OfferTypeId offerTypeId); /// /// Adds an app to the database @@ -490,5 +490,5 @@ public interface IOfferRepository /// /// /// - public Task<(bool IsStatusActive, bool IsUserOfProvider, DocumentTypeId DocumentTypeId, DocumentStatusId DocumentStatusId)> GetOfferAssignedAppDocumentsByIdAsync(Guid offerId, Guid userCompanyId, OfferTypeId offerTypeId, Guid documentId); + Task<(bool IsStatusActive, bool IsUserOfProvider, DocumentTypeId DocumentTypeId, DocumentStatusId DocumentStatusId)> GetOfferAssignedAppDocumentsByIdAsync(Guid offerId, Guid userCompanyId, OfferTypeId offerTypeId, Guid documentId); } diff --git a/src/registration/Registration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/registration/Registration.Service/BusinessLogic/RegistrationBusinessLogic.cs index d99ddedb60..775ccbbcde 100644 --- a/src/registration/Registration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/registration/Registration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -181,7 +181,7 @@ public async Task UploadDocumentAsync(Guid applicationId, IFormFile document, Do throw ForbiddenException.Create(RegistrationErrors.REGISTRATION_FORBIDDEN_DOCUMENT_ACCESSIBLE_AFTER_ONBOARDING_PROCESS, new ErrorParameter[] { new("documentId", documentId.ToString()) }); } - var document = await documentRepository.GetDocumentByIdAsync(documentId).ConfigureAwait(ConfigureAwaitOptions.None); + var document = await documentRepository.GetDocumentByIdAsync(documentId, [DocumentTypeId.COMMERCIAL_REGISTER_EXTRACT]).ConfigureAwait(ConfigureAwaitOptions.None); if (document is null) { throw NotFoundException.Create(RegistrationErrors.REGISTRATION_DOCUMENT_NOT_EXIST, new ErrorParameter[] { new("documentId", documentId.ToString()) }); diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs index 7a66c36bc6..455eb534d4 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs @@ -912,7 +912,7 @@ public async Task GetDocumentAsync_WithValidData_ReturnsExpected() // Arrange var documentId = Guid.NewGuid(); var content = new byte[7]; - A.CallTo(() => _documentRepository.GetDocumentByIdAsync(documentId)) + A.CallTo(() => _documentRepository.GetDocumentByIdAsync(A._, A>._)) .Returns(new Document(documentId, content, content, "test.pdf", MediaTypeId.JSON, DateTimeOffset.UtcNow, DocumentStatusId.LOCKED, DocumentTypeId.APP_CONTRACT, content.Length)); // Act @@ -921,6 +921,7 @@ public async Task GetDocumentAsync_WithValidData_ReturnsExpected() // Assert result.Should().NotBeNull(); result.fileName.Should().Be("test.pdf"); + A.CallTo(() => _documentRepository.GetDocumentByIdAsync(documentId, A>.That.IsSameSequenceAs(new[] { DocumentTypeId.COMMERCIAL_REGISTER_EXTRACT }))).MustHaveHappenedOnceExactly(); } [Fact] @@ -928,7 +929,7 @@ public async Task GetDocumentAsync_WithNotExistingDocument_ThrowsNotFoundExcepti { // Arrange var documentId = Guid.NewGuid(); - A.CallTo(() => _documentRepository.GetDocumentByIdAsync(documentId)) + A.CallTo(() => _documentRepository.GetDocumentByIdAsync(A._, A>._)) .Returns(null); // Act @@ -937,6 +938,7 @@ public async Task GetDocumentAsync_WithNotExistingDocument_ThrowsNotFoundExcepti // Assert var ex = await Assert.ThrowsAsync(Act); ex.Message.Should().Be(AdministrationRegistrationErrors.REGISTRATION_NOT_DOC_NOT_EXIST.ToString()); + A.CallTo(() => _documentRepository.GetDocumentByIdAsync(documentId, A>.That.IsSameSequenceAs(new[] { DocumentTypeId.COMMERCIAL_REGISTER_EXTRACT }))).MustHaveHappenedOnceExactly(); } #endregion diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/DocumentRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/DocumentRepositoryTests.cs index 2de324f43f..189419a000 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/DocumentRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/DocumentRepositoryTests.cs @@ -76,6 +76,60 @@ public async Task CreateDocument_ReturnsExpectedDocument() #endregion + #region GetDocumentByIdAsync + + [Fact] + public async Task GetDocumentById_ReturnsExpected() + { + // Arrange + var (sut, _) = await CreateSut(); + var documentId = new Guid("9685f744-9d90-4102-a949-fcd0bb86f954"); + var documentTypeId = DocumentTypeId.CX_FRAME_CONTRACT; + + // Act + var result = await sut.GetDocumentByIdAsync(documentId, [documentTypeId]); + + // Assert + result.Should().NotBeNull().And.Match(x => + x.Id == documentId && + x.DocumentTypeId == documentTypeId && + x.MediaTypeId == MediaTypeId.PNG && + x.DocumentName == "Default_App_Image.png" + ); + } + + [Fact] + public async Task GetDocumentById_WithInvalidId_ReturnsNull() + { + // Arrange + var (sut, _) = await CreateSut(); + var documentId = Guid.NewGuid(); + var documentTypeId = DocumentTypeId.CX_FRAME_CONTRACT; + + // Act + var result = await sut.GetDocumentByIdAsync(documentId, [documentTypeId]); + + // Assert + result.Should().BeNull(); + } + + [Fact] + public async Task GetDocumentById_WithOtherDocumentTypeId_ReturnsNull() + { + // Arrange + var (sut, _) = await CreateSut(); + var documentId = new Guid("9685f744-9d90-4102-a949-fcd0bb86f954"); + var documentTypeId = DocumentTypeId.PRESENTATION; + + // Act + var result = await sut.GetDocumentByIdAsync(documentId, [documentTypeId]); + + // Assert + result.Should().BeNull(); + } + + #endregion + #region GetUploadedDocuments [Theory] diff --git a/tests/registration/Registration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs b/tests/registration/Registration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs index 5baa922387..2d37416fb6 100644 --- a/tests/registration/Registration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs +++ b/tests/registration/Registration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs @@ -3060,7 +3060,7 @@ public async Task GetDocumentAsync_WithValidData_ReturnsExpected() var content = new byte[7]; A.CallTo(() => _documentRepository.GetDocumentIdWithCompanyUserCheckAsync(documentId, _identity.IdentityId)) .Returns((documentId, true, true, false)); - A.CallTo(() => _documentRepository.GetDocumentByIdAsync(documentId)) + A.CallTo(() => _documentRepository.GetDocumentByIdAsync(A._, A>._)) .Returns(new Document(documentId, content, content, "test.pdf", MediaTypeId.PDF, DateTimeOffset.UtcNow, DocumentStatusId.LOCKED, DocumentTypeId.APP_CONTRACT, content.Length)); var sut = new RegistrationBusinessLogic(Options.Create(new RegistrationSettings()), null!, null!, null!, null!, _portalRepositories, null!, _identityService, _dateTimeProvider, _mailingProcessCreation); @@ -3071,6 +3071,7 @@ public async Task GetDocumentAsync_WithValidData_ReturnsExpected() result.Should().NotBeNull(); result.FileName.Should().Be("test.pdf"); result.MediaType.Should().Be("application/pdf"); + A.CallTo(() => _documentRepository.GetDocumentByIdAsync(documentId, A>.That.IsSameSequenceAs(new[] { DocumentTypeId.COMMERCIAL_REGISTER_EXTRACT }))).MustHaveHappenedOnceExactly(); } [Fact]