Skip to content

Commit 8586c98

Browse files
committed
#94: Mpa section is converted to bsb-admin
1 parent 49c830a commit 8586c98

File tree

79 files changed

+26508
-6709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+26508
-6709
lines changed

src/AbpCompanyName.AbpProjectName.Application/AbpCompanyName.AbpProjectName.Application.csproj

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,36 @@
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<Reference Include="Abp, Version=2.1.3.0, Culture=neutral, processorArchitecture=MSIL">
39-
<HintPath>..\packages\Abp.2.1.3\lib\net46\Abp.dll</HintPath>
38+
<Reference Include="Abp, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
39+
<HintPath>..\packages\Abp.2.2.1\lib\net46\Abp.dll</HintPath>
4040
<Private>True</Private>
4141
</Reference>
42-
<Reference Include="Abp.AutoMapper, Version=2.1.3.0, Culture=neutral, processorArchitecture=MSIL">
43-
<HintPath>..\packages\Abp.AutoMapper.2.1.3\lib\net46\Abp.AutoMapper.dll</HintPath>
42+
<Reference Include="Abp.AutoMapper, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Abp.AutoMapper.2.2.1\lib\net46\Abp.AutoMapper.dll</HintPath>
4444
<Private>True</Private>
4545
</Reference>
46-
<Reference Include="Abp.Zero, Version=2.1.3.0, Culture=neutral, processorArchitecture=MSIL">
47-
<HintPath>..\packages\Abp.Zero.2.1.3\lib\net46\Abp.Zero.dll</HintPath>
46+
<Reference Include="Abp.Zero, Version=2.2.1.0, Culture=neutral, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Abp.Zero.2.2.1\lib\net46\Abp.Zero.dll</HintPath>
4848
<Private>True</Private>
4949
</Reference>
50-
<Reference Include="Abp.Zero.Common, Version=2.1.3.0, Culture=neutral, processorArchitecture=MSIL">
51-
<HintPath>..\packages\Abp.Zero.Common.2.1.3\lib\net46\Abp.Zero.Common.dll</HintPath>
50+
<Reference Include="Abp.Zero.Common, Version=2.2.1.0, Culture=neutral, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Abp.Zero.Common.2.2.1\lib\net46\Abp.Zero.Common.dll</HintPath>
5252
<Private>True</Private>
5353
</Reference>
5454
<Reference Include="AutoMapper, Version=6.1.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
5555
<HintPath>..\packages\AutoMapper.6.1.0\lib\net45\AutoMapper.dll</HintPath>
5656
<Private>True</Private>
5757
</Reference>
58-
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
59-
<SpecificVersion>False</SpecificVersion>
60-
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
58+
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
59+
<HintPath>..\packages\Castle.Core.4.0.0\lib\net45\Castle.Core.dll</HintPath>
60+
<Private>True</Private>
6161
</Reference>
62-
<Reference Include="Castle.Facilities.Logging, Version=3.4.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
63-
<HintPath>..\packages\Castle.LoggingFacility.3.4.0\lib\net45\Castle.Facilities.Logging.dll</HintPath>
62+
<Reference Include="Castle.Facilities.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
63+
<HintPath>..\packages\Castle.LoggingFacility.4.0.0\lib\net45\Castle.Facilities.Logging.dll</HintPath>
6464
<Private>True</Private>
6565
</Reference>
66-
<Reference Include="Castle.Windsor, Version=3.4.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
67-
<HintPath>..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll</HintPath>
66+
<Reference Include="Castle.Windsor, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
67+
<HintPath>..\packages\Castle.Windsor.4.0.0\lib\net45\Castle.Windsor.dll</HintPath>
6868
<Private>True</Private>
6969
</Reference>
7070
<Reference Include="JetBrains.Annotations, Version=10.4.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
@@ -135,24 +135,27 @@
135135
<Compile Include="Authorization\Accounts\IAccountAppService.cs" />
136136
<Compile Include="Configuration\UiThemeInfo.cs" />
137137
<Compile Include="Configuration\UiThemes.cs" />
138-
<Compile Include="MultiTenancy\Dto\CreateTenantInput.cs" />
138+
<Compile Include="MultiTenancy\Dto\CreateTenantDto.cs" />
139+
<Compile Include="MultiTenancy\Dto\EditTenantDto.cs" />
140+
<Compile Include="MultiTenancy\Dto\TenantDto.cs" />
139141
<Compile Include="MultiTenancy\ITenantAppService.cs" />
140-
<Compile Include="MultiTenancy\Dto\TenantListDto.cs" />
141142
<Compile Include="MultiTenancy\TenantAppService.cs" />
142143
<Compile Include="Properties\AssemblyInfo.cs" />
144+
<Compile Include="Roles\Dto\CreateRoleDto.cs" />
145+
<Compile Include="Roles\Dto\PermissionDto.cs" />
146+
<Compile Include="Roles\Dto\RoleDto.cs" />
143147
<Compile Include="Roles\IRoleAppService.cs" />
144-
<Compile Include="Roles\Dto\UpdateRolePermissionsInput.cs" />
145-
<Compile Include="Users\Dto\CreateUserInput.cs" />
148+
<Compile Include="Users\Dto\CreateUserDto.cs" />
149+
<Compile Include="Users\Dto\UpdateUserDto.cs" />
150+
<Compile Include="Users\Dto\UserDto.cs" />
146151
<Compile Include="Users\IUserAppService.cs" />
147152
<Compile Include="Roles\RoleAppService.cs" />
148153
<Compile Include="Sessions\Dto\GetCurrentLoginInformationsOutput.cs" />
149154
<Compile Include="Sessions\Dto\TenantLoginInfoDto.cs" />
150155
<Compile Include="Sessions\Dto\UserLoginInfoDto.cs" />
151156
<Compile Include="Sessions\ISessionAppService.cs" />
152157
<Compile Include="Sessions\SessionAppService.cs" />
153-
<Compile Include="Users\Dto\ProhibitPermissionInput.cs" />
154158
<Compile Include="Users\UserAppService.cs" />
155-
<Compile Include="Users\Dto\UserListDto.cs" />
156159
</ItemGroup>
157160
<ItemGroup>
158161
<None Include="app.config" />
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
using System.Reflection;
2+
using Abp.Authorization;
3+
using Abp.Authorization.Roles;
4+
using Abp.Authorization.Users;
25
using Abp.AutoMapper;
6+
using Abp.Domain.Repositories;
37
using Abp.Modules;
8+
using AbpCompanyName.AbpProjectName.Authorization.Roles;
9+
using AbpCompanyName.AbpProjectName.Authorization.Users;
10+
using AbpCompanyName.AbpProjectName.Roles.Dto;
11+
using AbpCompanyName.AbpProjectName.Users.Dto;
412

513
namespace AbpCompanyName.AbpProjectName
614
{
@@ -9,16 +17,38 @@ public class AbpProjectNameApplicationModule : AbpModule
917
{
1018
public override void PreInitialize()
1119
{
12-
Configuration.Modules.AbpAutoMapper().Configurators.Add(mapper =>
13-
{
14-
//Add your custom AutoMapper mappings here...
15-
//mapper.CreateMap<,>()
16-
});
1720
}
1821

1922
public override void Initialize()
2023
{
2124
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
25+
26+
// TODO: Is there somewhere else to store these, with the dto classes
27+
Configuration.Modules.AbpAutoMapper().Configurators.Add(cfg =>
28+
{
29+
// Role and permission
30+
cfg.CreateMap<Permission, string>().ConvertUsing(r => r.Name);
31+
cfg.CreateMap<RolePermissionSetting, string>().ConvertUsing(r => r.Name);
32+
33+
cfg.CreateMap<CreateRoleDto, Role>().ForMember(x => x.Permissions, opt => opt.Ignore());
34+
cfg.CreateMap<RoleDto, Role>().ForMember(x => x.Permissions, opt => opt.Ignore());
35+
36+
IRepository<Role, int> repository = IocManager.Resolve<IRepository<Role, int>>();
37+
// User and role
38+
cfg.CreateMap<UserRole, string>().ConvertUsing((r) => {
39+
//TODO: Fix, this seems hacky
40+
Role role = repository.FirstOrDefault(r.RoleId);
41+
return role.DisplayName;
42+
});
43+
44+
IocManager.Release(repository);
45+
46+
cfg.CreateMap<UserDto, User>();
47+
cfg.CreateMap<UserDto, User>().ForMember(x => x.Roles, opt => opt.Ignore());
48+
49+
cfg.CreateMap<CreateUserDto, User>();
50+
cfg.CreateMap<CreateUserDto, User>().ForMember(x => x.Roles, opt => opt.Ignore());
51+
});
2252
}
2353
}
2454
}

src/AbpCompanyName.AbpProjectName.Application/MultiTenancy/Dto/CreateTenantInput.cs renamed to src/AbpCompanyName.AbpProjectName.Application/MultiTenancy/Dto/CreateTenantDto.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System.ComponentModel.DataAnnotations;
1+
using System.ComponentModel.DataAnnotations;
22
using Abp.Authorization.Users;
33
using Abp.AutoMapper;
44
using Abp.MultiTenancy;
55

66
namespace AbpCompanyName.AbpProjectName.MultiTenancy.Dto
77
{
88
[AutoMapTo(typeof(Tenant))]
9-
public class CreateTenantInput
9+
public class CreateTenantDto
1010
{
1111
[Required]
1212
[StringLength(AbpTenantBase.MaxTenancyNameLength)]
@@ -23,5 +23,7 @@ public class CreateTenantInput
2323

2424
[MaxLength(AbpTenantBase.MaxConnectionStringLength)]
2525
public string ConnectionString { get; set; }
26+
27+
public bool IsActive { get; set; }
2628
}
2729
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using Abp.AutoMapper;
3+
using Abp.MultiTenancy;
4+
5+
namespace AbpCompanyName.AbpProjectName.MultiTenancy.Dto
6+
{
7+
[AutoMapTo(typeof(Tenant))]
8+
public class EditTenantDto
9+
{
10+
[Required]
11+
[StringLength(AbpTenantBase.MaxTenancyNameLength)]
12+
[RegularExpression(Tenant.TenancyNameRegex)]
13+
public string TenancyName { get; set; }
14+
15+
[Required]
16+
[StringLength(Tenant.MaxNameLength)]
17+
public string Name { get; set; }
18+
19+
public bool IsActive { get; set; }
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using Abp.Application.Services.Dto;
3+
using Abp.AutoMapper;
4+
using Abp.MultiTenancy;
5+
6+
namespace AbpCompanyName.AbpProjectName.MultiTenancy.Dto
7+
{
8+
[AutoMapTo(typeof(Tenant)), AutoMapFrom(typeof(Tenant))]
9+
public class TenantDto : EntityDto
10+
{
11+
[Required]
12+
[StringLength(AbpTenantBase.MaxTenancyNameLength)]
13+
[RegularExpression(Tenant.TenancyNameRegex)]
14+
public string TenancyName { get; set; }
15+
16+
[Required]
17+
[StringLength(Tenant.MaxNameLength)]
18+
public string Name { get; set; }
19+
20+
public bool IsActive { get; set; }
21+
}
22+
}

src/AbpCompanyName.AbpProjectName.Application/MultiTenancy/Dto/TenantListDto.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
using System.Threading.Tasks;
2-
using Abp.Application.Services;
1+
using Abp.Application.Services;
32
using Abp.Application.Services.Dto;
43
using AbpCompanyName.AbpProjectName.MultiTenancy.Dto;
54

65
namespace AbpCompanyName.AbpProjectName.MultiTenancy
76
{
8-
public interface ITenantAppService : IApplicationService
7+
public interface ITenantAppService : IAsyncCrudAppService<TenantDto, int, PagedResultRequestDto, CreateTenantDto, TenantDto>
98
{
10-
ListResultDto<TenantListDto> GetTenants();
11-
12-
Task CreateTenant(CreateTenantInput input);
139
}
1410
}
Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
using System.Collections.Generic;
21
using System.Linq;
32
using System.Threading.Tasks;
3+
using Abp.Application.Services;
44
using Abp.Application.Services.Dto;
55
using Abp.Authorization;
6-
using Abp.AutoMapper;
6+
using Abp.Domain.Repositories;
77
using Abp.Extensions;
8+
using Abp.IdentityFramework;
89
using Abp.MultiTenancy;
910
using Abp.Runtime.Security;
1011
using AbpCompanyName.AbpProjectName.Authorization;
1112
using AbpCompanyName.AbpProjectName.Authorization.Roles;
1213
using AbpCompanyName.AbpProjectName.Authorization.Users;
1314
using AbpCompanyName.AbpProjectName.Editions;
1415
using AbpCompanyName.AbpProjectName.MultiTenancy.Dto;
15-
using AbpCompanyName.AbpProjectName.Users;
16+
using Microsoft.AspNet.Identity;
1617

1718
namespace AbpCompanyName.AbpProjectName.MultiTenancy
1819
{
1920
[AbpAuthorize(PermissionNames.Pages_Tenants)]
20-
public class TenantAppService : AbpProjectNameAppServiceBase, ITenantAppService
21+
public class TenantAppService : AsyncCrudAppService<Tenant, TenantDto, int, PagedResultRequestDto, CreateTenantDto, TenantDto>, ITenantAppService
2122
{
2223
private readonly TenantManager _tenantManager;
23-
private readonly RoleManager _roleManager;
2424
private readonly EditionManager _editionManager;
25+
private readonly RoleManager _roleManager;
26+
private readonly UserManager _userManager;
2527
private readonly IAbpZeroDbMigrator _abpZeroDbMigrator;
2628

2729
public TenantAppService(
28-
TenantManager tenantManager,
29-
RoleManager roleManager,
30-
EditionManager editionManager,
31-
IAbpZeroDbMigrator abpZeroDbMigrator)
30+
IRepository<Tenant, int> repository,
31+
32+
TenantManager tenantManager,
33+
EditionManager editionManager,
34+
UserManager userManager,
35+
36+
RoleManager roleManager,
37+
IAbpZeroDbMigrator abpZeroDbMigrator
38+
) : base(repository)
3239
{
3340
_tenantManager = tenantManager;
34-
_roleManager = roleManager;
3541
_editionManager = editionManager;
42+
_roleManager = roleManager;
3643
_abpZeroDbMigrator = abpZeroDbMigrator;
44+
_userManager = userManager;
3745
}
3846

39-
public ListResultDto<TenantListDto> GetTenants()
47+
public override async Task<TenantDto> Create(CreateTenantDto input)
4048
{
41-
return new ListResultDto<TenantListDto>(
42-
_tenantManager.Tenants
43-
.OrderBy(t => t.TenancyName)
44-
.ToList()
45-
.MapTo<List<TenantListDto>>()
46-
);
47-
}
49+
CheckCreatePermission();
4850

49-
public async Task CreateTenant(CreateTenantInput input)
50-
{
5151
//Create tenant
52-
var tenant = input.MapTo<Tenant>();
52+
var tenant = ObjectMapper.Map<Tenant>(input);
5353
tenant.ConnectionString = input.ConnectionString.IsNullOrEmpty()
5454
? null
5555
: SimpleStringCipher.Instance.Encrypt(input.ConnectionString);
@@ -60,7 +60,7 @@ public async Task CreateTenant(CreateTenantInput input)
6060
tenant.EditionId = defaultEdition.Id;
6161
}
6262

63-
await TenantManager.CreateAsync(tenant);
63+
await _tenantManager.CreateAsync(tenant);
6464
await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id.
6565

6666
//Create tenant database
@@ -80,13 +80,36 @@ public async Task CreateTenant(CreateTenantInput input)
8080

8181
//Create admin user for the tenant
8282
var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, User.DefaultPassword);
83-
CheckErrors(await UserManager.CreateAsync(adminUser));
83+
CheckErrors(await _userManager.CreateAsync(adminUser));
8484
await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id
8585

8686
//Assign admin user to role!
87-
CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));
87+
CheckErrors(await _userManager.AddToRoleAsync(adminUser.Id, adminRole.Name));
8888
await CurrentUnitOfWork.SaveChangesAsync();
8989
}
90+
91+
return MapToEntityDto(tenant);
92+
}
93+
94+
protected override void MapToEntity(TenantDto updateInput, Tenant entity)
95+
{
96+
//Manually mapped since TenantDto contains non-editable properties too.
97+
entity.Name = updateInput.Name;
98+
entity.TenancyName = updateInput.TenancyName;
99+
entity.IsActive = updateInput.IsActive;
100+
}
101+
102+
public override async Task Delete(EntityDto<int> input)
103+
{
104+
CheckDeletePermission();
105+
106+
var tenant = await _tenantManager.GetByIdAsync(input.Id);
107+
await _tenantManager.DeleteAsync(tenant);
108+
}
109+
110+
private void CheckErrors(IdentityResult identityResult)
111+
{
112+
identityResult.CheckErrors(LocalizationManager);
90113
}
91114
}
92115
}

0 commit comments

Comments
 (0)