mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-22 21:02:08 +08:00
8657 roleactivities: adds role event activities and handlers for workflows (#8658)
* Added Role Event Activities and Handlers for workflows. * Removed and sorted using * Added user as the Content parameter for worflow triggers when possible (UserAdded and UserRemoved role events).
This commit is contained in:
committed by
GitHub
parent
babe1d665d
commit
9728831556
@@ -0,0 +1,54 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Workflows.Models;
|
||||||
|
using Orchard.Workflows.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Roles.Activities {
|
||||||
|
public class RoleEventActivity : Event {
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public RoleEventActivity() {
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanStartWorkflow {
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name {
|
||||||
|
get {
|
||||||
|
return "OnRoleEvent";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override LocalizedString Category {
|
||||||
|
get {
|
||||||
|
return T("Roles");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override LocalizedString Description {
|
||||||
|
get {
|
||||||
|
return T("Manage Role Event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||||
|
string operatore = workflowContext.Tokens["Action"].ToString();
|
||||||
|
LocalizedString msg = T(operatore);
|
||||||
|
yield return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||||
|
return new[] {
|
||||||
|
T("Created"),
|
||||||
|
T("Removed"),
|
||||||
|
T("Renamed"),
|
||||||
|
T("UserAdded"),
|
||||||
|
T("UserRemoved"),
|
||||||
|
T("PermissionAdded"),
|
||||||
|
T("PermissionRemoved")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Workflows.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Roles.Events {
|
||||||
|
public class RoleEventHandler : IRoleEventHandler {
|
||||||
|
private readonly IWorkflowManager _workflowManager;
|
||||||
|
|
||||||
|
public RoleEventHandler(IWorkflowManager workflowManager) {
|
||||||
|
_workflowManager = workflowManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Created(RoleCreatedContext context) {
|
||||||
|
_workflowManager.TriggerEvent("OnRoleEvent",
|
||||||
|
null,
|
||||||
|
() => new Dictionary<string, object> {
|
||||||
|
{ "Role", context.Role },
|
||||||
|
{ "Action", "RoleCreated" } });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PermissionAdded(PermissionAddedContext context) {
|
||||||
|
_workflowManager.TriggerEvent("OnRoleEvent",
|
||||||
|
null,
|
||||||
|
() => new Dictionary<string, object> {
|
||||||
|
{ "Role", context.Role },
|
||||||
|
{ "Permission", context.Permission },
|
||||||
|
{ "Action", "PermissionAdded" } });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PermissionRemoved(PermissionRemovedContext context) {
|
||||||
|
_workflowManager.TriggerEvent("OnRoleEvent",
|
||||||
|
null,
|
||||||
|
() => new Dictionary<string, object> {
|
||||||
|
{ "Role", context.Role },
|
||||||
|
{ "Permission", context.Permission },
|
||||||
|
{ "Action", "PermissionRemoved" } });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Removed(RoleRemovedContext context) {
|
||||||
|
_workflowManager.TriggerEvent("OnRoleEvent",
|
||||||
|
null,
|
||||||
|
() => new Dictionary<string, object> {
|
||||||
|
{ "Role", context.Role },
|
||||||
|
{ "Action", "RoleRemoved" } });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Renamed(RoleRenamedContext context) {
|
||||||
|
_workflowManager.TriggerEvent("OnRoleEvent",
|
||||||
|
null,
|
||||||
|
() => new Dictionary<string, object> {
|
||||||
|
{ "PreviousName", context.PreviousRoleName },
|
||||||
|
{ "NewName", context.NewRoleName },
|
||||||
|
{ "Action", "RoleRenamed" } });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UserAdded(UserAddedContext context) {
|
||||||
|
// Content of workflow event is the user
|
||||||
|
var content = context.User.ContentItem;
|
||||||
|
_workflowManager.TriggerEvent("OnRoleEvent",
|
||||||
|
content,
|
||||||
|
() => new Dictionary<string, object> {
|
||||||
|
{ "Role", context.Role },
|
||||||
|
{ "User", context.User },
|
||||||
|
{ "Action", "UserAdded" } });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UserRemoved(UserRemovedContext context) {
|
||||||
|
// Content of workflow event is the user
|
||||||
|
var content = context.User.ContentItem;
|
||||||
|
_workflowManager.TriggerEvent("OnRoleEvent",
|
||||||
|
content,
|
||||||
|
() => new Dictionary<string, object> {
|
||||||
|
{ "Role", context.Role },
|
||||||
|
{ "User", context.User },
|
||||||
|
{ "Action", "UserRemoved" } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,6 +92,7 @@
|
|||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Activities\RoleEventActivity.cs" />
|
||||||
<Compile Include="Activities\UnassignRoleActivity.cs" />
|
<Compile Include="Activities\UnassignRoleActivity.cs" />
|
||||||
<Compile Include="Activities\AssignRoleActivity.cs" />
|
<Compile Include="Activities\AssignRoleActivity.cs" />
|
||||||
<Compile Include="Activities\IsInRoleActivity.cs" />
|
<Compile Include="Activities\IsInRoleActivity.cs" />
|
||||||
@@ -107,6 +108,7 @@
|
|||||||
<Compile Include="Events\PermissionRoleContext.cs" />
|
<Compile Include="Events\PermissionRoleContext.cs" />
|
||||||
<Compile Include="Events\RoleContext.cs" />
|
<Compile Include="Events\RoleContext.cs" />
|
||||||
<Compile Include="Events\RoleCreatedContext.cs" />
|
<Compile Include="Events\RoleCreatedContext.cs" />
|
||||||
|
<Compile Include="Events\RoleEventHandler.cs" />
|
||||||
<Compile Include="Events\RoleRemovedContext.cs" />
|
<Compile Include="Events\RoleRemovedContext.cs" />
|
||||||
<Compile Include="Events\RoleRenamedContext.cs" />
|
<Compile Include="Events\RoleRenamedContext.cs" />
|
||||||
<Compile Include="Events\UserAddedContext.cs" />
|
<Compile Include="Events\UserAddedContext.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user