Skip to content

Commit

Permalink
Refine content workflow actions in EditBar dnnsoftware#6115
Browse files Browse the repository at this point in the history
  • Loading branch information
tvatavuk committed Oct 3, 2024
1 parent 5d86e3c commit 5110898
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="HttpModules\EditBarModule.cs" />
<Compile Include="Items\AddExistingModuleMenu.cs" />
<Compile Include="Items\AddModuleMenu.cs" />
<Compile Include="Items\WorkflowBaseMenuItem.cs" />
<Compile Include="Items\WorkflowStateMenu.cs" />
<Compile Include="Items\CompleteWorkflowMenu.cs" />
<Compile Include="Items\DiscardWorkflowMenu.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@ namespace Dnn.EditBar.UI.Items
using System;

using Dnn.EditBar.Library;
using Dnn.EditBar.Library.Items;
using DotNetNuke.Application;
using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Content.Workflow;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Tabs.TabVersions;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Personalization;

[Serializable]
public class CompleteStateMenu : BaseMenuItem
public class CompleteStateMenu : WorkflowBaseMenuItem
{
/// <inheritdoc/>
public override string Name { get; } = "CompleteState";

/// <inheritdoc/>
public override string Text => "Submit";
public override string Text => this.IsFirstState ? "Submit" : "Approve"; // (1) "Submit" -> (2..last-2) "Approve" -> (last) HIDDEN

/// <inheritdoc/>
public override string CssClass => string.Empty;
Expand All @@ -42,15 +33,9 @@ public class CompleteStateMenu : BaseMenuItem
public override int Order { get; } = 78;

/// <inheritdoc/>
public override bool Visible()
{
var contentItem = Util.GetContentController().GetContentItem(TabController.CurrentPage.ContentItemId);
return Personalization.GetUserMode() == PortalSettings.Mode.Edit
&& DotNetNukeContext.Current.Application.SKU == "DNN" // IsPlatform
&& TabVersionSettings.Instance.IsVersioningEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // versioning is enabled
&& TabWorkflowSettings.Instance.IsWorkflowEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // workflow is enabled
&& ((WorkflowEngine.Instance.IsWorkflowOnDraft(contentItem) && PermissionProvider.Instance().CanAddContentToPage(TabController.CurrentPage))
|| (!WorkflowEngine.Instance.IsWorkflowCompleted(contentItem) && WorkflowSecurity.Instance.HasStateReviewerPermission(contentItem.StateID)));
}
public override bool Visible() => base.Visible()
&& !this.IsLastState // not the last 'Published' state
&& !this.IsPriorState // not the state that is before last 'Published' state
&& (this.IsDraftWithPermissions || this.IsReviewOrOtherIntermediateStateWithPermissions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@ namespace Dnn.EditBar.UI.Items
using System;

using Dnn.EditBar.Library;
using Dnn.EditBar.Library.Items;
using DotNetNuke.Application;
using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Content.Workflow;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Tabs.TabVersions;
using DotNetNuke.Services.Personalization;

[Serializable]
public class CompleteWorkflowMenu : BaseMenuItem
public class CompleteWorkflowMenu : WorkflowBaseMenuItem
{
/// <inheritdoc/>
public override string Name { get; } = "CompleteWorkflow";

/// <inheritdoc/>
public override string Text => "Approve";
public override string Text => "Publish";

/// <inheritdoc/>
public override string CssClass => string.Empty;
Expand All @@ -38,18 +30,12 @@ public class CompleteWorkflowMenu : BaseMenuItem
public override string Loader { get; } = "CompleteWorkflow";

/// <inheritdoc/>
public override int Order { get; } = 80;
public override int Order { get; } = 79;

/// <inheritdoc/>
public override bool Visible()
{
var contentItem = Util.GetContentController().GetContentItem(TabController.CurrentPage.ContentItemId);
return Personalization.GetUserMode() == PortalSettings.Mode.Edit
&& DotNetNukeContext.Current.Application.SKU == "DNN" // IsPlatform
&& TabVersionSettings.Instance.IsVersioningEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // versioning is enabled
&& TabWorkflowSettings.Instance.IsWorkflowEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // workflow is enabled
&& !WorkflowEngine.Instance.IsWorkflowCompleted(contentItem) // tab has new version that is not published
&& WorkflowSecurity.Instance.HasStateReviewerPermission(contentItem.StateID); // user has workflow approval permission
}
public override bool Visible() => base.Visible()
&& (this.IsReviewOrOtherIntermediateStateWithPermissions
|| (this.IsPriorState && this.IsDraftWithPermissions) // for Save Draft workflow
|| (this.IsLastState && this.HasUnpublishVersion && this.HasDraftPermission)); // for Direct Publish workflow
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@ namespace Dnn.EditBar.UI.Items
using System;

using Dnn.EditBar.Library;
using Dnn.EditBar.Library.Items;
using DotNetNuke.Application;
using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Content.Workflow;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Tabs.TabVersions;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Personalization;

[Serializable]
public class DiscardStateMenu : BaseMenuItem
public class DiscardStateMenu : WorkflowBaseMenuItem
{
/// <inheritdoc/>
public override string Name { get; } = "DiscardState";

/// <inheritdoc/>
public override string Text => "Discard";
public override string Text => "Reject"; // (1) HIDDEN -> (2..last) "Reject"

/// <inheritdoc/>
public override string CssClass => string.Empty;
Expand All @@ -39,18 +30,12 @@ public class DiscardStateMenu : BaseMenuItem
public override string Loader { get; } = "DiscardState";

/// <inheritdoc/>
public override int Order { get; } = 79;
public override int Order { get; } = 80;

/// <inheritdoc/>
public override bool Visible()
{
var contentItem = Util.GetContentController().GetContentItem(TabController.CurrentPage.ContentItemId);
return Personalization.GetUserMode() == PortalSettings.Mode.Edit
&& DotNetNukeContext.Current.Application.SKU == "DNN" // IsPlatform
&& TabVersionSettings.Instance.IsVersioningEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // versioning is enabled
&& TabWorkflowSettings.Instance.IsWorkflowEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // workflow is enabled
&& ((WorkflowEngine.Instance.IsWorkflowOnDraft(contentItem) && PermissionProvider.Instance().CanAddContentToPage(TabController.CurrentPage))
|| (!WorkflowEngine.Instance.IsWorkflowCompleted(contentItem) && WorkflowSecurity.Instance.HasStateReviewerPermission(contentItem.StateID)));
}
public override bool Visible() => base.Visible()
&& !this.IsLastState // not the last 'Published' state
&& !this.IsFirstState
&& this.IsReviewOrOtherIntermediateStateWithPermissions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@ namespace Dnn.EditBar.UI.Items
using System;

using Dnn.EditBar.Library;
using Dnn.EditBar.Library.Items;
using DotNetNuke.Application;
using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Content.Workflow;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Tabs.TabVersions;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Personalization;

[Serializable]
public class DiscardWorkflowMenu : BaseMenuItem
public class DiscardWorkflowMenu : WorkflowBaseMenuItem
{
/// <inheritdoc/>
public override string Name { get; } = "DiscardWorkflow";

/// <inheritdoc/>
public override string Text => "Reject";
public override string Text => "Discard";

/// <inheritdoc/>
public override string CssClass => string.Empty;
Expand All @@ -42,15 +33,8 @@ public class DiscardWorkflowMenu : BaseMenuItem
public override int Order { get; } = 81;

/// <inheritdoc/>
public override bool Visible()
{
var contentItem = Util.GetContentController().GetContentItem(TabController.CurrentPage.ContentItemId);
return Personalization.GetUserMode() == PortalSettings.Mode.Edit
&& DotNetNukeContext.Current.Application.SKU == "DNN" // IsPlatform
&& TabVersionSettings.Instance.IsVersioningEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // versioning is enabled
&& TabWorkflowSettings.Instance.IsWorkflowEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // workflow is enabled
&& !WorkflowEngine.Instance.IsWorkflowCompleted(contentItem) // tab has new version that is not published
&& WorkflowSecurity.Instance.HasStateReviewerPermission(contentItem.StateID); // user has workflow approval permission
}
public override bool Visible() => base.Visible()
&& ((!this.IsLastState && (this.IsDraftWithPermissions || this.IsReviewOrOtherIntermediateStateWithPermissions))
|| (this.IsLastState && this.HasUnpublishVersion && this.HasDraftPermission)); // for Direct Publish workflow
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 Dnn.EditBar.UI.Items
{
using System.Linq;

using Dnn.EditBar.Library.Items;
using DotNetNuke.Application;
using DotNetNuke.Entities.Content;
using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Content.Workflow;
using DotNetNuke.Entities.Content.Workflow.Entities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Tabs.TabVersions;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Personalization;

public abstract class WorkflowBaseMenuItem : BaseMenuItem
{
private readonly IWorkflowEngine workflowEngine = WorkflowEngine.Instance;

internal Workflow Workflow => WorkflowManager.Instance.GetWorkflow(this.WorkflowState.WorkflowID);

internal WorkflowState WorkflowState => /*this.workflowState ??=*/ WorkflowStateManager.Instance.GetWorkflowState(this.ContentItem.StateID);

internal bool IsEditMode => Personalization.GetUserMode() == PortalSettings.Mode.Edit;

internal bool IsPlatform => DotNetNukeContext.Current.Application.SKU == "DNN";

internal bool IsWorkflowEnabled => this.IsVersioningEnabled && TabWorkflowSettings.Instance.IsWorkflowEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID);

internal bool IsFirstState => this.WorkflowState.StateName == this.Workflow.FirstState.StateName; // 'Draft'

internal bool IsPriorState => this.WorkflowState.StateName == this.PriorState?.StateName;

internal bool IsLastState => this.WorkflowState.StateName == this.Workflow.LastState.StateName; // 'Published'

internal bool IsDraftWithPermissions => this.workflowEngine.IsWorkflowOnDraft(this.ContentItem) && this.HasDraftPermission;

internal bool IsReviewOrOtherIntermediateStateWithPermissions => !this.workflowEngine.IsWorkflowCompleted(this.ContentItem) && WorkflowSecurity.Instance.HasStateReviewerPermission(this.ContentItem.StateID);

internal bool IsWorkflowCompleted => WorkflowEngine.Instance.IsWorkflowCompleted(TabController.CurrentPage.ContentItemId);

internal bool HasBeenPublished => TabController.CurrentPage.HasBeenPublished;

internal bool HasUnpublishVersion => TabVersionBuilder.Instance.GetUnPublishedVersion(TabController.CurrentPage.TabID) != null;

internal bool HasUnpublishVersionWithPermissions => this.HasUnpublishVersion && WorkflowSecurity.Instance.HasStateReviewerPermission(this.ContentItem.StateID);

internal bool HasDraftPermission => PermissionProvider.Instance().CanAddContentToPage(TabController.CurrentPage);

private ContentItem ContentItem => Util.GetContentController().GetContentItem(TabController.CurrentPage.ContentItemId);

private bool IsVersioningEnabled => TabVersionSettings.Instance.IsVersioningEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID);

// State before the last one.
private WorkflowState PriorState => this.Workflow.States == null || !this.Workflow.States.Any() ? null : this.Workflow.States.OrderBy(s => s.Order).Reverse().Skip(1).FirstOrDefault();

public override bool Visible() =>
this.IsEditMode
&& this.IsPlatform
&& this.IsWorkflowEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@
namespace Dnn.EditBar.UI.Items
{
using System;

using Dnn.EditBar.Library.Items;
using Dnn.PersonaBar.Pages.Components;
using DotNetNuke.Application;
using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Tabs.TabVersions;
using DotNetNuke.Services.Personalization;
using System.Linq;

[Serializable]
public class WorkflowStateMenu : BaseMenuItem
public class WorkflowStateMenu : WorkflowBaseMenuItem
{
/// <inheritdoc/>
public override string Name { get; } = "WorkflowState";

/// <inheritdoc/>
public override string Text => TabController.CurrentPage.HasBeenPublished && WorkflowHelper.IsWorkflowCompleted(TabController.CurrentPage) ? "Published" : "Draft";
public override string Text => $"<small>{this.Workflow.WorkflowName}:</small><br>{this.RenderStates()}";

/// <inheritdoc/>
public override string CssClass => string.Empty;
Expand All @@ -39,14 +31,19 @@ public class WorkflowStateMenu : BaseMenuItem
/// <inheritdoc/>
public override int Order { get; } = 77;

/// <inheritdoc/>
public override bool Visible()
// render list of workflow states from first state to current workflow state
private string RenderStates()
{
var contentItem = Util.GetContentController().GetContentItem(TabController.CurrentPage.ContentItemId);
return Personalization.GetUserMode() == PortalSettings.Mode.Edit
&& DotNetNukeContext.Current.Application.SKU == "DNN" // IsPlatform
&& TabVersionSettings.Instance.IsVersioningEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID) // versioning is enabled
&& TabWorkflowSettings.Instance.IsWorkflowEnabled(PortalSettings.Current.PortalId, TabController.CurrentPage.TabID); // workflow is enabled
var currentState = $"<strong>{this.WorkflowState.StateName}</strong>";
if (this.IsFirstState || this.IsLastState)
{
return currentState;
}

// return "Draft > Review > Review2" for example
var pastStates = this.Workflow.States.Where(s => s.Order < this.WorkflowState.Order).OrderBy(s => s.Order).ToList();
var pastStatesHtml = string.Join(" &gt; ", pastStates.Select(s => $"{s.StateName}"));
return string.Join(" &gt; ", pastStatesHtml, currentState);
}
}
}

0 comments on commit 5110898

Please sign in to comment.