Skip to content

Commit

Permalink
Integration of Content Workflow API dnnsoftware#6115
Browse files Browse the repository at this point in the history
  • Loading branch information
tvatavuk committed Oct 10, 2024
1 parent 86753e4 commit 04efa70
Show file tree
Hide file tree
Showing 53 changed files with 3,101 additions and 1,723 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private static string GetPortalSettingThroughReflection(int? portalId, string se
{
if (portalId.HasValue)
{
var method = PortalControllerType.GetMethod("GetPortalSettingsDictionary");
var method = PortalControllerType.GetMethod("GetPortalSettingsDictionary", BindingFlags.NonPublic | BindingFlags.Static);
var dictionary = (Dictionary<string, string>)method.Invoke(null, new object[] { portalId.Value });
string value;
if (dictionary.TryGetValue(settingKey, out value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ namespace DotNetNuke.Web.InternalServices
using System.Net.Http;
using System.Web.Http;

using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Content.Workflow;
using DotNetNuke.Entities.Content.Workflow.Dto;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Framework;
using DotNetNuke.Internal.SourceGenerators;
using DotNetNuke.Services.Exceptions;
Expand Down Expand Up @@ -100,5 +102,91 @@ public HttpResponseMessage Approve(NotificationDTO postData)

return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");
}

[HttpPost]
[ValidateAntiForgeryToken]
public HttpResponseMessage CompleteState()
{
try
{
this.workflowEngine.CompleteState(this.BuildStateTransaction());
return this.Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
}
catch (Exception exc)
{
Exceptions.LogException(exc);
}

return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");
}

[HttpPost]
[ValidateAntiForgeryToken]
public HttpResponseMessage DiscardState()
{
try
{
this.workflowEngine.DiscardState(this.BuildStateTransaction());
return this.Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
}
catch (Exception exc)
{
Exceptions.LogException(exc);
}

return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");
}

[HttpPost]
[ValidateAntiForgeryToken]
public HttpResponseMessage CompleteWorkflow()
{
try
{
this.workflowEngine.CompleteWorkflow(this.BuildStateTransaction());
return this.Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
}
catch (Exception exc)
{
Exceptions.LogException(exc);
}

return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");
}

[HttpPost]
[ValidateAntiForgeryToken]
public HttpResponseMessage DiscardWorkflow()
{
try
{
this.workflowEngine.DiscardWorkflow(this.BuildStateTransaction());
return this.Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
}
catch (Exception exc)
{
Exceptions.LogException(exc);
}

return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");
}

private StateTransaction BuildStateTransaction()
{
var portalId = this.PortalSettings.PortalId;
var tabId = this.Request.FindTabId();
var currentPage = TabController.Instance.GetTab(tabId, portalId);
var contentItemId = currentPage.ContentItemId;
var contentController = Util.GetContentController();
var contentItem = contentController.GetContentItem(contentItemId);
var stateTransaction = new StateTransaction
{
ContentItemId = contentItem.ContentItemId,
CurrentStateId = contentItem.StateID,
Message = new StateTransactionMessage(),
UserId = this.UserInfo.UserID,
};
return stateTransaction;
}
}
}
6 changes: 6 additions & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@
<Compile Include="Entities\Content\Taxonomy\TermHelper.cs" />
<Compile Include="Entities\Modules\BusinessControllerProvider.cs" />
<Compile Include="Entities\Modules\BusinessControllerProviderExtensions.cs" />
<Compile Include="Entities\Content\Workflow\Actions\TabActions\CompleteState.cs" />
<Compile Include="Entities\Content\Workflow\Actions\TabActions\CompleteWorkflow.cs" />
<Compile Include="Entities\Content\Workflow\Actions\TabActions\DiscardState.cs" />
<Compile Include="Entities\Content\Workflow\Actions\TabActions\DiscardWorkflow.cs" />
<Compile Include="Entities\Content\Workflow\Actions\TabActions\StartWorkflow.cs" />
<Compile Include="Entities\Content\Workflow\Actions\TabActions\TabActionBase.cs" />
<Compile Include="Entities\Modules\Prompt\AddModule.cs" />
<Compile Include="Entities\Modules\ICustomTokenProvider.cs" />
<Compile Include="Entities\Modules\InstalledModuleInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Entities.Content.Workflow.Actions.TabActions
{
using DotNetNuke.Entities.Content.Workflow.Actions;
using DotNetNuke.Entities.Content.Workflow.Dto;
using DotNetNuke.Entities.Content.Workflow.Entities;

/// <summary>
/// Completes a state, moving the workflow forward to the next state. If the next state is not the last one,
/// it sends notifications to the reviewers of the next state; otherwise, it sends a notification to the user
/// who submitted the draft once the workflow is complete.
/// </summary>
internal class CompleteState : TabActionBase, IWorkflowAction
{
/// <inheritdoc />
public void DoActionOnStateChanging(StateTransaction stateTransaction)
{
// nothing
}

/// <inheritdoc />
public void DoActionOnStateChanged(StateTransaction stateTransaction)
=> RemoveCache(stateTransaction);

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
=> new ()
{
Subject = GetString($"{nameof(CompleteState)}{nameof(ActionMessage.Subject)}", "Page Approval"),
Body = GetString($"{nameof(CompleteState)}{nameof(ActionMessage.Body)}", "Page '{0}' is in the '{1}' state and awaits review and approval.", GetTab(stateTransaction.ContentItemId).LocalizedTabName, currentState.StateName),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Entities.Content.Workflow.Actions.TabActions
{
using DotNetNuke.Entities.Content.Workflow.Actions;
using DotNetNuke.Entities.Content.Workflow.Dto;
using DotNetNuke.Entities.Content.Workflow.Entities;
using DotNetNuke.Entities.Tabs.TabVersions;

/// <summary>
/// Completes the workflow, no matter what the current state is.
/// It also sends a system notification to the user who submitted the workflow to
/// inform them about the complete workflow action.
/// </summary>
internal class CompleteWorkflow : TabActionBase, IWorkflowAction
{
/// <summary>
/// Publishes the tab version.
/// </summary>
/// <param name="stateTransaction">The state transaction.</param>
public void DoActionOnStateChanging(StateTransaction stateTransaction)
{
var tab = GetTab(stateTransaction.ContentItemId);
if (tab == null)
{
return;
}

TabVersionBuilder.Instance.Publish(tab.PortalID, tab.TabID, stateTransaction.UserId);
}

/// <inheritdoc />
public void DoActionOnStateChanged(StateTransaction stateTransaction)
=> RemoveCache(stateTransaction);

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
=> new ()
{
Subject = GetString($"{nameof(CompleteWorkflow)}{nameof(ActionMessage.Subject)}", "Page Published"),
Body = GetString($"{nameof(CompleteWorkflow)}{nameof(ActionMessage.Body)}", "Page '{0}' has been published and is now live.", GetTab(stateTransaction.ContentItemId).LocalizedTabName),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Entities.Content.Workflow.Actions.TabActions
{
using DotNetNuke.Entities.Content.Workflow.Actions;
using DotNetNuke.Entities.Content.Workflow.Dto;
using DotNetNuke.Entities.Content.Workflow.Entities;

/// <summary>
/// Discards a state, moving the workflow backward to the previous state. If the previous state is not the first one,
/// it sends notifications to the reviewers of the previous state; otherwise, it sends a notification to the user
/// who submitted the draft when the workflow is in the draft state.
/// </summary>
internal class DiscardState : TabActionBase, IWorkflowAction
{
/// <inheritdoc />
public void DoActionOnStateChanging(StateTransaction stateTransaction)
{
// nothing
}

/// <inheritdoc />
public void DoActionOnStateChanged(StateTransaction stateTransaction)
=> RemoveCache(stateTransaction);

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
=> new ()
{
Subject = GetString($"{nameof(DiscardState)}{nameof(ActionMessage.Subject)}", "Page Rejected"),
Body = GetString($"{nameof(DiscardState)}{nameof(ActionMessage.Body)}", "The edits for page '{0}' were rejected, and it is now in '{1}' state.", GetTab(stateTransaction.ContentItemId).LocalizedTabName, currentState.StateName),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Entities.Content.Workflow.Actions.TabActions
{
using System.Linq;

using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Content.Workflow.Actions;
using DotNetNuke.Entities.Content.Workflow.Dto;
using DotNetNuke.Entities.Content.Workflow.Entities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Tabs.TabVersions;

/// <summary>
/// Discards the tab workflow, no matter what the current state is. It also sends a system notification to the user
/// who submitted the workflow to inform them about the discard workflow action.
/// </summary>
internal class DiscardWorkflow : TabActionBase, IWorkflowAction
{
/// <summary>
/// Discards the tab version.
/// </summary>
/// <param name="stateTransaction">The state transaction.</param>
public void DoActionOnStateChanging(StateTransaction stateTransaction)
{
var tab = GetTab(stateTransaction.ContentItemId);
if (tab == null)
{
return;
}

TabVersionBuilder.Instance.Discard(tab.TabID, stateTransaction.UserId);
}

/// <summary>
/// Deletes the tab when necessary.
/// </summary>
/// <param name="stateTransaction">The state transaction.</param>
public void DoActionOnStateChanged(StateTransaction stateTransaction)
{
var tab = GetTab(stateTransaction.ContentItemId);
if (tab == null)
{
return;
}

if (HasOnlyOneTabVersion(tab))
{
TabController.Instance.SoftDeleteTab(tab.TabID, new PortalSettings(tab.PortalID));
TabController.Instance.DeleteTab(tab.TabID, tab.PortalID);
}

DataCache.RemoveCache($"Tab_Tabs{tab.PortalID}");
}

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
=> new ()
{
Subject = GetString($"{nameof(DiscardWorkflow)}{nameof(ActionMessage.Subject)}", "Page Discarded"),
Body = GetString($"{nameof(DiscardWorkflow)}{nameof(ActionMessage.Body)}", "Edits for page '{0}' have been discarded.", GetTab(stateTransaction.ContentItemId).LocalizedTabName),
};

/// <summary>
/// Checks if the tab has only one version.
/// </summary>
/// <param name="tabInfo">The tab information.</param>
/// <returns>True if the tab has only one version; otherwise, false.</returns>
private static bool HasOnlyOneTabVersion(TabInfo tabInfo)
{
var tabVersions = TabVersionController.Instance.GetTabVersions(tabInfo.TabID, true);
return tabVersions == null || !tabVersions.Any();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Entities.Content.Workflow.Actions.TabActions
{
using DotNetNuke.Entities.Content.Workflow.Actions;
using DotNetNuke.Entities.Content.Workflow.Dto;
using DotNetNuke.Entities.Content.Workflow.Entities;

/// <summary>
/// Starts a tab workflow.
/// </summary>
internal class StartWorkflow : TabActionBase, IWorkflowAction
{
/// <inheritdoc />
public void DoActionOnStateChanging(StateTransaction stateTransaction)
{
// nothing
}

/// <inheritdoc />
public void DoActionOnStateChanged(StateTransaction stateTransaction)
=> RemoveCache(stateTransaction);

/// <inheritdoc />
public ActionMessage GetActionMessage(StateTransaction stateTransaction, WorkflowState currentState)
=> new ()
{
Subject = GetString($"{nameof(StartWorkflow)}{nameof(ActionMessage.Subject)}", "Page Submitted"),
Body = GetString($"{nameof(StartWorkflow)}{nameof(ActionMessage.Body)}", "Page '{0}' is in the '{1}' state and waiting to be submitted.", GetTab(stateTransaction.ContentItemId).LocalizedTabName, currentState.StateName),
};
}
}
Loading

0 comments on commit 04efa70

Please sign in to comment.