mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-27 12:29:04 +08:00
committed by
Sébastien Ros
parent
bc66cdb36c
commit
3bda4acee1
@@ -41,7 +41,7 @@ namespace Orchard.Roles.Activities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override LocalizedString Description {
|
public override LocalizedString Description {
|
||||||
get { return T("Assign specific roles to the current content item if it's a user."); }
|
get { return T("Assign specific roles to the current content item if it's a user."); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Form {
|
public override string Form {
|
||||||
@@ -49,7 +49,7 @@ namespace Orchard.Roles.Activities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
|
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||||
return new[] {T("Done")};
|
return new[] { T("Done") };
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||||
@@ -59,7 +59,7 @@ namespace Orchard.Roles.Activities {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = _workContextAccessor.GetContext().CurrentUser.As<IUserRoles>();
|
user = _workContextAccessor.GetContext().CurrentUser.As<IUserRoles>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var roles = GetRoles(activityContext);
|
var roles = GetRoles(activityContext);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@@ -67,7 +67,7 @@ namespace Orchard.Roles.Activities {
|
|||||||
if (!user.Roles.Contains(role)) {
|
if (!user.Roles.Contains(role)) {
|
||||||
var roleRecord = _roleService.GetRoleByName(role);
|
var roleRecord = _roleService.GetRoleByName(role);
|
||||||
if (roleRecord != null) {
|
if (roleRecord != null) {
|
||||||
_repository.Create(new UserRolesPartRecord {UserId = user.Id, Role = roleRecord});
|
_repository.Create(new UserRolesPartRecord { UserId = user.Id, Role = roleRecord });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logger.Debug("Role not found: {0}", role);
|
Logger.Debug("Role not found: {0}", role);
|
||||||
@@ -78,7 +78,7 @@ namespace Orchard.Roles.Activities {
|
|||||||
|
|
||||||
yield return T("Done");
|
yield return T("Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> GetRoles(ActivityContext context) {
|
private IEnumerable<string> GetRoles(ActivityContext context) {
|
||||||
var roles = context.GetState<string>("Roles");
|
var roles = context.GetState<string>("Roles");
|
||||||
|
|
||||||
@@ -86,7 +86,8 @@ namespace Orchard.Roles.Activities {
|
|||||||
return Enumerable.Empty<string>();
|
return Enumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return roles.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
|
return roles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Data;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Logging;
|
||||||
|
using Orchard.Roles.Models;
|
||||||
|
using Orchard.Roles.Services;
|
||||||
|
using Orchard.Workflows.Models;
|
||||||
|
using Orchard.Workflows.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Roles.Activities {
|
||||||
|
[OrchardFeature("Orchard.Roles.Workflows")]
|
||||||
|
public class UnssignRoleActivity : Task {
|
||||||
|
private readonly IWorkContextAccessor _workContextAccessor;
|
||||||
|
private readonly IRepository<UserRolesPartRecord> _repository;
|
||||||
|
private readonly IRoleService _roleService;
|
||||||
|
|
||||||
|
public UnssignRoleActivity(
|
||||||
|
IWorkContextAccessor workContextAccessor,
|
||||||
|
IRepository<UserRolesPartRecord> repository,
|
||||||
|
IRoleService roleService) {
|
||||||
|
_workContextAccessor = workContextAccessor;
|
||||||
|
_repository = repository;
|
||||||
|
_roleService = roleService;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
Logger = NullLogger.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
|
public override string Name {
|
||||||
|
get { return "UnassignRole"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override LocalizedString Category {
|
||||||
|
get { return T("User"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override LocalizedString Description {
|
||||||
|
get { return T("Unassign specific roles from the current content item if it's a user."); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Form {
|
||||||
|
get { return "SelectRoles"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||||
|
return new[] { T("Done") };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||||
|
var user = workflowContext.Content.As<IUserRoles>();
|
||||||
|
|
||||||
|
// if the current workflow subject is not a user, use current user
|
||||||
|
if (user == null) {
|
||||||
|
user = _workContextAccessor.GetContext().CurrentUser.As<IUserRoles>();
|
||||||
|
}
|
||||||
|
|
||||||
|
var roles = GetRoles(activityContext);
|
||||||
|
|
||||||
|
if (user != null) {
|
||||||
|
foreach (var role in roles) {
|
||||||
|
if (user.Roles.Contains(role)) {
|
||||||
|
var roleRecord = _roleService.GetRoleByName(role);
|
||||||
|
if (roleRecord != null) {
|
||||||
|
var currentUserRoleRecord = _repository.Fetch(x => x.UserId == user.Id && x.Role.Id == roleRecord.Id).SingleOrDefault();
|
||||||
|
if (currentUserRoleRecord != null) {
|
||||||
|
_repository.Delete(currentUserRoleRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Logger.Debug("Role not found: {0}", role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return T("Done");
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<string> GetRoles(ActivityContext context) {
|
||||||
|
var roles = context.GetState<string>("Roles");
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(roles)) {
|
||||||
|
return Enumerable.Empty<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return roles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,6 +90,7 @@
|
|||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<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" />
|
||||||
<Compile Include="Activities\UserTaskActivity.cs" />
|
<Compile Include="Activities\UserTaskActivity.cs" />
|
||||||
@@ -137,6 +138,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Module.txt" />
|
<Content Include="Module.txt" />
|
||||||
<Content Include="Styles\admin-usertask.css" />
|
<Content Include="Styles\admin-usertask.css" />
|
||||||
|
<Content Include="Styles\workflows-activity-unassign-role.css" />
|
||||||
<Content Include="Styles\workflows-activity-assign-role.css" />
|
<Content Include="Styles\workflows-activity-assign-role.css" />
|
||||||
<Content Include="Styles\workflows-activity-isinrole.css" />
|
<Content Include="Styles\workflows-activity-isinrole.css" />
|
||||||
<Content Include="Styles\workflows-activity-usertask.css" />
|
<Content Include="Styles\workflows-activity-usertask.css" />
|
||||||
@@ -195,6 +197,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="packages.config" />
|
<Content Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Views\Activity-UnassignRole.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
activity-unassign-role {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4AsSDQYi3LJqFgAAAaRJREFUWMPtl7tKA1EQhr9dNIhXVETEylthYyEknYWCYKeFzyNEwRQ+ggipBAkEawsL9REsbARBEnRjTGGhlbGZyHo4N+OJF/CHIZvzzz+ZzM6Zswv/0KMbKAA3YgVZC8U7UQCaiu0G5J2oagJUA/LviA0JRJq1jINPo8f3n5oSKGrWDhx80eBr0zibMAEawJ6hyRIxtckyomkY+N+JTeBO0zwTDl61CrAumkkH/wH3hoAuXme3KZ2VjxRH245ofrKikU/c+Kfv+48n0NXB2M0/UYHQCSRAHsgB42I5YAeo+ZTMtg1dW+8Q6LPE7weOUv4zuuxtCSSWHy9ZDqhIuS6L5tx3Err4GjDoMQ9aGAbqol32uRVjDn7LcyClkRftvk8CJWkmE7/QRgKLor0K0YwDnk2ajjMk10/xdw0cBa8tbYgEplOl1lmsfAeYk89KiAQ22tC0ngfOQvTAV7bhSqiJ2M4gOg09ksvAiKUSo8Cx+NaB2U6cCXUZMlmgVywLbAOP4vMALIU+VeeBC48ZcAJMdfJ4X5MXkEvgGXgBruVFZVUneAM9RhZRUdfKzwAAAABJRU5ErkJggg==');
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbox-task.toolbox-unassign-role {
|
||||||
|
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4AsSDQYi3LJqFgAAAaRJREFUWMPtl7tKA1EQhr9dNIhXVETEylthYyEknYWCYKeFzyNEwRQ+ggipBAkEawsL9REsbARBEnRjTGGhlbGZyHo4N+OJF/CHIZvzzz+ZzM6Zswv/0KMbKAA3YgVZC8U7UQCaiu0G5J2oagJUA/LviA0JRJq1jINPo8f3n5oSKGrWDhx80eBr0zibMAEawJ6hyRIxtckyomkY+N+JTeBO0zwTDl61CrAumkkH/wH3hoAuXme3KZ2VjxRH245ofrKikU/c+Kfv+48n0NXB2M0/UYHQCSRAHsgB42I5YAeo+ZTMtg1dW+8Q6LPE7weOUv4zuuxtCSSWHy9ZDqhIuS6L5tx3Err4GjDoMQ9aGAbqol32uRVjDn7LcyClkRftvk8CJWkmE7/QRgKLor0K0YwDnk2ajjMk10/xdw0cBa8tbYgEplOl1lmsfAeYk89KiAQ22tC0ngfOQvTAV7bhSqiJ2M4gOg09ksvAiKUSo8Cx+NaB2U6cCXUZMlmgVywLbAOP4vMALIU+VeeBC48ZcAJMdfJ4X5MXkEvgGXgBruVFZVUneAM9RhZRUdfKzwAAAABJRU5ErkJggg==');
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: 6px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbox-task.toolbox-unassign-role div {
|
||||||
|
margin-left: 36px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
@{
|
||||||
|
var rolesData = (string)Model.State.Roles;
|
||||||
|
var roles = !String.IsNullOrWhiteSpace(rolesData) ? rolesData.Split(',') : Enumerable.Empty<string>();
|
||||||
|
var description = roles.Any() ? T("Unassign roles: {0}", String.Join(", ", roles)) : T("No roles specified");
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="activity-unassign-role" title="@description">
|
||||||
|
</div>
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
<PropertyValue name="Indent_FlushLabelsLeft">0</PropertyValue>
|
<PropertyValue name="Indent_FlushLabelsLeft">0</PropertyValue>
|
||||||
<PropertyValue name="Indent_UnindentLabels">1</PropertyValue>
|
<PropertyValue name="Indent_UnindentLabels">1</PropertyValue>
|
||||||
<PropertyValue name="NewLines_AnonymousTypeInitializer_EachMember">1</PropertyValue>
|
<PropertyValue name="NewLines_AnonymousTypeInitializer_EachMember">1</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Braces_Accessor">1</PropertyValue>
|
<PropertyValue name="NewLines_Braces_Accessor">0</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Braces_AnonymousMethod">0</PropertyValue>
|
<PropertyValue name="NewLines_Braces_AnonymousMethod">0</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Braces_AnonymousTypeInitializer">0</PropertyValue>
|
<PropertyValue name="NewLines_Braces_AnonymousTypeInitializer">0</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Braces_ArrayInitializer">0</PropertyValue>
|
<PropertyValue name="NewLines_Braces_ArrayInitializer">0</PropertyValue>
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
<PropertyValue name="NewLines_Braces_LambdaExpressionBody">0</PropertyValue>
|
<PropertyValue name="NewLines_Braces_LambdaExpressionBody">0</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Braces_Method">0</PropertyValue>
|
<PropertyValue name="NewLines_Braces_Method">0</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Braces_ObjectInitializer">0</PropertyValue>
|
<PropertyValue name="NewLines_Braces_ObjectInitializer">0</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Braces_Property">1</PropertyValue>
|
<PropertyValue name="NewLines_Braces_Property">0</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Braces_Type">0</PropertyValue>
|
<PropertyValue name="NewLines_Braces_Type">0</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Keywords_Catch">1</PropertyValue>
|
<PropertyValue name="NewLines_Keywords_Catch">1</PropertyValue>
|
||||||
<PropertyValue name="NewLines_Keywords_Else">1</PropertyValue>
|
<PropertyValue name="NewLines_Keywords_Else">1</PropertyValue>
|
||||||
|
|||||||
Reference in New Issue
Block a user