mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -18,6 +18,7 @@ namespace Orchard.Roles.Drivers {
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private const string TemplateName = "Parts/Roles.UserRoles";
|
||||
|
||||
public UserRolesPartDriver(
|
||||
IRepository<UserRolesPartRecord> userRolesRepository,
|
||||
@@ -46,20 +47,19 @@ namespace Orchard.Roles.Drivers {
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ApplyRoles, _authenticationService.GetAuthenticatedUser(), userRolesPart))
|
||||
return null;
|
||||
|
||||
var roles =
|
||||
_roleService.GetRoles().Select(
|
||||
x => new UserRoleEntry {
|
||||
return ContentShape("Parts_Roles_UserRoles_Edit",
|
||||
() => {
|
||||
var roles =_roleService.GetRoles().Select(x => new UserRoleEntry {
|
||||
RoleId = x.Id,
|
||||
Name = x.Name,
|
||||
Granted = userRolesPart.Roles.Contains(x.Name)
|
||||
});
|
||||
|
||||
Granted = userRolesPart.Roles.Contains(x.Name)});
|
||||
var model = new UserRolesViewModel {
|
||||
User = userRolesPart.As<IUser>(),
|
||||
UserRoles = userRolesPart,
|
||||
Roles = roles.ToList(),
|
||||
};
|
||||
return ContentPartTemplate(model, "Parts/Roles.UserRoles");
|
||||
return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
|
||||
});
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(UserRolesPart userRolesPart, IUpdateModel updater, dynamic shapeHelper) {
|
||||
@@ -67,29 +67,26 @@ namespace Orchard.Roles.Drivers {
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ApplyRoles, _authenticationService.GetAuthenticatedUser(), userRolesPart))
|
||||
return null;
|
||||
|
||||
var model = new UserRolesViewModel {
|
||||
User = userRolesPart.As<IUser>(),
|
||||
UserRoles = userRolesPart,
|
||||
};
|
||||
|
||||
var model = BuildEditorViewModel(userRolesPart);
|
||||
if (updater.TryUpdateModel(model, Prefix, null, null)) {
|
||||
|
||||
var currentUserRoleRecords = _userRolesRepository.Fetch(x => x.UserId == model.User.Id);
|
||||
var currentRoleRecords = currentUserRoleRecords.Select(x => x.Role);
|
||||
var targetRoleRecords = model.Roles.Where(x => x.Granted).Select(x => _roleService.GetRole(x.RoleId));
|
||||
|
||||
foreach (var addingRole in targetRoleRecords.Where(x => !currentRoleRecords.Contains(x))) {
|
||||
_notifier.Warning(T("Adding role {0} to user {1}", addingRole.Name, userRolesPart.As<IUser>().UserName));
|
||||
_userRolesRepository.Create(new UserRolesPartRecord { UserId = model.User.Id, Role = addingRole });
|
||||
}
|
||||
|
||||
foreach (var removingRole in currentUserRoleRecords.Where(x => !targetRoleRecords.Contains(x.Role))) {
|
||||
_notifier.Warning(T("Removing role {0} from user {1}", removingRole.Role.Name, userRolesPart.As<IUser>().UserName));
|
||||
_userRolesRepository.Delete(removingRole);
|
||||
}
|
||||
}
|
||||
return ContentShape("Parts_Roles_UserRoles_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
||||
}
|
||||
|
||||
}
|
||||
return ContentPartTemplate(model, "Parts/Roles.UserRoles");
|
||||
private static UserRolesViewModel BuildEditorViewModel(UserRolesPart userRolesPart) {
|
||||
return new UserRolesViewModel { User = userRolesPart.As<IUser>(), UserRoles = userRolesPart };
|
||||
}
|
||||
}
|
||||
}
|
@@ -39,6 +39,7 @@
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations">
|
||||
@@ -108,6 +109,9 @@
|
||||
<Name>Orchard.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Placement.info" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
3
src/Orchard.Web/Modules/Orchard.Roles/Placement.info
Normal file
3
src/Orchard.Web/Modules/Orchard.Roles/Placement.info
Normal file
@@ -0,0 +1,3 @@
|
||||
<Placement>
|
||||
<Place Parts_Roles_UserRoles_Edit="Primary:10"/>
|
||||
</Placement>
|
Reference in New Issue
Block a user