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

Added a AdaptiveCardsBuilder and changed the way we generate adaptive… #608

Merged
merged 16 commits into from
Dec 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public async Task<ActionResult<ApiCollection<ApiPersonAbsence>>> GetPersonAbsenc
r.AlwaysAccessWhen()
.CurrentUserIs(profile.Identifier)
.FullControl()
.FullControlInternal();
.FullControlInternal()
.BeTrustedApplication();


r.AnyOf(or =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using AdaptiveCards;
using Newtonsoft.Json;

namespace Fusion.Resources.Functions.ApiClients.ApiModels;
Expand All @@ -11,5 +12,5 @@ public class SendNotificationsRequest

[JsonProperty("description")] public string Description { get; set; }

[JsonProperty("card")] public object Card { get; set; }
[JsonProperty("card")] public AdaptiveCard Card { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Fusion.ApiClients.Org;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Fusion.Resources.Functions.ApiClients;

public interface IOrgClient
{
Task<ApiChangeLog> GetChangeLog(string projectId, string positionId, string instanceId);
}


#region model
public class ApiChangeLog
{
public Guid ProjectId { get; set; }
public DateTimeOffset? FirstEventDate { get; set; }
public DateTimeOffset? LastEventDate { get; set; }
public List<ApiChangeLogEvent> Events { get; set; }

}

public class ApiChangeLogEvent
{

public Guid? PositionId { get; set; }
public string? PositionName { get; set; }

Check warning on line 30 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public string? PositionExternalId { get; set; }

Check warning on line 31 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public Guid? InstanceId { get; set; }
public string Name { get; set; }
public string ChangeCategory { get; set; }
public ApiPersonV2? Actor { get; set; }

Check warning on line 35 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public DateTimeOffset TimeStamp { get; set; }
public string? Description { get; set; }

Check warning on line 37 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public string ChangeType { get; set; }
public object? PayLoad { get; set; }

Check warning on line 39 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

public ApiInstanceSnapshot? Instance { get; init; }

Check warning on line 41 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

public Guid EventId { get; set; }
public string EventFriendlyName { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public Guid? DraftId { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? ChangeSource { get; set; }

Check warning on line 49 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? ChangeSourceId { get; set; }

public class ApiInstanceSnapshot
{
public DateTime? AppliesFrom { get; set; }
public DateTime? AppliesTo { get; set; }
public double? WorkLoad { get; set; }
}
}

public class ChangeType
{
public static string PositionInstanceCreated = "PositionInstanceCreated";
public static string PersonAssignedToPosition = "PersonAssignedToPosition";
public static string PositionInstanceAllocationStateChanged = "PositionInstanceAllocationStateChanged";
public static string PositionInstanceAppliesToChanged = "PositionInstanceAppliesToChanged";
public static string PositionInstanceAppliesFromChanged = "PositionInstanceAppliesFromChanged";
public static string PositionInstanceParentPositionIdChanged = "PositionInstanceParentPositionIdChanged";
public static string PositionInstancePercentChanged = "PositionInstancePercentChanged";
public static string PositionInstanceLocationChanged = "PositionInstanceLocationChanged";
}

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IResourcesApiClient
Task<bool> ReassignRequestAsync(ResourceAllocationRequest item, string? department);
Task<IEnumerable<ResourceAllocationRequest>> GetAllRequestsForDepartment(string departmentIdentifier);
Task<IEnumerable<InternalPersonnelPerson>> GetAllPersonnelForDepartment(string departmentIdentifier);
Task<IEnumerable<ApiPersonAbsence>> GetLeaveForPersonnel(string personId);

#region Models

Expand All @@ -29,7 +30,13 @@ public class ResourceAllocationRequest
public ProposedPerson? ProposedPerson { get; set; }
public bool HasProposedPerson => ProposedPerson?.Person.AzureUniquePersonId is not null;
public string? State { get; set; }
public Workflow? workflow { get; set; }
public Workflow? Workflow { get; set; }
public DateTimeOffset Created { get; set; }
public InternalPersonnelPerson? CreatedBy { get; set; }
public DateTimeOffset? Updated { get; set; }
public InternalPersonnelPerson? UpdatedBy { get; set; }
public DateTimeOffset? LastActivity { get; set; }
public bool IsDraft { get; set; }
}

public enum RequestState
Expand All @@ -41,12 +48,9 @@ public class Workflow
{
public string LogicAppName { get; set; }
public string LogicAppVersion { get; set; }

[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public ApiWorkflowState State { get; set; }

public IEnumerable<WorkflowStep> Steps { get; set; }

public enum ApiWorkflowState { Running, Canceled, Error, Completed, Terminated, Unknown }

}
Expand All @@ -55,33 +59,27 @@ public class WorkflowStep
{
public string Id { get; set; }
public string Name { get; set; }

public bool IsCompleted => Completed.HasValue;

/// <summary>
/// Pending, Approved, Rejected, Skipped
/// </summary>
[System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(JsonStringEnumConverter))]
public ApiWorkflowStepState State { get; set; }

public DateTimeOffset? Started { get; set; }
public DateTimeOffset? Completed { get; set; }
public DateTimeOffset? DueDate { get; set; }
public InternalPersonnelPerson? CompletedBy { get; set; }
public string Description { get; set; }
public string? Reason { get; set; }

public string? PreviousStep { get; set; }
public string? NextStep { get; set; }

public enum ApiWorkflowStepState { Pending, Approved, Rejected, Skipped, Unknown }
}

public class ProposedPerson
{
public Person Person { get; set; } = null!;
public InternalPersonnelPerson Person { get; set; } = null!;
}

public class Person
{
public Guid? AzureUniquePersonId { get; set; }
Expand All @@ -98,7 +96,6 @@ public class ProjectReference

public class InternalPersonnelPerson
{

public Guid? AzureUniquePersonId { get; set; }
public string? Mail { get; set; } = null!;
public string? Name { get; set; } = null!;
Expand All @@ -110,6 +107,7 @@ public class InternalPersonnelPerson
public bool IsResourceOwner { get; set; }
public string? AccountType { get; set; }
public List<PersonnelPosition> PositionInstances { get; set; } = new List<PersonnelPosition>();
public List<ApiPersonAbsence> ApiPersonAbsences { get; set; } = new List<ApiPersonAbsence>();
}

public class PersonnelPosition
Expand All @@ -127,6 +125,32 @@ public class PersonnelPosition
public double Workload { get; set; }
public ProjectReference? Project { get; set; }
}

public class ApiPersonAbsence
{
public Guid Id { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public DateTimeOffset? Created { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public InternalPersonnelPerson? CreatedBy { get; set; }
public bool IsPrivate { get; set; }
public string? Comment { get; set; }
//public ApiTaskDetails? TaskDetails { get; set; } // Trengs denne?
public DateTimeOffset? AppliesFrom { get; set; }
public DateTimeOffset? AppliesTo { get; set; }
public ApiAbsenceType? Type { get; set; }
public double? AbsencePercentage { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool IsActive => AppliesFrom <= DateTime.UtcNow.Date && AppliesTo >= DateTime.UtcNow.Date;

}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum ApiAbsenceType { Absence, Vacation, OtherTasks }



#endregion Models
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Fusion.Resources.Functions.ApiClients.ApiModels;
using Fusion.Resources.Functions.Integration;

namespace Fusion.Resources.Functions.ApiClients;

public class OrgClient : IOrgClient
{
private readonly HttpClient orgClient;

public OrgClient(IHttpClientFactory httpClientFactory)
{
orgClient = httpClientFactory.CreateClient(HttpClientNames.Application.Org);
orgClient.Timeout = TimeSpan.FromMinutes(5);
}

public async Task<ApiChangeLog> GetChangeLog(string projectId, string positionId, string instanceId)
{
var data =
await orgClient.GetAsJsonAsync<ApiChangeLog>($"/projects/{projectId}/positions/{positionId}/instances/{instanceId}/change-log?api-version=2.0");

return data;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public async Task<IEnumerable<InternalPersonnelPerson>> GetAllPersonnelForDepart
return response.Value.ToList();
}

public async Task<IEnumerable<ApiPersonAbsence>> GetLeaveForPersonnel(string personId)
{
var response = await resourcesClient.GetAsJsonAsync<InternalCollection<ApiPersonAbsence>>(
$"persons/{personId}/absence");

return response.Value.ToList();
}

public async Task<bool> ReassignRequestAsync(ResourceAllocationRequest item, string? department)
{
var content = JsonConvert.SerializeObject(new { AssignedDepartment = department });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public static IServiceCollection AddHttpClients(this IServiceCollection services
builder.AddNotificationsClient();
services.AddScoped<INotificationApiClient, NotificationApiClient>();

builder.AddOrgClient();
services.AddScoped<IOrgClient, OrgClient>();

return services;
}
}
Expand Down

This file was deleted.

Loading
Loading