mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-17 19:37:45 +08:00
完成直接为用户分配模块
This commit is contained in:
parent
e259fdd34c
commit
fc7c568b3a
@ -11,12 +11,15 @@ namespace OpenAuth.App
|
|||||||
{
|
{
|
||||||
private IUserRepository _repository;
|
private IUserRepository _repository;
|
||||||
private IOrgRepository _orgRepository;
|
private IOrgRepository _orgRepository;
|
||||||
|
private IUserModuleRepository _usermoduleRepository;
|
||||||
|
|
||||||
public UserManagerApp(IUserRepository repository,
|
public UserManagerApp(IUserRepository repository,
|
||||||
IOrgRepository orgRepository)
|
IOrgRepository orgRepository,
|
||||||
|
IUserModuleRepository usermoduleRepository)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_orgRepository = orgRepository;
|
_orgRepository = orgRepository;
|
||||||
|
_usermoduleRepository = usermoduleRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetUserCntInOrg(int orgId)
|
public int GetUserCntInOrg(int orgId)
|
||||||
@ -112,6 +115,11 @@ namespace OpenAuth.App
|
|||||||
_repository.SetOrg(user.Id, orgIds);
|
_repository.SetOrg(user.Id, orgIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void AccessModules(int userId, int[] ids)
|
||||||
|
{
|
||||||
|
_usermoduleRepository.DeleteByUser(userId);
|
||||||
|
_usermoduleRepository.AddUserModule(userId, ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
14
OpenAuth.Domain/Interface/IUserModuleRepository.cs
Normal file
14
OpenAuth.Domain/Interface/IUserModuleRepository.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OpenAuth.Domain.Interface
|
||||||
|
{
|
||||||
|
public interface IUserModuleRepository : IRepository<UserModule>
|
||||||
|
{
|
||||||
|
void DeleteByUser(params int[] userIds);
|
||||||
|
void AddUserModule(int userId, params int[] moduleIds);
|
||||||
|
}
|
||||||
|
}
|
@ -46,6 +46,7 @@
|
|||||||
<Compile Include="Interface\IOrgRepository.cs" />
|
<Compile Include="Interface\IOrgRepository.cs" />
|
||||||
<Compile Include="Interface\IRepository.cs" />
|
<Compile Include="Interface\IRepository.cs" />
|
||||||
<Compile Include="Interface\IRoleRepository.cs" />
|
<Compile Include="Interface\IRoleRepository.cs" />
|
||||||
|
<Compile Include="Interface\IUserModuleRepository.cs" />
|
||||||
<Compile Include="Interface\IUserRepository.cs" />
|
<Compile Include="Interface\IUserRepository.cs" />
|
||||||
<Compile Include="Module.cs" />
|
<Compile Include="Module.cs" />
|
||||||
<Compile Include="ModuleElement.cs" />
|
<Compile Include="ModuleElement.cs" />
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using OpenAuth.App;
|
using OpenAuth.App;
|
||||||
using OpenAuth.App.ViewModel;
|
using OpenAuth.App.ViewModel;
|
||||||
|
using OpenAuth.Mvc.Models;
|
||||||
|
using WebGrease.Css.Extensions;
|
||||||
|
|
||||||
namespace OpenAuth.Mvc.Controllers
|
namespace OpenAuth.Mvc.Controllers
|
||||||
{
|
{
|
||||||
@ -69,5 +73,21 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
|
|
||||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string AccessModule(int userId, string moduleIds)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var ids = moduleIds.Split(',').Select(id => int.Parse(id)).ToArray();
|
||||||
|
_app.AccessModules(userId, ids);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
BjuiResponse.message = e.Message;
|
||||||
|
BjuiResponse.statusCode = "300";
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,8 +30,14 @@
|
|||||||
var selected = getSelected(2);
|
var selected = getSelected(2);
|
||||||
if (selected == null) return;
|
if (selected == null) return;
|
||||||
|
|
||||||
$.getJSON('UserManager/AccessModule', function (json) {
|
$.post('UserManager/AccessModule', { userId: selected, moduleIds: accessIds },
|
||||||
//授权操作
|
function (json) {
|
||||||
|
var rel = $.parseJSON(json);
|
||||||
|
if (rel.statusCode == "200") {
|
||||||
|
$(this).alertmsg('ok', rel.message);
|
||||||
|
} else {
|
||||||
|
$(this).alertmsg('error', rel.message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
<component type=" OpenAuth.Repository.OrgRepository" service="OpenAuth.Domain.Interface.IOrgRepository,OpenAuth.Domain" />
|
<component type=" OpenAuth.Repository.OrgRepository" service="OpenAuth.Domain.Interface.IOrgRepository,OpenAuth.Domain" />
|
||||||
<component type=" OpenAuth.Repository.RoleRepository" service="OpenAuth.Domain.Interface.IRoleRepository,OpenAuth.Domain" />
|
<component type=" OpenAuth.Repository.RoleRepository" service="OpenAuth.Domain.Interface.IRoleRepository,OpenAuth.Domain" />
|
||||||
<component type=" OpenAuth.Repository.ModuleRepository" service="OpenAuth.Domain.Interface.IModuleRepository,OpenAuth.Domain" />
|
<component type=" OpenAuth.Repository.ModuleRepository" service="OpenAuth.Domain.Interface.IModuleRepository,OpenAuth.Domain" />
|
||||||
|
<component type=" OpenAuth.Repository.UserModuleRepository" service="OpenAuth.Domain.Interface.IUserModuleRepository,OpenAuth.Domain" />
|
||||||
</components>
|
</components>
|
||||||
</autofac>
|
</autofac>
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ModuleRepository.cs" />
|
<Compile Include="ModuleRepository.cs" />
|
||||||
<Compile Include="RoleRepository.cs" />
|
<Compile Include="RoleRepository.cs" />
|
||||||
|
<Compile Include="UserModuleRepository.cs" />
|
||||||
<Compile Include="UserRepository.cs" />
|
<Compile Include="UserRepository.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
51
OpenAuth.Repository/UserModuleRepository.cs
Normal file
51
OpenAuth.Repository/UserModuleRepository.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// ***********************************************************************
|
||||||
|
// Assembly : OpenAuth.Repository
|
||||||
|
// Author : yubaolee
|
||||||
|
// Created : 11-26-2015
|
||||||
|
//
|
||||||
|
// Last Modified By : yubaolee
|
||||||
|
// Last Modified On : 11-26-2015
|
||||||
|
// ***********************************************************************
|
||||||
|
// <copyright file="UserModuleRepository.cs" company="www.cnblogs.com/yubaolee">
|
||||||
|
// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
|
||||||
|
// </copyright>
|
||||||
|
// <summary>用户菜单分配操作</summary>
|
||||||
|
// ***********************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenAuth.Domain;
|
||||||
|
using OpenAuth.Domain.Interface;
|
||||||
|
|
||||||
|
namespace OpenAuth.Repository
|
||||||
|
{
|
||||||
|
public class UserModuleRepository : BaseRepository<UserModule>, IUserModuleRepository
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 删除指定用户关联的模块
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userIds">The user ids.</param>
|
||||||
|
public void DeleteByUser(params int[] userIds)
|
||||||
|
{
|
||||||
|
Delete(u =>userIds.Contains(u.UserId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 为指定的用户分配模块
|
||||||
|
/// </summary>
|
||||||
|
public void AddUserModule(int userId, params int[] moduleIds)
|
||||||
|
{
|
||||||
|
foreach (var moduleId in moduleIds)
|
||||||
|
{
|
||||||
|
Add(new UserModule
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
ModuleId = moduleId,
|
||||||
|
OperateTime = DateTime.Now
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,9 @@ namespace OpenAuth.UnitTest
|
|||||||
public class TestUserApp
|
public class TestUserApp
|
||||||
{
|
{
|
||||||
|
|
||||||
private UserManagerApp _app = new UserManagerApp(new UserRepository(), new OrgRepository());
|
private UserManagerApp _app = new UserManagerApp(new UserRepository(),
|
||||||
|
new OrgRepository(),
|
||||||
|
new UserModuleRepository());
|
||||||
private string _time = DateTime.Now.ToString("HH_mm_ss_ms");
|
private string _time = DateTime.Now.ToString("HH_mm_ss_ms");
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user