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

EN-376 Add contributors and note to language variants #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion Kontent.Ai.Management.Tests/CodeSamples/CmApiV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,15 @@ public async void PutVariantWorkflow()
var exception = await Record.ExceptionAsync(async () =>
await client.ChangeLanguageVariantWorkflowAsync(
new LanguageVariantIdentifier(itemIdentifier, languageIdentifier),
new WorkflowStepIdentifier(Reference.ById(Guid.Empty), workflowStepIdentifier)
new ChangeLanguageVariantWorkflowModel(Reference.ById(Guid.Empty), workflowStepIdentifier)
{
DueDate = new DueDateModel
{
Value = DateTime.UtcNow.AddDays(42)
},
Contributors = new List<UserIdentifier> { UserIdentifier.ByEmail("[email protected]") },
Note = "Moving this to the next workflow step."
}
));
Assert.Null(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
},
Expand Down Expand Up @@ -363,6 +369,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "00000000-0000-0000-0000-000000000000"
},
Expand Down Expand Up @@ -364,6 +370,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "00000000-0000-0000-0000-000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "10000000-0000-0000-0000-000000000000"
},
Expand Down Expand Up @@ -364,6 +370,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "10000000-0000-0000-0000-000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "20000000-0000-0000-0000-000000000000"
},
Expand Down Expand Up @@ -367,6 +373,12 @@
"due_date": {
"value": "2092-01-07T06:04:00.7069564Z"
},
"contributors": [
{
"id": "4b628214-e4fe-4fe0-b1ff-955df33e1515"
}
],
"note": "Just a note",
"item": {
"id": "20000000-0000-0000-0000-000000000000"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ private static LanguageVariantModel GetExpectedLanguageVariantModel(
Workflow = new WorkflowStepIdentifier(Reference.ById(Guid.Parse("00000000-0000-0000-0000-000000000000")), Reference.ById(Guid.Parse("eee6db3b-545a-4785-8e86-e3772c8756f9"))),
Schedule = GetExpectedScheduleResponseModel(),
DueDate = GetExpectedDueDateModel(),
Contributors = GetExpectedContributors(),
Note = "Just a note",
Elements = ElementsData.GetExpectedDynamicElements(),
};

Expand All @@ -544,6 +546,8 @@ private static LanguageVariantModel<ComplexTestModel> GetExpectedComplexTestMode
Workflow = new WorkflowStepIdentifier(Reference.ById(Guid.Parse("00000000-0000-0000-0000-000000000000")), Reference.ById(Guid.Parse("eee6db3b-545a-4785-8e86-e3772c8756f9"))),
Schedule = GetExpectedScheduleResponseModel(),
DueDate = GetExpectedDueDateModel(),
Contributors = GetExpectedContributors(),
Note = "Just a note",
Elements = ElementsData.GetExpectedStronglyTypedElementsModel(),
};

Expand All @@ -558,6 +562,9 @@ private static LanguageVariantModel<ComplexTestModel> GetExpectedComplexTestMode
private static DueDateModel GetExpectedDueDateModel() =>
new() { Value = DateTimeOffset.Parse("2092-01-07T06:04:00.7069564Z").UtcDateTime };

private static List<UserIdentifier> GetExpectedContributors() =>
new List<UserIdentifier>() { UserIdentifier.ById("4b628214-e4fe-4fe0-b1ff-955df33e1515") };

private class CombinationOfIdentifiersAndUrl : IEnumerable<object[]>
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Kontent.Ai.Management.Models.LanguageVariants;
using Kontent.Ai.Management.Models.Publishing;
using Kontent.Ai.Management.Models.Shared;
using Kontent.Ai.Management.Models.Workflow;
using Kontent.Ai.Management.Tests.Base;
using System;
using System.Collections;
Expand All @@ -28,18 +27,18 @@ public async void ChangeLanguageVariantWorkflowAsync_ChangesWorkflow(LanguageVar
{
var client = _scenario.CreateManagementClient();

var workflowIdentifier = new WorkflowStepIdentifier
var model = new ChangeLanguageVariantWorkflowModel
(
workflowIdentifier: Reference.ById(Guid.NewGuid()),
stepIdentifier: Reference.ById(Guid.NewGuid())
);

await client.ChangeLanguageVariantWorkflowAsync(variantIdentifier, workflowIdentifier);
await client.ChangeLanguageVariantWorkflowAsync(variantIdentifier, model);

_scenario
.CreateExpectations()
.HttpMethod(HttpMethod.Put)
.RequestPayload(workflowIdentifier)
.RequestPayload(model)
.Url($"{expectedUrl}/change-workflow")
.Validate();
}
Expand All @@ -49,13 +48,13 @@ public async void ChangeLanguageVariantWorkflowAsync_NoIdentifier_Throws()
{
var client = _scenario.CreateManagementClient();

var workflowIdentifier = new WorkflowStepIdentifier
var model = new ChangeLanguageVariantWorkflowModel
(
workflowIdentifier: Reference.ById(Guid.NewGuid()),
stepIdentifier: Reference.ById(Guid.NewGuid())
);

await client.Invoking(x => x.ChangeLanguageVariantWorkflowAsync(null, workflowIdentifier)).Should().ThrowAsync<ArgumentNullException>();
await client.Invoking(x => x.ChangeLanguageVariantWorkflowAsync(null, model)).Should().ThrowAsync<ArgumentNullException>();
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions Kontent.Ai.Management/IManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public interface IManagementClient
/// Changes workflow.
/// </summary>
/// <param name="identifier">Identifier of the language variant to be changed.</param>
/// <param name="workflowStepIdentifier">Workflow step identifier to set.</param>
Task ChangeLanguageVariantWorkflowAsync(LanguageVariantIdentifier identifier, WorkflowStepIdentifier workflowStepIdentifier);
/// <param name="changeModel">Change language variant workflow model.</param>
Task ChangeLanguageVariantWorkflowAsync(LanguageVariantIdentifier identifier, ChangeLanguageVariantWorkflowModel changeModel);

/// <summary>
/// Creates the asset folder.
Expand Down
7 changes: 3 additions & 4 deletions Kontent.Ai.Management/ManagementClient.Publishing.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Kontent.Ai.Management.Models.LanguageVariants;
using Kontent.Ai.Management.Models.Publishing;
using Kontent.Ai.Management.Models.Workflow;
using System;
using System.Net.Http;
using System.Threading.Tasks;
Expand All @@ -13,15 +12,15 @@ namespace Kontent.Ai.Management;
public sealed partial class ManagementClient
{
/// <inheritdoc />
public async Task ChangeLanguageVariantWorkflowAsync(LanguageVariantIdentifier identifier, WorkflowStepIdentifier workflowStepIdentifier)
public async Task ChangeLanguageVariantWorkflowAsync(LanguageVariantIdentifier identifier, ChangeLanguageVariantWorkflowModel changeModel)
{
ArgumentNullException.ThrowIfNull(identifier);

ArgumentNullException.ThrowIfNull(workflowStepIdentifier);
ArgumentNullException.ThrowIfNull(changeModel);

var endpointUrl = _urlBuilder.BuildWorkflowChangeUrl(identifier);

await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, workflowStepIdentifier);
await _actionInvoker.InvokeMethodAsync(endpointUrl, HttpMethod.Put, changeModel);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Kontent.Ai.Management.Models.Shared;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Kontent.Ai.Management.Models.LanguageVariants;

/// <summary>
/// Represents a change language variant workflow model.
/// </summary>
public sealed class ChangeLanguageVariantWorkflowModel
{
/// <summary>
/// Represents the identifier of the workflow.
/// </summary>
[JsonProperty("workflow_identifier")]
public Reference Workflow { get; set; }

/// <summary>
/// Represents the identifier of the step in the workflow.
/// </summary>
[JsonProperty("step_identifier")]
public Reference Step { get; set; }

/// <summary>
/// Gets or sets due date.
/// </summary>
[JsonProperty("due_date")]
public DueDateModel DueDate { get; set; }

/// <summary>
/// Gets or sets a note.
/// </summary>
[JsonProperty("note")]
public string Note { get; set; }

/// <summary>
/// Gets or sets the contributors.
/// </summary>
[JsonProperty("contributors")]
public IEnumerable<UserIdentifier> Contributors { get; set; }

/// <summary>
/// Creates an instance of the change language variant workflow model.
/// </summary>
/// <param name="workflowIdentifier">The identifier of the workflow.</param>
/// <param name="stepIdentifier">The identifier of the workflow step.</param>
public ChangeLanguageVariantWorkflowModel(Reference workflowIdentifier, Reference stepIdentifier)
{
Workflow = workflowIdentifier;
Step = stepIdentifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@ public sealed class LanguageVariantModel
/// </summary>
[JsonProperty("due_date")]
public DueDateModel DueDate { get; set; }

/// <summary>
/// Gets or sets a note.
/// </summary>
[JsonProperty("note")]
public string Note { get; set; }

/// <summary>
/// Gets or sets the contributors.
/// </summary>
[JsonProperty("contributors")]
public IEnumerable<UserIdentifier> Contributors { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Kontent.Ai.Management.Models.Workflow;
using Kontent.Ai.Management.Models.Shared;
using Kontent.Ai.Management.Models.Workflow;
using Newtonsoft.Json;
using System.Collections.Generic;

Expand All @@ -25,6 +26,18 @@ public sealed class LanguageVariantUpsertModel
/// </summary>
public DueDateModel DueDate { get; set; }

/// <summary>
/// Gets or sets a note.
/// </summary>
[JsonProperty("note")]
public string Note { get; set; }

/// <summary>
/// Gets or sets the contributors.
/// </summary>
[JsonProperty("contributors")]
public IEnumerable<UserIdentifier> Contributors { get; set; }

/// <summary>
/// Creates an instance of the language variant upsert model.
/// </summary>
Expand All @@ -37,5 +50,7 @@ internal LanguageVariantUpsertModel(LanguageVariantModel languageVariant)
Elements = languageVariant.Elements;
Workflow = languageVariant.Workflow;
DueDate = languageVariant.DueDate;
Note = languageVariant.Note;
Contributors = languageVariant.Contributors;
}
}
6 changes: 5 additions & 1 deletion Kontent.Ai.Management/Models/Shared/UserIdentifier.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Kontent.Ai.Management.Models.Shared;
using Newtonsoft.Json;

namespace Kontent.Ai.Management.Models.Shared;

/// <summary>
/// Represents identifier of users.
Expand All @@ -10,11 +12,13 @@ private UserIdentifier() { }
/// <summary>
/// Gets the id of the identifier.
/// </summary>
[JsonProperty("id", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Id { get; private set; }

/// <summary>
/// Gets the email of the identifier.
/// </summary>
[JsonProperty("email", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Email { get; private set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Kontent.Ai.Management.Models.Workflow;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace Kontent.Ai.Management.Models.StronglyTyped;

Expand Down Expand Up @@ -53,4 +54,16 @@ namespace Kontent.Ai.Management.Models.StronglyTyped;
/// </summary>
[JsonProperty("due_date")]
public DueDateModel DueDate { get; set; }

/// <summary>
/// Gets or sets a note.
/// </summary>
[JsonProperty("note")]
public string Note { get; set; }

/// <summary>
/// Gets or sets the contributors.
/// </summary>
[JsonProperty("contributors")]
public IEnumerable<UserIdentifier> Contributors { get; set; }
}
Loading
Loading