From 9103d1ae94d42a47c81eda9cffef5cbcf70cccb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Sun, 15 Jun 2025 23:57:14 +0300 Subject: [PATCH] =?UTF-8?q?Branch=20Entity=20Hatas=C4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Identity/Dto/AssignedBranchViewModel.cs | 12 + .../Identity/Dto/UserInfoViewModel.cs | 2 + .../GridOptionsDto/GridOptionsDto.cs | 2 +- .../Identity/PlatformIdentityAppService.cs | 47 +- .../Seeds/ListFormsSeeder.cs | 2 +- .../Seeds/SeederData.json | 36 ++ .../Branches/IPlatformBranchesRepository.cs | 10 - .../ListForms/ListFormManager.cs | 11 +- .../Queries/SelectQueryManager.cs | 12 +- .../Branches/PlatformBranchRepository.cs | 46 -- api/src/Kurs.Platform.HttpApi.Host/Program.cs | 3 +- ui/dev-dist/sw.js | 2 +- ui/src/proxy/admin/models.ts | 6 + ui/src/proxy/form/models.ts | 1 + ui/src/views/admin/identity/Users/Details.tsx | 605 +++++++++--------- 15 files changed, 420 insertions(+), 377 deletions(-) create mode 100644 api/src/Kurs.Platform.Application.Contracts/Identity/Dto/AssignedBranchViewModel.cs delete mode 100644 api/src/Kurs.Platform.Domain/Branches/IPlatformBranchesRepository.cs delete mode 100644 api/src/Kurs.Platform.EntityFrameworkCore/Branches/PlatformBranchRepository.cs diff --git a/api/src/Kurs.Platform.Application.Contracts/Identity/Dto/AssignedBranchViewModel.cs b/api/src/Kurs.Platform.Application.Contracts/Identity/Dto/AssignedBranchViewModel.cs new file mode 100644 index 00000000..bfd06bd5 --- /dev/null +++ b/api/src/Kurs.Platform.Application.Contracts/Identity/Dto/AssignedBranchViewModel.cs @@ -0,0 +1,12 @@ +using System; + +namespace Kurs.Platform.Identity.Dto; + +public class AssignedBranchViewModel +{ + public Guid Id { get; set; } + + public string Name { get; set; } + + public bool IsAssigned { get; set; } +} diff --git a/api/src/Kurs.Platform.Application.Contracts/Identity/Dto/UserInfoViewModel.cs b/api/src/Kurs.Platform.Application.Contracts/Identity/Dto/UserInfoViewModel.cs index cfd7313d..d4e9ffc4 100644 --- a/api/src/Kurs.Platform.Application.Contracts/Identity/Dto/UserInfoViewModel.cs +++ b/api/src/Kurs.Platform.Application.Contracts/Identity/Dto/UserInfoViewModel.cs @@ -36,6 +36,8 @@ public class UserInfoViewModel: ExtensibleObject public AssignedRoleViewModel[] Roles { get; set; } + public AssignedBranchViewModel[] Branches { get; set; } + public bool LockUser { get; set; } public DateTimeOffset? LastPasswordChangeTime { get; set; } diff --git a/api/src/Kurs.Platform.Application.Contracts/ListForms/GridOptionsDto/GridOptionsDto.cs b/api/src/Kurs.Platform.Application.Contracts/ListForms/GridOptionsDto/GridOptionsDto.cs index e9431637..0a76e049 100644 --- a/api/src/Kurs.Platform.Application.Contracts/ListForms/GridOptionsDto/GridOptionsDto.cs +++ b/api/src/Kurs.Platform.Application.Contracts/ListForms/GridOptionsDto/GridOptionsDto.cs @@ -270,7 +270,7 @@ public class GridOptionsDto : AuditedEntityDto /// /// Liste formların branch çalışıp çalışmadığını ifade eder. /// - public bool IsBranch { get; set; } + public bool IsBranch { get; set; } = false; /// /// Liste formların ou'lu çalışıp çalışmadığını ifade eder. /// diff --git a/api/src/Kurs.Platform.Application/Identity/PlatformIdentityAppService.cs b/api/src/Kurs.Platform.Application/Identity/PlatformIdentityAppService.cs index 9007982c..b5e1e298 100644 --- a/api/src/Kurs.Platform.Application/Identity/PlatformIdentityAppService.cs +++ b/api/src/Kurs.Platform.Application/Identity/PlatformIdentityAppService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Kurs.Platform.Entities; using Kurs.Platform.Extensions; using Kurs.Platform.Identity.Dto; using Microsoft.AspNetCore.Authorization; @@ -18,18 +19,23 @@ public class PlatformIdentityAppService : ApplicationService public IIdentityUserAppService IdentityUserAppService { get; } private readonly IIdentityUserRepository identityUserRepository; public IRepository permissionRepository { get; } - + public IRepository branchRepository { get; } + public IRepository branchUsersRepository { get; } public IdentityUserManager UserManager { get; set; } public PlatformIdentityAppService( IIdentityUserAppService identityUserAppService, IIdentityUserRepository identityUserRepository, - IRepository permissionRepository + IRepository permissionRepository, + IRepository branchRepository, + IRepository branchUsersRepository ) { this.IdentityUserAppService = identityUserAppService; this.identityUserRepository = identityUserRepository; this.permissionRepository = permissionRepository; + this.branchRepository = branchRepository; + this.branchUsersRepository = branchUsersRepository; } public async Task GetByIdAsync(Guid UserId) @@ -46,6 +52,19 @@ public class PlatformIdentityAppService : ApplicationService } } + var query = await branchUsersRepository.GetQueryableAsync(); + var branchUsers = query.Where(a => a.UserId == UserId).Select(r => r.BranchId).ToList(); + var currentTenantId = CurrentTenant.Id.HasValue ? CurrentTenant.Id : null; + + var branchList = await branchRepository.GetListAsync(a=> a.TenantId == currentTenantId); + var branches = branchList.Select(branch => new AssignedBranchViewModel + { + Id = branch.Id, + Name = branch.Name, + IsAssigned = branchUsers.Contains(branch.Id) + }) + .ToArray(); + return new UserInfoViewModel() { Id = user.Id, @@ -53,6 +72,7 @@ public class PlatformIdentityAppService : ApplicationService Name = user.Name, Surname = user.Surname, Roles = roles, + Branches = branches, Email = user.Email, PhoneNumber = user.PhoneNumber, IsActive = user.IsActive, @@ -126,6 +146,29 @@ public class PlatformIdentityAppService : ApplicationService user.SetRocketUsername(UserInfo.RocketUsername); await UserManager.UpdateAsync(user); + + //Braches bu kısımda güncelleniyor. + var existingBranches = await branchUsersRepository.GetListAsync(x => x.UserId == user.Id); + foreach (var item in existingBranches) + { + await branchUsersRepository.DeleteAsync(item); + } + + // 2. Yeni atamaları ekle + var assignedBranchIds = UserInfo.Branches + .Where(b => b.IsAssigned) + .Select(b => b.Id) + .ToList(); + + foreach (var branchId in assignedBranchIds) + { + var branchUser = new BranchUsers + { + UserId = user.Id, + BranchId = branchId + }; + await branchUsersRepository.InsertAsync(branchUser); + } } public async Task> GetPermissionList() diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/ListFormsSeeder.cs b/api/src/Kurs.Platform.DbMigrator/Seeds/ListFormsSeeder.cs index e1b40443..c8dba414 100644 --- a/api/src/Kurs.Platform.DbMigrator/Seeds/ListFormsSeeder.cs +++ b/api/src/Kurs.Platform.DbMigrator/Seeds/ListFormsSeeder.cs @@ -8073,7 +8073,7 @@ public class ListFormsSeeder : IDataSeedContributor, ITransientDependency }, new ListFormField { - ListFormCode = listFormTenants.ListFormCode, + ListFormCode = listFormBranches.ListFormCode, RoleId = null, UserId = null, CultureName = LanguageCodes.En, diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/SeederData.json b/api/src/Kurs.Platform.DbMigrator/Seeds/SeederData.json index 41537b66..dedad383 100644 --- a/api/src/Kurs.Platform.DbMigrator/Seeds/SeederData.json +++ b/api/src/Kurs.Platform.DbMigrator/Seeds/SeederData.json @@ -1962,6 +1962,42 @@ "en": "Role Management", "tr": "Rol Yönetimi" }, + { + "resourceName": "Platform", + "key": "Abp.Identity.User.UserInformation.BranchManagement", + "en": "Branch Management", + "tr": "Şube Yönetimi" + }, + { + "resourceName": "Platform", + "key": "Abp.Identity.User.UserInformation.PersonalInformation", + "en": "Personal Information", + "tr": "Kişisel Bilgiler" + }, + { + "resourceName": "Platform", + "key": "Abp.Identity.User.UserInformation.ContactInformation", + "en": "Contact Information", + "tr": "İletişim Bilgileri" + }, + { + "resourceName": "Platform", + "key": "Abp.Identity.User.UserInformation.AccountTimestamps", + "en": "Account Timestamps", + "tr": "Zaman Damgaları" + }, + { + "resourceName": "Platform", + "key": "Abp.Identity.User.LockoutManagement.AccountStatus", + "en": "Account Status", + "tr": "Hesap Durumları" + }, + { + "resourceName": "Platform", + "key": "Abp.Identity.User.LockoutManagement.LoginAndLockoutSettings", + "en": "Login And Lockout Settings", + "tr": "Giriş ve Kilit Ayarları" + }, { "resourceName": "Platform", "key": "Abp.Identity.User.UserInformation.EmailAddress", diff --git a/api/src/Kurs.Platform.Domain/Branches/IPlatformBranchesRepository.cs b/api/src/Kurs.Platform.Domain/Branches/IPlatformBranchesRepository.cs deleted file mode 100644 index 525fa2fd..00000000 --- a/api/src/Kurs.Platform.Domain/Branches/IPlatformBranchesRepository.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Kurs.Platform.Branches; - -public interface IPlatformBranchesRepository -{ - Task> GetBranchIdsWithUserId(Guid userId); -} diff --git a/api/src/Kurs.Platform.Domain/ListForms/ListFormManager.cs b/api/src/Kurs.Platform.Domain/ListForms/ListFormManager.cs index bfe6e5ed..fda6f1ca 100644 --- a/api/src/Kurs.Platform.Domain/ListForms/ListFormManager.cs +++ b/api/src/Kurs.Platform.Domain/ListForms/ListFormManager.cs @@ -1,5 +1,4 @@ -using Kurs.Platform.Branches; -using Kurs.Platform.Entities; +using Kurs.Platform.Entities; using Kurs.Platform.Enums; using Kurs.Platform.Localization; using Kurs.Platform.OrganizationUnits; @@ -38,7 +37,7 @@ public class ListFormManager : PlatformDomainService, IListFormManager private readonly IRepository listFormRepository; private readonly IDefaultValueManager defaultValueManager; private readonly IPlatformOuRepository ouRepository; - private readonly IPlatformBranchesRepository branchUsersRepository; + private readonly IRepository branchUsersRepository; private readonly string cultureName; private readonly string cultureNameDefault; @@ -51,7 +50,7 @@ public class ListFormManager : PlatformDomainService, IListFormManager IRepository listFormRepository, IDefaultValueManager defaultValueManager, IPlatformOuRepository ouRepository, - IPlatformBranchesRepository branchUsersRepository) + IRepository branchUsersRepository) : base(settingProvider, localizer, currentUser, objectMapper, authManager) { this.listFormRepository = listFormRepository; @@ -133,10 +132,10 @@ public class ListFormManager : PlatformDomainService, IListFormManager if (listForm.IsBranch) { - var ids = await branchUsersRepository.GetBranchIdsWithUserId(CurrentUser.Id.Value); + var ids = await branchUsersRepository.GetListAsync((a) => a.UserId == CurrentUser.Id.Value); if (ids.Count > 0) { - fields.Add("BranchId", $"IN ({string.Join(",", ids.Select(a => $"'{a}'"))})"); + fields.Add("BranchId", $"IN ({string.Join(",", ids.Select(a => $"'{a.BranchId}'"))})"); } else { diff --git a/api/src/Kurs.Platform.Domain/Queries/SelectQueryManager.cs b/api/src/Kurs.Platform.Domain/Queries/SelectQueryManager.cs index b710d7e5..2685e3fb 100644 --- a/api/src/Kurs.Platform.Domain/Queries/SelectQueryManager.cs +++ b/api/src/Kurs.Platform.Domain/Queries/SelectQueryManager.cs @@ -5,7 +5,6 @@ using System.Globalization; using System.Linq; using System.Text; using System.Text.Json; -using Kurs.Platform.Branches; using Kurs.Platform.Entities; using Kurs.Platform.Enums; using Kurs.Platform.Extensions; @@ -13,6 +12,7 @@ using Kurs.Platform.ListForms; using Kurs.Platform.Localization; using Kurs.Platform.OrganizationUnits; using Microsoft.Extensions.Localization; +using Volo.Abp.Domain.Repositories; using Volo.Abp.ObjectMapping; using Volo.Abp.Settings; using Volo.Abp.Users; @@ -104,7 +104,7 @@ public class SelectQueryManager : PlatformDomainService, ISelectQueryManager public bool IsAppliedGridFilter { get; private set; } public bool IsAppliedServerFilter { get; private set; } public IPlatformOuRepository OuRepository { get; } - public IPlatformBranchesRepository BranchesRepository { get; } + public IRepository BranchUsersRepository { get; } public SelectQueryManager( ISettingProvider settingProvider, @@ -113,7 +113,7 @@ public class SelectQueryManager : PlatformDomainService, ISelectQueryManager IObjectMapper objectMapper, IListFormAuthorizationManager authManager, IPlatformOuRepository ouRepository, - IPlatformBranchesRepository branchesRepository) + IRepository branchUsersRepository) : base(settingProvider, localizer, currentUser, objectMapper, authManager) { SelectFields = []; @@ -122,7 +122,7 @@ public class SelectQueryManager : PlatformDomainService, ISelectQueryManager SortParts = []; SummaryQueries = []; OuRepository = ouRepository; - BranchesRepository = branchesRepository; + BranchUsersRepository = branchUsersRepository; } public void PrepareQueries(ListForm listform, @@ -407,10 +407,10 @@ public class SelectQueryManager : PlatformDomainService, ISelectQueryManager whereParts.Add("AND"); } - var ids = BranchesRepository.GetBranchIdsWithUserId(CurrentUser.Id.Value).Result; + var ids = BranchUsersRepository.GetListAsync((a) => a.UserId == CurrentUser.Id.Value).Result; if (ids.Count > 0) { - whereParts.Add($"\"BranchId\" IN ({string.Join(",", ids.Select(a => $"'{a}'"))})"); + whereParts.Add($"\"BranchId\" IN ({string.Join(",", ids.Select(a => $"'{a.BranchId}'"))})"); } else { diff --git a/api/src/Kurs.Platform.EntityFrameworkCore/Branches/PlatformBranchRepository.cs b/api/src/Kurs.Platform.EntityFrameworkCore/Branches/PlatformBranchRepository.cs deleted file mode 100644 index 64807c1b..00000000 --- a/api/src/Kurs.Platform.EntityFrameworkCore/Branches/PlatformBranchRepository.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Linq.Dynamic.Core; -using System.Threading.Tasks; -using Kurs.Platform.Entities; -using Kurs.Platform.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; -using Volo.Abp.Domain.Repositories.EntityFrameworkCore; -using Volo.Abp.EntityFrameworkCore; -using Volo.Abp.Identity; - -namespace Kurs.Platform.Branches -{ - public class PlatformBranchRepository : EfCoreRepository, IPlatformBranchesRepository - { - public PlatformBranchRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) - { - } - - public async Task> GetBranchIdsWithUserId(Guid userId) - { - var query = await GetQueryableAsync(userId); - var organizationUnitCodes = await query.Select(ou => ou.Code).ToListAsync(); - var dbContext = await GetDbContextAsync(); - - return await dbContext.OrganizationUnits - .Where(a => organizationUnitCodes.Any(b => a.Code.StartsWith(b))) - .Select(a => a.Id) - .ToListAsync(); - } - - //Get IQueryable - private async Task> GetQueryableAsync(Guid userId) - { - var dbContext = await GetDbContextAsync(); - var query = from userBranch in dbContext.Set() - join branch in dbContext.Branches on userBranch.BranchId equals branch.Id - where userBranch.UserId == userId - select branch; - - return query; - } - } -} diff --git a/api/src/Kurs.Platform.HttpApi.Host/Program.cs b/api/src/Kurs.Platform.HttpApi.Host/Program.cs index ec39615a..0128890b 100644 --- a/api/src/Kurs.Platform.HttpApi.Host/Program.cs +++ b/api/src/Kurs.Platform.HttpApi.Host/Program.cs @@ -34,7 +34,8 @@ public class Program }; var loggerConfig = new LoggerConfiguration() - .MinimumLevel.Information(); + .MinimumLevel.Error() + .WriteTo.Console(); // Konsola da log yaz switch (DefaultDatabaseProvider) { diff --git a/ui/dev-dist/sw.js b/ui/dev-dist/sw.js index 7169b65e..040b53cb 100644 --- a/ui/dev-dist/sw.js +++ b/ui/dev-dist/sw.js @@ -82,7 +82,7 @@ define(['./workbox-54d0af47'], (function (workbox) { 'use strict'; "revision": "3ca0b8505b4bec776b69afdba2768812" }, { "url": "index.html", - "revision": "0.5oedcrigdno" + "revision": "0.13cgdm1rjp" }], {}); workbox.cleanupOutdatedCaches(); workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), { diff --git a/ui/src/proxy/admin/models.ts b/ui/src/proxy/admin/models.ts index 594a09a2..82aea1b0 100644 --- a/ui/src/proxy/admin/models.ts +++ b/ui/src/proxy/admin/models.ts @@ -122,6 +122,7 @@ export interface UserInfoViewModel extends ExtensibleObject { isVerified: boolean userRoleNames: string[] roles: AssignedRoleViewModel[] + branches: AssignedRoleViewModel[] lockUser: boolean lastPasswordChangeTime?: Date | string @@ -138,3 +139,8 @@ export interface AssignedRoleViewModel { name?: string isAssigned: boolean } + +export interface AssignedBranchViewModel { + name?: string + isAssigned: boolean +} \ No newline at end of file diff --git a/ui/src/proxy/form/models.ts b/ui/src/proxy/form/models.ts index a34e2924..e0dfc4e4 100644 --- a/ui/src/proxy/form/models.ts +++ b/ui/src/proxy/form/models.ts @@ -472,6 +472,7 @@ export interface GridOptionsDto extends AuditedEntityDto { insertServiceAddress?: string deleteServiceAddress?: string isTenant: boolean + isBranch: boolean isOrganizationUnit: boolean listFormType: string isSubForm: boolean diff --git a/ui/src/views/admin/identity/Users/Details.tsx b/ui/src/views/admin/identity/Users/Details.tsx index b6c85b80..2728864c 100644 --- a/ui/src/views/admin/identity/Users/Details.tsx +++ b/ui/src/views/admin/identity/Users/Details.tsx @@ -79,149 +79,150 @@ function UserDetails() { {({ touched, errors, resetForm, isSubmitting, values }) => { const userRoleNames = values.userRoleNames const roles = values.roles + const branches = values.branches return (
- -
-
{translate('::Abp.Identity.User.UserInformation.RoleManagement')}
-
- - {({ form, remove, push }) => ( -
- {roles && roles.length > 0 - ? roles.map((_, index: number) => { - return ( -
- - - -
+
+ +
+ {/* Personal Information */} +
+ + + +
+ + {/* Personal Information */} +
+ + + +
+ + {/* Şube Management */} +
+
{translate('::Abp.Identity.User.UserInformation.BranchManagement')}
+
+ + {({ form, remove, push }) => ( +
+ {branches && branches.length > 0 + ? branches.map((_, index: number) => ( +
+ + + +
+ )) + : null} +
+ )} +
+
+
+ + {/* Role Management */} +
+
{translate('::Abp.Identity.User.UserInformation.RoleManagement')}
+
+ + {({ form, remove, push }) => ( +
+ {roles && roles.length > 0 + ? roles.map((_, index: number) => ( +
+ + + +
+ )) + : null} +
+ )} +
+
+
+ + {/* Contact Information */} +
+
{translate('::Abp.Identity.User.UserInformation.ContactInformation')}
+ + + + + + + + + +
+ + {/* Account Timestamps */} +
+
{translate('::Abp.Identity.User.UserInformation.AccountTimestamps')}
+ + + {({ field, form }: FieldProps) => ( + { + form.setFieldValue( + field.name, + date ? dayjs(date).format('YYYY-MM-DDTHH:mm:ss[Z]') : null, ) - }) - : null} -
- )} - + }} + /> + )} + + + + + {({ field, form }: FieldProps) => ( + + )} + + + + + {({ field, form }: FieldProps) => ( + + )} + + +
-
- - - - - - - - - - - - - - - - - - - - {({ field, form }: FieldProps) => ( - { - form.setFieldValue( - field.name, - date ? dayjs(date).format('YYYY-MM-DDTHH:mm:ss[Z]') : null, - ) - }} - /> - )} - - - - - - - - - - {({ field, form }: FieldProps) => ( - - )} - - - - - {({ field, form }: FieldProps) => ( - - )} - - -
- + +