Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(postcertificate): post company certificates #489

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public CompanyDataSettings()
{
UseCaseParticipationMediaTypes = null!;
SsiCertificateMediaTypes = null!;
CompanyCertificateMediaTypes = null!;
}

/// <summary>
Expand All @@ -48,6 +49,14 @@ public CompanyDataSettings()
[DistinctValues]
public IEnumerable<MediaTypeId> SsiCertificateMediaTypes { get; set; }

/// <summary>
/// The media types that are allowed for the uploaded document for company certificate
/// </summary>
[Required]
[EnumEnumeration]
[DistinctValues]
public IEnumerable<MediaTypeId> CompanyCertificateMediaTypes { get; set; }

/// <summary>
/// The maximum page size
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public interface ICompanyDataBusinessLogic
Task RejectCredential(Guid credentialId);

IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes();

Task CreateCompanyCertificate(CompanyCertificateCreationData data, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/********************************************************************************
* Copyright (c) 2021, 2023 BMW Group AG
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -268,6 +267,31 @@ public async Task<NoContentResult> CreateSsiCertificate([FromForm] SsiCertificat
return NoContent();
}

/// <summary>
/// Creates the Company Certificate request
/// </summary>
/// <param name="data">The type and document</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <returns>The id of the created Company certificate request</returns>
/// <remarks>Example: POST: api/administration/companydata/companyCertificate</remarks>
/// <response code="204">Successfully created the Company certificate request.</response>
/// <response code="400">
/// </response>
[HttpPost]
[Consumes("multipart/form-data")]
[Authorize(Roles = "upload_certificates")]
[Authorize(Policy = PolicyTypes.ValidIdentity)]
[Authorize(Policy = PolicyTypes.ValidCompany)]
[RequestFormLimits(ValueLengthLimit = 2000000, MultipartBodyLengthLimit = 2000000)]
[Route("companyCertificate")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
public async Task<NoContentResult> CreateCompanyCertificate([FromForm] CompanyCertificateCreationData data, CancellationToken cancellationToken)
{
await _logic.CreateCompanyCertificate(data, cancellationToken).ConfigureAwait(false);
return NoContent();
}

/// <summary>
/// Gets all outstanding, existing and inactive credentials
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/********************************************************************************
* Copyright (c) 2021, 2024 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.PortalBackend.PortalEntities.Enums;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;

public record CompanyCertificateCreationData
(
CompanyCertificateTypeId CertificateType,
IFormFile Document,
DateTimeOffset? ExpiryDate
);
3 changes: 2 additions & 1 deletion src/administration/Administration.Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@
"CompanyData": {
"MaxPageSize": 20,
"UseCaseParticipationMediaTypes": [],
"SsiCertificateMediaTypes": []
"SsiCertificateMediaTypes": [],
"CompanyCertificateMediaTypes":[]
},
"Network2Network": {
"InitialRoles": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class PortalRepositories : IPortalRepositories
{ typeof(IUserBusinessPartnerRepository), context => new UserBusinessPartnerRepository(context) },
{ typeof(IUserRepository), context => new UserRepository(context) },
{ typeof(IUserRolesRepository), context => new UserRolesRepository(context) },
{ typeof(ICompanyCertificateRepository), context => new CompanyCertificateRepository(context) },
}.ToImmutableDictionary();

public PortalRepositories(PortalDbContext portalDbContext)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/********************************************************************************
* Copyright (c) 2021, 2024 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 Microsoft.EntityFrameworkCore;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;

public class CompanyCertificateRepository : ICompanyCertificateRepository
{
private readonly PortalDbContext _context;

/// <summary>
/// Constructor.
/// </summary>
/// <param name="portalDbContext">Portal DB context.</param>
public CompanyCertificateRepository(PortalDbContext portalDbContext)
{
_context = portalDbContext;
}

public Task<bool> CheckCompanyCertificateType(CompanyCertificateTypeId certificateTypeId) =>
Phil91 marked this conversation as resolved.
Show resolved Hide resolved
_context.CompanyCertificateTypes
.AnyAsync(x =>
x.CompanyCertificateTypeAssignedStatus!.CompanyCertificateTypeStatusId == CompanyCertificateTypeStatusId.ACTIVE &&
x.Id == certificateTypeId);

/// <inheritdoc />
public CompanyCertificate CreateCompanyCertificate(Guid companyId, CompanyCertificateTypeId companyCertificateTypeId, Guid docId, Action<CompanyCertificate>? setOptionalFields)
{
var companyCertificate = new CompanyCertificate(Guid.NewGuid(), DateTimeOffset.UtcNow, companyCertificateTypeId, CompanyCertificateStatusId.ACTIVE, companyId, docId);
setOptionalFields?.Invoke(companyCertificate);
return _context.CompanyCertificates.Add(companyCertificate).Entity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/********************************************************************************
* Copyright (c) 2021, 2024 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.PortalBackend.PortalEntities;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;

public interface ICompanyCertificateRepository
{
/// <summary>
/// Checks whether the given CertificateType is a <see cref="CompanyCertificateTypeId"/> Certificate
/// </summary>
/// <param name="certificateTypeId">Id of the credentialTypeId</param>
/// <returns><c>true</c> if the tpye is a certificate, otherwise <c>false</c></returns>
Task<bool> CheckCompanyCertificateType(CompanyCertificateTypeId certificateTypeId);

/// <summary>
/// Creates the company certificate data
/// </summary>
/// <param name="companyId">Id of the company</param>
/// <param name="companyCertificateTypeId">Id of the company certificate types</param>
/// <param name="docId">id of the document</param>
/// <param name="setOptionalFields">Action to set optional fields</param>
/// <returns>The created entity</returns>
CompanyCertificate CreateCompanyCertificate(Guid companyId, CompanyCertificateTypeId companyCertificateTypeId, Guid docId, Action<CompanyCertificate>? setOptionalFields = null);
}
Loading
Loading