Skip to content

Commit

Permalink
feat(ssi): adjust identityId to string
Browse files Browse the repository at this point in the history
adjust the identityId to string to be able to save the clientId of a technical user
  • Loading branch information
Phil91 committed Apr 19, 2024
1 parent d193c71 commit d8f555f
Show file tree
Hide file tree
Showing 47 changed files with 2,779 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ private static async ValueTask HandleDecline(
IPortalService portalService,
CancellationToken cancellationToken)
{
var content = JsonSerializer.Serialize(new { Type = data.VerifiedCredentialTypeId, CredentialId = data.Id }, Options);
await portalService.AddNotification(content, data.RequesterId, NotificationTypeId.CREDENTIAL_REJECTED, cancellationToken);
companySsiDetailsRepository.AttachAndModifyCompanySsiDetails(data.Id, c =>
{
c.CompanySsiDetailStatusId = data.CompanySsiDetailStatusId;
Expand All @@ -140,13 +138,19 @@ private static async ValueTask HandleDecline(
c.CompanySsiDetailStatusId = CompanySsiDetailStatusId.INACTIVE;
});

var typeValue = data.VerifiedCredentialTypeId.GetEnumValue() ?? throw new UnexpectedConditionException($"VerifiedCredentialType {data.VerifiedCredentialTypeId} does not exists");
var mailParameters = new Dictionary<string, string>
if (Guid.TryParse(data.RequesterId, out var requesterId))
{
{ "requestName", typeValue },
{ "reason", "The credential is already expired" }
};
await portalService.TriggerMail("CredentialRejected", data.RequesterId, mailParameters, cancellationToken);
var content = JsonSerializer.Serialize(new { Type = data.VerifiedCredentialTypeId, CredentialId = data.Id }, Options);
await portalService.AddNotification(content, requesterId, NotificationTypeId.CREDENTIAL_REJECTED, cancellationToken);

var typeValue = data.VerifiedCredentialTypeId.GetEnumValue() ?? throw new UnexpectedConditionException($"VerifiedCredentialType {data.VerifiedCredentialTypeId} does not exists");
var mailParameters = new Dictionary<string, string>
{
{ "requestName", typeValue },
{ "reason", "The credential is already expired" }
};
await portalService.TriggerMail("CredentialRejected", requesterId, mailParameters, cancellationToken);
}
}

private static async ValueTask HandleNotification(
Expand Down Expand Up @@ -182,15 +186,19 @@ private static async ValueTask HandleNotification(
CredentialId = data.Id,
ExpiryCheckTypeId = newExpiryCheckTypeId
}, Options);
await portalService.AddNotification(content, data.RequesterId, NotificationTypeId.CREDENTIAL_EXPIRY, cancellationToken);
var typeValue = data.VerifiedCredentialTypeId.GetEnumValue() ?? throw new UnexpectedConditionException($"VerifiedCredentialType {data.VerifiedCredentialTypeId} does not exists");
var mailParameters = new Dictionary<string, string>

if (Guid.TryParse(data.RequesterId, out var requesterId))
{
{ "typeId", typeValue },
{ "version", data.DetailVersion ?? "no version" },
{ "expiryDate", data.ExpiryDate?.ToString("dd MMMM yyyy") ?? throw new ConflictException("Expiry Date must be set here") }
};
await portalService.AddNotification(content, requesterId, NotificationTypeId.CREDENTIAL_EXPIRY, cancellationToken);
var typeValue = data.VerifiedCredentialTypeId.GetEnumValue() ?? throw new UnexpectedConditionException($"VerifiedCredentialType {data.VerifiedCredentialTypeId} does not exists");
var mailParameters = new Dictionary<string, string>
{
{ "typeId", typeValue },
{ "version", data.DetailVersion ?? "no version" },
{ "expiryDate", data.ExpiryDate?.ToString("dd MMMM yyyy") ?? throw new ConflictException("Expiry Date must be set here") }
};

await portalService.TriggerMail("CredentialExpiry", data.RequesterId, mailParameters, cancellationToken);
await portalService.TriggerMail("CredentialExpiry", requesterId, mailParameters, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Org.Eclipse.TractusX.SsiCredentialIssuer.DBAccess.Models;

public record CredentialExpiryData(
Guid Id,
Guid RequesterId,
string RequesterId,
DateTimeOffset? ExpiryDate,
ExpiryCheckTypeId? ExpiryCheckTypeId,
string? DetailVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public IAsyncEnumerable<SsiCertificateTransferData> GetSsiCertificates(string bp
.ToAsyncEnumerable();

/// <inheritdoc />
public CompanySsiDetail CreateSsiDetails(string bpnl, VerifiedCredentialTypeId verifiedCredentialTypeId, CompanySsiDetailStatusId companySsiDetailStatusId, string issuerBpn, Guid userId, Action<CompanySsiDetail>? setOptionalFields)
public CompanySsiDetail CreateSsiDetails(string bpnl, VerifiedCredentialTypeId verifiedCredentialTypeId, CompanySsiDetailStatusId companySsiDetailStatusId, string issuerBpn, string userId, Action<CompanySsiDetail>? setOptionalFields)
{
var detail = new CompanySsiDetail(Guid.NewGuid(), bpnl, verifiedCredentialTypeId, companySsiDetailStatusId, issuerBpn, userId, DateTimeOffset.UtcNow);
setOptionalFields?.Invoke(detail);
Expand Down Expand Up @@ -216,7 +216,7 @@ public IQueryable<CompanySsiDetail> GetAllCredentialDetails(CompanySsiDetailStat
/// <inheritdoc />
public void AttachAndModifyCompanySsiDetails(Guid id, Action<CompanySsiDetail>? initialize, Action<CompanySsiDetail> updateFields)
{
var entity = new CompanySsiDetail(id, null!, default, default, null!, Guid.Empty, DateTimeOffset.MinValue);
var entity = new CompanySsiDetail(id, null!, default, default, null!, null!, DateTimeOffset.MinValue);
initialize?.Invoke(entity);
_context.Attach(entity);
updateFields.Invoke(entity);
Expand Down Expand Up @@ -270,7 +270,7 @@ public IAsyncEnumerable<CredentialExpiryData> GetExpiryData(DateTimeOffset now,
}

public void RemoveSsiDetail(Guid companySsiDetailId) =>
_context.CompanySsiDetails.Remove(new CompanySsiDetail(companySsiDetailId, null!, default, default, null!, Guid.Empty, DateTimeOffset.MinValue));
_context.CompanySsiDetails.Remove(new CompanySsiDetail(companySsiDetailId, null!, default, default, null!, null!, DateTimeOffset.MinValue));

public void CreateProcessData(Guid companySsiDetailId, JsonDocument schema, VerifiedCredentialTypeKindId credentialTypeKindId, Action<CompanySsiProcessData>? setOptionalFields)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface ICompanySsiDetailsRepository
/// <param name="userId">Id of the creator</param>
/// <param name="setOptionalFields">sets the optional fields</param>
/// <returns>The created entity</returns>
CompanySsiDetail CreateSsiDetails(string bpnl, VerifiedCredentialTypeId verifiedCredentialTypeId, CompanySsiDetailStatusId companySsiDetailStatusId, string issuerBpn, Guid userId, Action<CompanySsiDetail>? setOptionalFields);
CompanySsiDetail CreateSsiDetails(string bpnl, VerifiedCredentialTypeId verifiedCredentialTypeId, CompanySsiDetailStatusId companySsiDetailStatusId, string issuerBpn, string userId, Action<CompanySsiDetail>? setOptionalFields);

/// <summary>
/// Checks whether the credential details are already exists for the company and the given version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/********************************************************************************
* Copyright (c) 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.SsiCredentialIssuer.Entities.Auditing;
using Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Auditing.Enums;
using Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Enums;
using System.ComponentModel.DataAnnotations;

namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.AuditEntities;

public class AuditCompanySsiDetail20240419 : IAuditEntityV2
{
/// <inheritdoc />
[Key]
public Guid AuditV2Id { get; set; }

public Guid Id { get; set; }
public string Bpnl { get; set; } = null!;
public string IssuerBpn { get; set; } = null!;
public VerifiedCredentialTypeId VerifiedCredentialTypeId { get; set; }
public CompanySsiDetailStatusId CompanySsiDetailStatusId { get; set; }
public DateTimeOffset DateCreated { get; private set; }
public string CreatorUserId { get; set; }

Check warning on line 39 in src/database/SsiCredentialIssuer.Entities/AuditEntities/AuditCompanySsiDetail20240419.cs

View workflow job for this annotation

GitHub Actions / build (7.0)

Non-nullable property 'CreatorUserId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 39 in src/database/SsiCredentialIssuer.Entities/AuditEntities/AuditCompanySsiDetail20240419.cs

View workflow job for this annotation

GitHub Actions / build (7.0)

Non-nullable property 'CreatorUserId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public DateTimeOffset? ExpiryDate { get; set; }
public Guid? VerifiedCredentialExternalTypeDetailVersionId { get; set; }

public ExpiryCheckTypeId? ExpiryCheckTypeId { get; set; }
public Guid? ProcessId { get; set; }
public Guid? ExternalCredentialId { get; set; }
public string? Credential { get; set; }
public DateTimeOffset? DateLastChanged { get; set; }
public string? LastEditorId { get; set; }

/// <inheritdoc />
public string? AuditV2LastEditorId { get; set; }

/// <inheritdoc />
public AuditOperationId AuditV2OperationId { get; set; }

/// <inheritdoc />
public DateTimeOffset AuditV2DateLastChanged { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/********************************************************************************
* Copyright (c) 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.SsiCredentialIssuer.Entities.Auditing;
using Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Auditing.Enums;
using Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Enums;
using System.ComponentModel.DataAnnotations;

namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.AuditEntities;

public class AuditDocument20240419 : IAuditEntityV2
{
/// <inheritdoc />
[Key]
public Guid AuditV2Id { get; set; }

public Guid Id { get; private set; }

public DateTimeOffset? DateCreated { get; private set; }

public byte[]? DocumentHash { get; set; }

public byte[]? DocumentContent { get; set; }

public string? DocumentName { get; set; }

public MediaTypeId? MediaTypeId { get; set; }

public DocumentTypeId? DocumentTypeId { get; set; }

public DocumentStatusId? DocumentStatusId { get; set; }

public string? CompanyUserId { get; set; }
public DateTimeOffset? DateLastChanged { get; set; }
public string? LastEditorId { get; private set; }

/// <inheritdoc />
public DateTimeOffset AuditV2DateLastChanged { get; set; }

/// <inheritdoc />
public string? AuditV2LastEditorId { get; set; }

/// <inheritdoc />
public AuditOperationId AuditV2OperationId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/********************************************************************************
* Copyright (c) 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
********************************************************************************/

namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Auditing.Attributes;

/// <summary>
/// Attribute to Provide the needed methods to setup an audit trigger
/// </summary>
/// <remarks>
/// The implementation of this Attribute must not be changed.
/// When changes are needed create a V3 of it.
/// </remarks>
[AttributeUsage(AttributeTargets.Class)]
public class AuditEntityV2Attribute : Attribute
{
public AuditEntityV2Attribute(Type auditEntityType)
{
if (!typeof(IAuditEntityV2).IsAssignableFrom(auditEntityType))
{
throw new ArgumentException($"Entity must derive from {nameof(IAuditEntityV2)}", nameof(auditEntityType));
}

AuditEntityType = auditEntityType;

Check warning

Code scanning / CodeQL

Virtual call in constructor or destructor Warning

Avoid virtual calls in a constructor or destructor.
}

public virtual Type AuditEntityType { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/********************************************************************************
* Copyright (c) 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
********************************************************************************/

namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Auditing.Attributes;

/// <summary>
/// Attribute to mark the creators id in the base class.
/// The usage is optional. If not set <see cref="LastEditorV2Attribute"/>
/// is being used to determine the creators id.
/// </summary>
/// <remarks>
/// The implementation of this Attribute must not be changed.
/// When changes are needed create a V3 of it.
/// </remarks>
[AttributeUsage(AttributeTargets.Property)]
public class AuditInsertEditorV2Attribute : Attribute
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/********************************************************************************
* Copyright (c) 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
********************************************************************************/

namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Auditing.Attributes;

/// <summary>
/// Attribute to mark the last editor id in the base class
/// </summary>
/// <remarks>
/// The implementation of this Attribute must not be changed.
/// When changes are needed create a V3 of it.
/// </remarks>
[AttributeUsage(AttributeTargets.Property)]
public class LastChangedV2Attribute : Attribute
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/********************************************************************************
* Copyright (c) 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
********************************************************************************/

namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Auditing.Attributes;

/// <summary>
/// Attribute to mark the last editor id in the base class
/// </summary>
/// <remarks>
/// The implementation of this Attribute must not be changed.
/// When changes are needed create a V3 of it.
/// </remarks>
[AttributeUsage(AttributeTargets.Property)]
public class LastEditorV2Attribute : Attribute
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class AuditingDependencyInjection
public static IServiceCollection AddDbAuditing(this IServiceCollection services)
{
return services
.AddTransient<IAuditHandler, AuditHandlerV1>()
.AddTransient<IAuditHandler, AuditHandlerV2>()
.AddTransient<IDateTimeProvider, UtcDateTimeProvider>();
}
}
Loading

0 comments on commit d8f555f

Please sign in to comment.