Tenant Seed düzenlemesi

This commit is contained in:
Sedat Öztürk 2025-10-11 01:27:06 +03:00
parent 8c8e214e78
commit d9f021c0f1
42 changed files with 392 additions and 266 deletions

View file

@ -1,93 +0,0 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Blog;
public class BlogPostDto : FullAuditedEntityDto<Guid>
{
public Guid? TenantId { get; set; }
public string Title { get; set; }
public string Slug { get; set; }
public string ContentTr { get; set; }
public string ContentEn { get; set; }
public string Summary { get; set; }
public string CoverImage { get; set; }
public Guid CategoryId { get; set; }
public BlogCategoryDto Category { get; set; }
public AuthorDto Author { get; set; }
public int ViewCount { get; set; }
public int LikeCount { get; set; }
public int CommentCount { get; set; }
public bool IsPublished { get; set; }
public DateTime? PublishedAt { get; set; }
public List<string> Tags { get; set; }
public bool IsLiked { get; set; }
public BlogPostDto()
{
Tags = [];
}
}
public class AuthorDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Avatar { get; set; }
}
public class CreateUpdateBlogPostDto
{
public Guid? TenantId { get; set; }
public string Title { get; set; }
public string Slug { get; set; }
public string ContentTr { get; set; }
public string ContentEn { get; set; }
public string Summary { get; set; }
public string ReadTime { get; set; }
public string CoverImage { get; set; }
public Guid CategoryId { get; set; }
public List<string> Tags { get; set; }
public bool IsPublished { get; set; }
public CreateUpdateBlogPostDto()
{
Tags = [];
}
}
public class BlogPostListDto : EntityDto<Guid>
{
public Guid? TenantId { get; set; }
public string Title { get; set; }
public string Slug { get; set; }
public string Summary { get; set; }
public string ReadTime { get; set; }
public string CoverImage { get; set; }
public string ContentTr { get; set; }
public string ContentEn { get; set; }
public BlogCategoryDto Category { get; set; }
public AuthorDto Author { get; set; }
public int ViewCount { get; set; }
public int LikeCount { get; set; }
public int CommentCount { get; set; }
public bool IsPublished { get; set; }
public DateTime? PublishedAt { get; set; }
public DateTime CreationTime { get; set; }
public List<string> Tags { get; set; }
public BlogPostListDto()
{
Tags = [];
}
}

View file

@ -4,7 +4,7 @@ using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Abouts; namespace Kurs.Platform.Public;
public class AboutDto : EntityDto<Guid> public class AboutDto : EntityDto<Guid>
{ {

View file

@ -0,0 +1,10 @@
using System;
namespace Kurs.Platform.Public;
public class AuthorDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Avatar { get; set; }
}

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Blog; namespace Kurs.Platform.Public;
public class BlogCategoryDto : FullAuditedEntityDto<Guid> public class BlogCategoryDto : FullAuditedEntityDto<Guid>
{ {
@ -15,13 +15,4 @@ public class BlogCategoryDto : FullAuditedEntityDto<Guid>
public int PostCount { get; set; } public int PostCount { get; set; }
} }
public class CreateUpdateBlogCategoryDto
{
public Guid? TenantId { get; set; }
public string Name { get; set; }
public string Slug { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public int DisplayOrder { get; set; }
public bool IsActive { get; set; }
}

View file

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Blog; namespace Kurs.Platform.Public;
public class BlogPostAndCategoriesDto public class BlogPostAndCategoriesDto
{ {

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Public;
public class BlogPostDto : FullAuditedEntityDto<Guid>
{
public Guid? TenantId { get; set; }
public string Title { get; set; }
public string Slug { get; set; }
public string ContentTr { get; set; }
public string ContentEn { get; set; }
public string Summary { get; set; }
public string CoverImage { get; set; }
public Guid CategoryId { get; set; }
public BlogCategoryDto Category { get; set; }
public AuthorDto Author { get; set; }
public int ViewCount { get; set; }
public int LikeCount { get; set; }
public int CommentCount { get; set; }
public bool IsPublished { get; set; }
public DateTime? PublishedAt { get; set; }
public List<string> Tags { get; set; }
public bool IsLiked { get; set; }
public BlogPostDto()
{
Tags = [];
}
}

View file

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Public;
public class BlogPostListDto : EntityDto<Guid>
{
public Guid? TenantId { get; set; }
public string Title { get; set; }
public string Slug { get; set; }
public string Summary { get; set; }
public string ReadTime { get; set; }
public string CoverImage { get; set; }
public string ContentTr { get; set; }
public string ContentEn { get; set; }
public BlogCategoryDto Category { get; set; }
public AuthorDto Author { get; set; }
public int ViewCount { get; set; }
public int LikeCount { get; set; }
public int CommentCount { get; set; }
public bool IsPublished { get; set; }
public DateTime? PublishedAt { get; set; }
public DateTime CreationTime { get; set; }
public List<string> Tags { get; set; }
public BlogPostListDto()
{
Tags = [];
}
}

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Contacts; namespace Kurs.Platform.Public;
public class CityDto : AuditedEntityDto<Guid> public class CityDto : AuditedEntityDto<Guid>
{ {

View file

@ -3,7 +3,7 @@ using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Contacts; namespace Kurs.Platform.Public;
public class ContactDto : EntityDto<Guid> public class ContactDto : EntityDto<Guid>
{ {
@ -52,30 +52,3 @@ public class ContactDto : EntityDto<Guid>
set { MapJson = JsonSerializer.Serialize(value); } set { MapJson = JsonSerializer.Serialize(value); }
} }
} }
public class BankDto
{
public string AccountHolder { get; set; }
public string Branch { get; set; }
public string AccountNumber { get; set; }
public string Iban { get; set; }
}
public class WorkHoursDto
{
public string Weekday { get; set; }
public string Weekend { get; set; }
public string Whatsapp { get; set; }
}
public class MapDto
{
public string Title { get; set; }
public string Src { get; set; }
public string Width { get; set; }
public string Height { get; set; }
public string Style { get; set; }
public bool? AllowFullScreen { get; set; }
public string Loading { get; set; }
public string ReferrerPolicy { get; set; }
}

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Contacts; namespace Kurs.Platform.Public;
public class ContactTagDto : AuditedEntityDto<Guid> public class ContactTagDto : AuditedEntityDto<Guid>
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Contacts; namespace Kurs.Platform.Public;
public class ContactTitleDto : AuditedEntityDto<Guid> public class ContactTitleDto : AuditedEntityDto<Guid>
{ {

View file

@ -2,7 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Contacts; namespace Kurs.Platform.Public;
public class CountryDto : AuditedEntityDto<Guid> public class CountryDto : AuditedEntityDto<Guid>
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Contacts; namespace Kurs.Platform.Public;
public class CountryGroupDto : AuditedEntityDto<Guid> public class CountryGroupDto : AuditedEntityDto<Guid>
{ {

View file

@ -0,0 +1,14 @@
using System;
namespace Kurs.Platform.Public;
public class CreateUpdateBlogCategoryDto
{
public Guid? TenantId { get; set; }
public string Name { get; set; }
public string Slug { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public int DisplayOrder { get; set; }
public bool IsActive { get; set; }
}

View file

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
namespace Kurs.Platform.Public;
public class CreateUpdateBlogPostDto
{
public Guid? TenantId { get; set; }
public string Title { get; set; }
public string Slug { get; set; }
public string ContentTr { get; set; }
public string ContentEn { get; set; }
public string Summary { get; set; }
public string ReadTime { get; set; }
public string CoverImage { get; set; }
public Guid CategoryId { get; set; }
public List<string> Tags { get; set; }
public bool IsPublished { get; set; }
public CreateUpdateBlogPostDto()
{
Tags = [];
}
}

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Contacts; namespace Kurs.Platform.Public;
public class DistrictDto : AuditedEntityDto<Guid> public class DistrictDto : AuditedEntityDto<Guid>
{ {

View file

@ -4,7 +4,7 @@ using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
namespace Kurs.Platform.Blog; namespace Kurs.Platform.Public;
public interface IBlogAppService : IApplicationService public interface IBlogAppService : IApplicationService
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Orders; namespace Kurs.Platform.Public;
public class InstallmentOptionDto : EntityDto<Guid> public class InstallmentOptionDto : EntityDto<Guid>
{ {

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
using Kurs.Platform.Tenants; using Kurs.Platform.Tenants;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Orders; namespace Kurs.Platform.Public;
public class OrderDto : EntityDto<Guid> public class OrderDto : EntityDto<Guid>
{ {
@ -21,11 +21,3 @@ public class OrderDto : EntityDto<Guid>
public Dictionary<string, object> PaymentData { get; set; } public Dictionary<string, object> PaymentData { get; set; }
} }
public class OrderItemDto
{
public Guid ProductId { get; set; }
public ProductDto Product { get; set; }
public string BillingCycle { get; set; } // monthly | yearly
public int Quantity { get; set; }
public decimal TotalPrice { get; set; }
}

View file

@ -0,0 +1,12 @@
using System;
namespace Kurs.Platform.Public;
public class OrderItemDto
{
public Guid ProductId { get; set; }
public ProductDto Product { get; set; }
public string BillingCycle { get; set; } // monthly | yearly
public int Quantity { get; set; }
public decimal TotalPrice { get; set; }
}

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Orders; namespace Kurs.Platform.Public;
public class PaymentMethodDto : EntityDto<Guid> public class PaymentMethodDto : EntityDto<Guid>
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Orders; namespace Kurs.Platform.Public;
public class ProductDto : EntityDto<Guid> public class ProductDto : EntityDto<Guid>
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace Kurs.Platform.Services; namespace Kurs.Platform.Public;
public class ServiceDto : FullAuditedEntityDto<Guid> public class ServiceDto : FullAuditedEntityDto<Guid>
{ {

View file

@ -7,7 +7,7 @@ using Microsoft.Extensions.Localization;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users; using Volo.Abp.Users;
namespace Kurs.Platform.Blog; namespace Kurs.Platform.Public;
[Authorize] [Authorize]
public class BlogAppService : PlatformAppService, IBlogAppService public class BlogAppService : PlatformAppService, IBlogAppService

View file

@ -2,21 +2,16 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Kurs.Platform.Entities; using Kurs.Platform.Entities;
using Kurs.Platform.Services;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using System.Text; using System.Text;
using Kurs.Platform.Data.Seeds; using Kurs.Platform.Data.Seeds;
using Kurs.Sender.Mail; using Kurs.Sender.Mail;
using Volo.Abp.Settings; using Volo.Abp.Settings;
using Kurs.Platform.Demos; using Kurs.Platform.Demos;
using Kurs.Platform.Blog;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using System.Linq; using System.Linq;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Kurs.Platform.Orders;
using System.Text.Json; using System.Text.Json;
using Kurs.Platform.Abouts;
using Kurs.Platform.Contacts;
namespace Kurs.Platform.Public; namespace Kurs.Platform.Public;

View file

@ -1,11 +1,6 @@
using AutoMapper; using AutoMapper;
using Kurs.Platform.Abouts;
using Kurs.Platform.Blog;
using Kurs.Platform.Contacts;
using Kurs.Platform.Demos; using Kurs.Platform.Demos;
using Kurs.Platform.Entities; using Kurs.Platform.Entities;
using Kurs.Platform.Orders;
using Kurs.Platform.Services;
namespace Kurs.Platform.Public; namespace Kurs.Platform.Public;

View file

@ -29,19 +29,6 @@
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<None Remove="Seeds\TenantData.json" />
<Content Include="Seeds\TenantData.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Seeds\TenantData.Dev.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Seeds\TenantData.Production.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="Seeds\HostData.json" /> <None Remove="Seeds\HostData.json" />
<Content Include="Seeds\HostData.json"> <Content Include="Seeds\HostData.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>

View file

@ -18,7 +18,7 @@ using Volo.Abp.PermissionManagement;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using EFCore.BulkExtensions; using EFCore.BulkExtensions;
using System.Collections.Generic; using System.Collections.Generic;
using Kurs.Platform.Contacts; using Kurs.Platform.Public;
using static Kurs.Settings.SettingsConsts; using static Kurs.Settings.SettingsConsts;
namespace Kurs.Platform.Data.Seeds; namespace Kurs.Platform.Data.Seeds;

View file

@ -0,0 +1,9 @@
namespace Kurs.Platform.Public;
public class BankDto
{
public string AccountHolder { get; set; }
public string Branch { get; set; }
public string AccountNumber { get; set; }
public string Iban { get; set; }
}

View file

@ -0,0 +1,13 @@
namespace Kurs.Platform.Public;
public class MapDto
{
public string Title { get; set; }
public string Src { get; set; }
public string Width { get; set; }
public string Height { get; set; }
public string Style { get; set; }
public bool? AllowFullScreen { get; set; }
public string Loading { get; set; }
public string ReferrerPolicy { get; set; }
}

View file

@ -1,4 +1,4 @@
namespace Kurs.Platform.Abouts; namespace Kurs.Platform.Public;
public class SectionDto public class SectionDto
{ {

View file

@ -1,4 +1,4 @@
namespace Kurs.Platform.Abouts; namespace Kurs.Platform.Public;
public class StatDto public class StatDto
{ {

View file

@ -0,0 +1,8 @@
namespace Kurs.Platform.Public;
public class WorkHoursDto
{
public string Weekday { get; set; }
public string Weekend { get; set; }
public string Whatsapp { get; set; }
}

View file

@ -21,8 +21,6 @@ using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement; using Volo.Abp.PermissionManagement;
using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using IdentityRole = Volo.Abp.Identity.IdentityRole;
using IdentityUser = Volo.Abp.Identity.IdentityUser;
using static Kurs.Settings.SettingsConsts; using static Kurs.Settings.SettingsConsts;
namespace Kurs.Platform.Migrations; namespace Kurs.Platform.Migrations;
@ -90,17 +88,19 @@ public class DatabaseMigrationEventHandler :
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData)
{ {
var schemaMigrated = false;
try try
{ {
schemaMigrated = await MigrateDatabaseSchemaAsync(eventData.TenantId); var schemaMigrated = await MigrateDatabaseSchemaAsync(eventData.TenantId);
if (schemaMigrated) if (schemaMigrated)
{ {
await SeedTenantDataAsync(eventData); await SeedTenantDataAsync(eventData);
} }
} }
catch (Exception) catch (Exception ex)
{ {
Logger.LogError(ex, "Error while seeding tenant data");
throw;
//await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); //await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex);
} }
} }
@ -189,80 +189,80 @@ public class DatabaseMigrationEventHandler :
{ {
using (CurrentTenant.Change(eventData.TenantId)) using (CurrentTenant.Change(eventData.TenantId))
{ {
// await DataSeeder.SeedAsync( await DataSeeder.SeedAsync(
// new DataSeedContext(eventData.TenantId) new DataSeedContext(eventData.TenantId)
// .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, eventData.Properties[IdentityDataSeedContributor.AdminEmailPropertyName]) .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, eventData.Properties[IdentityDataSeedContributor.AdminEmailPropertyName])
// .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, eventData.Properties[IdentityDataSeedContributor.AdminPasswordPropertyName]) .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, eventData.Properties[IdentityDataSeedContributor.AdminPasswordPropertyName])
// .WithProperty(IdentityDataSeedContributor.AdminUserNamePropertyName, eventData.Properties[IdentityDataSeedContributor.AdminUserNamePropertyName]) .WithProperty(IdentityDataSeedContributor.AdminUserNamePropertyName, eventData.Properties[IdentityDataSeedContributor.AdminUserNamePropertyName])
// ); );
await IdentityOptions.SetAsync(); // await IdentityOptions.SetAsync();
var result = new IdentityDataSeedResult(); // var result = new IdentityDataSeedResult();
var adminEmail = eventData.Properties[IdentityDataSeedContributor.AdminEmailPropertyName]; // var adminEmail = eventData.Properties[IdentityDataSeedContributor.AdminEmailPropertyName];
var adminPassword = eventData.Properties[IdentityDataSeedContributor.AdminPasswordPropertyName]; // var adminPassword = eventData.Properties[IdentityDataSeedContributor.AdminPasswordPropertyName];
var adminUserName = eventData.Properties[IdentityDataSeedContributor.AdminUserNamePropertyName]; // var adminUserName = eventData.Properties[IdentityDataSeedContributor.AdminUserNamePropertyName];
var adminUser = await UserRepository.FindByNormalizedUserNameAsync( // var adminUser = await UserRepository.FindByNormalizedUserNameAsync(
LookupNormalizer.NormalizeName(adminUserName) // LookupNormalizer.NormalizeName(adminUserName)
); // );
adminUser = new IdentityUser( // adminUser = new IdentityUser(
GuidGenerator.Create(), // GuidGenerator.Create(),
adminUserName, // adminUserName,
adminUserName, // adminUserName,
eventData.TenantId // eventData.TenantId
) // )
{ // {
Name = PlatformConsts.AbpIdentity.User.AdminNameDefaultValue, // Name = PlatformConsts.AbpIdentity.User.AdminNameDefaultValue,
Surname = PlatformConsts.AbpIdentity.User.AdminSurNameDefaultValue, // Surname = PlatformConsts.AbpIdentity.User.AdminSurNameDefaultValue,
}; // };
adminUser.SetEmailConfirmed(true); // adminUser.SetEmailConfirmed(true);
adminUser.SetIsVerified(true); // adminUser.SetIsVerified(true);
adminUser.SetPhoneNumber(PlatformConsts.AbpIdentity.User.AdminPhoneNumberDefaultValue, true); // adminUser.SetPhoneNumber(PlatformConsts.AbpIdentity.User.AdminPhoneNumberDefaultValue, true);
(await UserManager.CreateAsync(adminUser, adminPassword, validatePassword: false)).CheckErrors(); // (await UserManager.CreateAsync(adminUser, adminPassword, validatePassword: false)).CheckErrors();
result.CreatedAdminUser = true; // result.CreatedAdminUser = true;
var adminRole = await RoleRepository.FindByNormalizedNameAsync(LookupNormalizer.NormalizeName(PlatformConsts.AbpIdentity.User.AdminRoleName)); // var adminRole = await RoleRepository.FindByNormalizedNameAsync(LookupNormalizer.NormalizeName(PlatformConsts.AbpIdentity.User.AdminRoleName));
if (adminRole is null) // if (adminRole is null)
{ // {
adminRole = new IdentityRole( // adminRole = new IdentityRole(
GuidGenerator.Create(), // GuidGenerator.Create(),
PlatformConsts.AbpIdentity.User.AdminRoleName, // PlatformConsts.AbpIdentity.User.AdminRoleName,
eventData.TenantId // eventData.TenantId
) // )
{ // {
IsStatic = true, // IsStatic = true,
IsPublic = true // IsPublic = true
}; // };
(await RoleManager.CreateAsync(adminRole)).CheckErrors(); // (await RoleManager.CreateAsync(adminRole)).CheckErrors();
result.CreatedAdminRole = true; // result.CreatedAdminRole = true;
} // }
(await UserManager.AddToRoleAsync(adminUser, adminRole.Name)).CheckErrors(); // (await UserManager.AddToRoleAsync(adminUser, adminRole.Name)).CheckErrors();
/*admin rolüne ait yetkiler otomatik atanıyor*/ // /*admin rolüne ait yetkiler otomatik atanıyor*/
var permissions = await PermissionGrantRepository.GetListAsync("R", PlatformConsts.AbpIdentity.User.AdminRoleName); // var permissions = await PermissionGrantRepository.GetListAsync("R", PlatformConsts.AbpIdentity.User.AdminRoleName);
if (permissions.Count == 0) // if (permissions.Count == 0)
{ // {
await PermissionGrantRepository.InsertManyAsync( // await PermissionGrantRepository.InsertManyAsync(
[ // [
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Default, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Default, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Create, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Create, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Delete, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Delete, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Update, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Update, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Default + ".Export", "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.Default + ".Export", "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.ManagePermissions, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Roles.ManagePermissions, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Default, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Default, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Create, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Create, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Delete, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Delete, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Update, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Update, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.ManagePermissions, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.ManagePermissions, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Default + ".Export", "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.Default + ".Export", "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.ManageRoles, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.Users.ManageRoles, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.UserLookup.Default, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId), // new(Guid.NewGuid(), PlatformConsts.IdentityPermissions.UserLookup.Default, "R", PlatformConsts.AbpIdentity.User.AdminRoleName, eventData.TenantId),
]); // ]);
} // }
} }
} }
} }

View file

@ -7,6 +7,22 @@
<RootNamespace>Kurs.Platform</RootNamespace> <RootNamespace>Kurs.Platform</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="Tenants\Seeds\TenantData.json" />
<Content Include="Tenants\Seeds\TenantData.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Tenants\Seeds\TenantData.Dev.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Tenants\Seeds\TenantData.Production.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="EFCore.BulkExtensions" Version="9.0.1" /> <PackageReference Include="EFCore.BulkExtensions" Version="9.0.1" />
<ProjectReference Include="..\..\modules\Kurs.Languages\Kurs.Languages.EntityFrameworkCore\Kurs.Languages.EntityFrameworkCore.csproj" /> <ProjectReference Include="..\..\modules\Kurs.Languages\Kurs.Languages.EntityFrameworkCore\Kurs.Languages.EntityFrameworkCore.csproj" />

View file

@ -144,11 +144,15 @@ public class TenantDataSeeder : IDataSeedContributor, ITransientDependency
public async Task SeedAsync(DataSeedContext context) public async Task SeedAsync(DataSeedContext context)
{ {
var assemblyLocation = Path.GetDirectoryName(typeof(TenantDataSeeder).Assembly.Location)!;
var basePath = Path.Combine(assemblyLocation, "Tenants", "Seeds");
var configuration = new ConfigurationBuilder() var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory()) .SetBasePath(basePath)
.AddJsonFile(Path.Combine("Seeds", "TenantData.json")) .AddJsonFile("TenantData.json", optional: false, reloadOnChange: false)
.AddJsonFile(Path.Combine("Seeds", $"TenantData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json"), true) .AddJsonFile($"TenantData.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? ""}.json", optional: true)
.Build(); .Build();
var items = configuration.Get<TenantSeederDto>(); var items = configuration.Get<TenantSeederDto>();
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };

View file

@ -0,0 +1,105 @@
using System;
using System.Threading.Tasks;
using Kurs.Platform.Extensions;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement;
using IdentityRole = Volo.Abp.Identity.IdentityRole;
using IdentityUser = Volo.Abp.Identity.IdentityUser;
namespace Kurs.Platform.Data.Seeds;
[Dependency(ReplaceServices = true)]
public class TenantIdentityDataSeeder : IdentityDataSeeder
{
private readonly IPermissionGrantRepository permissionGrantRepository;
public TenantIdentityDataSeeder(
IGuidGenerator guidGenerator,
IIdentityRoleRepository roleRepository,
IIdentityUserRepository userRepository,
ILookupNormalizer lookupNormalizer,
IdentityUserManager userManager,
IdentityRoleManager roleManager,
IPermissionGrantRepository permissionGrantRepository,
ICurrentTenant currentTenant,
IOptions<IdentityOptions> identityOptions
) : base(guidGenerator, roleRepository, userRepository, lookupNormalizer, userManager, roleManager, currentTenant, identityOptions)
{
this.permissionGrantRepository = permissionGrantRepository;
}
public override async Task<IdentityDataSeedResult> SeedAsync(string adminEmail, string adminPassword, Guid? tenantId = null, string adminUserName = null)
{
Check.NotNullOrWhiteSpace(adminEmail, nameof(adminEmail));
Check.NotNullOrWhiteSpace(adminPassword, nameof(adminPassword));
using (CurrentTenant.Change(tenantId))
{
await IdentityOptions.SetAsync();
var result = new IdentityDataSeedResult();
var adminRole = await RoleRepository.FindByNormalizedNameAsync(LookupNormalizer.NormalizeName(PlatformConsts.AbpIdentity.User.AdminRoleName));
if (adminRole is null)
{
adminRole = new IdentityRole(
GuidGenerator.Create(),
PlatformConsts.AbpIdentity.User.AdminRoleName,
tenantId
)
{
IsStatic = true,
IsPublic = true
};
(await RoleManager.CreateAsync(adminRole)).CheckErrors();
result.CreatedAdminRole = true;
}
adminUserName ??= PlatformConsts.AbpIdentity.User.AdminEmailDefaultValue;
var adminUser = await UserRepository.FindByNormalizedUserNameAsync(
LookupNormalizer.NormalizeName(adminUserName)
);
if (adminUser is null)
{
adminUser = new IdentityUser(
GuidGenerator.Create(),
adminUserName,
adminEmail,
tenantId
)
{
Name = PlatformConsts.AbpIdentity.User.AdminNameDefaultValue,
Surname = PlatformConsts.AbpIdentity.User.AdminSurNameDefaultValue,
};
adminUser.SetEmailConfirmed(true);
adminUser.SetIsVerified(true);
adminUser.SetRocketUsername(PlatformConsts.AbpIdentity.User.AdminRocketUsernameDefaultValue);
adminUser.SetPhoneNumber(PlatformConsts.AbpIdentity.User.AdminPhoneNumberDefaultValue, true);
(await UserManager.CreateAsync(adminUser, adminPassword, validatePassword: false)).CheckErrors();
result.CreatedAdminUser = true;
(await UserManager.AddToRoleAsync(adminUser, PlatformConsts.AbpIdentity.User.AdminRoleName)).CheckErrors();
}
// Grant all permission kısmı Abp tarafından otomatik çalıştırılıyor.
// Ayrıca bende çalıştırınca hata veriyor.
// Hem DbMigrator hem de burada IdentityDataSeeder var.
// Aynı Assembly'de birden fazla IdentityDataSeeder olabilir
// DbMigrator çalışınca kendi IdentityDataSeeder'ını çalıştırıyor.
// Tenant seed edilince bu IdentityDataSeeder çalışıyor.
// See: Volo.Abp.PermissionManagement.PermissionDataSeedContributor
return result;
}
}
}

View file

@ -1,8 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Kurs.Platform.Abouts;
using Kurs.Platform.Contacts;
using Kurs.Platform.Entities; using Kurs.Platform.Entities;
using Kurs.Platform.Public;
namespace Kurs.Platform.Seeds; namespace Kurs.Platform.Seeds;