2026-02-24 20:44:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2026-07-31 17:55:45 +00:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
2026-06-07 20:45:39 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-06-10 21:38:20 +00:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2026-04-28 12:43:19 +00:00
|
|
|
|
using OpenIddict.Abstractions;
|
2026-08-21 19:27:59 +00:00
|
|
|
|
using Sozsoft.Platform.BlobStoring;
|
|
|
|
|
|
using Sozsoft.Platform.Entities;
|
|
|
|
|
|
using Sozsoft.Platform.Extensions;
|
|
|
|
|
|
using Sozsoft.Platform.Identity.Dto;
|
2026-10-02 23:11:39 +00:00
|
|
|
|
using Volo.Abp;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
|
|
|
using Volo.Abp.Guids;
|
|
|
|
|
|
using Volo.Abp.Identity;
|
|
|
|
|
|
using Volo.Abp.PermissionManagement;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Sozsoft.Platform.Identity;
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
public class PlatformIdentityAppService : ApplicationService
|
|
|
|
|
|
{
|
|
|
|
|
|
public IIdentityUserAppService IdentityUserAppService { get; }
|
|
|
|
|
|
private readonly IIdentityUserRepository identityUserRepository;
|
2026-06-10 09:19:57 +00:00
|
|
|
|
private readonly IIdentityRoleRepository identityRoleRepository;
|
2026-04-28 12:43:19 +00:00
|
|
|
|
private readonly IIdentitySessionRepository identitySessionRepository;
|
|
|
|
|
|
private readonly IOpenIddictTokenManager openIddictTokenManager;
|
2026-06-10 09:19:57 +00:00
|
|
|
|
private readonly IPermissionGrantRepository permissionGrantRepository;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
public IRepository<PermissionDefinitionRecord, Guid> permissionRepository { get; }
|
|
|
|
|
|
public IRepository<Branch, Guid> branchRepository { get; }
|
|
|
|
|
|
public IRepository<BranchUsers, Guid> branchUsersRepository { get; }
|
|
|
|
|
|
public IRepository<IdentityClaimType, Guid> claimTypesRepository { get; }
|
|
|
|
|
|
public IGuidGenerator guidGenerator { get; }
|
|
|
|
|
|
public IdentityUserManager UserManager { get; set; }
|
2026-04-26 19:05:19 +00:00
|
|
|
|
public IRepository<WorkHour, Guid> workHourRepository { get; }
|
2026-05-04 14:35:18 +00:00
|
|
|
|
public IRepository<Department, Guid> departmentRepository { get; }
|
|
|
|
|
|
public IRepository<JobPosition, Guid> jobPositionRepository { get; }
|
2026-06-07 20:45:39 +00:00
|
|
|
|
public BlobManager BlobCdnManager { get; }
|
2026-06-10 21:38:20 +00:00
|
|
|
|
private readonly IConfiguration configuration;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
public PlatformIdentityAppService(
|
|
|
|
|
|
IIdentityUserAppService identityUserAppService,
|
|
|
|
|
|
IIdentityUserRepository identityUserRepository,
|
2026-06-10 09:19:57 +00:00
|
|
|
|
IIdentityRoleRepository identityRoleRepository,
|
2026-04-28 12:43:19 +00:00
|
|
|
|
IIdentitySessionRepository identitySessionRepository,
|
|
|
|
|
|
IOpenIddictTokenManager openIddictTokenManager,
|
2026-06-10 09:19:57 +00:00
|
|
|
|
IPermissionGrantRepository permissionGrantRepository,
|
2026-02-24 20:44:16 +00:00
|
|
|
|
IRepository<PermissionDefinitionRecord, Guid> permissionRepository,
|
|
|
|
|
|
IRepository<Branch, Guid> branchRepository,
|
|
|
|
|
|
IRepository<BranchUsers, Guid> branchUsersRepository,
|
|
|
|
|
|
IRepository<IdentityClaimType, Guid> claimTypesRepository,
|
2026-04-26 19:05:19 +00:00
|
|
|
|
IRepository<WorkHour, Guid> workHourRepository,
|
2026-05-04 14:35:18 +00:00
|
|
|
|
IRepository<Department, Guid> departmentRepository,
|
|
|
|
|
|
IRepository<JobPosition, Guid> jobPositionRepository,
|
2026-06-07 20:45:39 +00:00
|
|
|
|
BlobManager blobCdnManager,
|
2026-06-10 21:38:20 +00:00
|
|
|
|
IConfiguration configuration,
|
2026-02-24 20:44:16 +00:00
|
|
|
|
IGuidGenerator guidGenerator
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.IdentityUserAppService = identityUserAppService;
|
|
|
|
|
|
this.identityUserRepository = identityUserRepository;
|
2026-06-10 09:19:57 +00:00
|
|
|
|
this.identityRoleRepository = identityRoleRepository;
|
2026-04-28 12:43:19 +00:00
|
|
|
|
this.identitySessionRepository = identitySessionRepository;
|
|
|
|
|
|
this.openIddictTokenManager = openIddictTokenManager;
|
2026-06-10 09:19:57 +00:00
|
|
|
|
this.permissionGrantRepository = permissionGrantRepository;
|
2026-04-26 19:05:19 +00:00
|
|
|
|
this.workHourRepository = workHourRepository;
|
2026-05-04 14:35:18 +00:00
|
|
|
|
this.departmentRepository = departmentRepository;
|
|
|
|
|
|
this.jobPositionRepository = jobPositionRepository;
|
2026-06-07 20:45:39 +00:00
|
|
|
|
this.BlobCdnManager = blobCdnManager;
|
2026-06-10 21:38:20 +00:00
|
|
|
|
this.configuration = configuration;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
this.permissionRepository = permissionRepository;
|
|
|
|
|
|
this.branchRepository = branchRepository;
|
|
|
|
|
|
this.branchUsersRepository = branchUsersRepository;
|
|
|
|
|
|
this.claimTypesRepository = claimTypesRepository;
|
|
|
|
|
|
this.guidGenerator = guidGenerator;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<UserInfoViewModel> GetByIdAsync(Guid UserId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var user = await identityUserRepository.GetAsync(UserId);
|
|
|
|
|
|
|
|
|
|
|
|
var userRoleNames = (await IdentityUserAppService.GetRolesAsync(user.Id)).Items.Select(r => r.Name).ToList();
|
|
|
|
|
|
var roles = ObjectMapper.Map<IReadOnlyList<IdentityRoleDto>, AssignedRoleViewModel[]>((await IdentityUserAppService.GetAssignableRolesAsync()).Items);
|
|
|
|
|
|
foreach (var role in roles)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (userRoleNames.Contains(role.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
role.IsAssigned = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var currentTenantId = CurrentTenant.Id.HasValue ? CurrentTenant.Id : null;
|
|
|
|
|
|
|
|
|
|
|
|
//Branch
|
|
|
|
|
|
var queryBranch = await branchUsersRepository.GetQueryableAsync();
|
2026-07-11 20:35:32 +00:00
|
|
|
|
var branchUsers = await AsyncExecuter.ToListAsync(
|
|
|
|
|
|
queryBranch.Where(a => a.UserId == UserId).Select(r => r.BranchId));
|
2026-02-24 20:44:16 +00:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
//Claim
|
|
|
|
|
|
var claimUsers = user.Claims;
|
|
|
|
|
|
var claimList = await claimTypesRepository.GetListAsync();
|
|
|
|
|
|
var claims = claimList.Select(claim =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var userClaim = claimUsers.FirstOrDefault(c => c.ClaimType == claim.Name);
|
|
|
|
|
|
return new AssignedClaimViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = userClaim?.Id ?? Guid.Empty,
|
|
|
|
|
|
ClaimType = claim.Name,
|
|
|
|
|
|
ClaimValue = userClaim?.ClaimValue,
|
|
|
|
|
|
IsAssigned = userClaim != null
|
|
|
|
|
|
};
|
|
|
|
|
|
}).ToArray();
|
|
|
|
|
|
|
2026-04-26 19:05:19 +00:00
|
|
|
|
var workHourList = await workHourRepository.GetListAsync();
|
|
|
|
|
|
var workHours = workHourList.Select(workHour => new AssignedWorkHourViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = workHour.Id,
|
|
|
|
|
|
Name = workHour.Name,
|
|
|
|
|
|
IsAssigned = workHourList.Contains(workHour)
|
|
|
|
|
|
}).ToArray();
|
2026-05-04 14:35:18 +00:00
|
|
|
|
|
|
|
|
|
|
var departmentList = await departmentRepository.GetListAsync();
|
2026-07-11 20:35:32 +00:00
|
|
|
|
var departments = departmentList.Select(department => new AssignedDepartmentViewModel
|
2026-05-04 14:35:18 +00:00
|
|
|
|
{
|
|
|
|
|
|
Id = department.Id,
|
|
|
|
|
|
Name = department.Name,
|
|
|
|
|
|
IsAssigned = departmentList.Contains(department)
|
|
|
|
|
|
}).ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
var jobPositionList = await jobPositionRepository.GetListAsync();
|
2026-07-11 20:35:32 +00:00
|
|
|
|
var jobPositions = jobPositionList.Select(jobPosition => new AssignedJobPoisitionViewModel
|
2026-05-04 14:35:18 +00:00
|
|
|
|
{
|
|
|
|
|
|
Id = jobPosition.Id,
|
|
|
|
|
|
Name = jobPosition.Name,
|
|
|
|
|
|
DepartmentId = jobPosition.DepartmentId,
|
|
|
|
|
|
IsAssigned = jobPositionList.Contains(jobPosition)
|
|
|
|
|
|
}).ToArray();
|
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
|
return new UserInfoViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = user.Id,
|
2026-05-27 22:30:13 +00:00
|
|
|
|
TenantId = user.TenantId,
|
2026-02-24 20:44:16 +00:00
|
|
|
|
UserName = user.UserName,
|
|
|
|
|
|
Name = user.Name,
|
|
|
|
|
|
Surname = user.Surname,
|
|
|
|
|
|
Roles = roles,
|
|
|
|
|
|
Branches = branches,
|
2026-05-04 14:35:18 +00:00
|
|
|
|
Departments = departments,
|
|
|
|
|
|
JobPositions = jobPositions,
|
2026-02-24 20:44:16 +00:00
|
|
|
|
Claims = claims,
|
2026-04-26 19:05:19 +00:00
|
|
|
|
WorkHours = workHours,
|
2026-02-24 20:44:16 +00:00
|
|
|
|
Email = user.Email,
|
|
|
|
|
|
PhoneNumber = user.PhoneNumber,
|
|
|
|
|
|
IsActive = user.IsActive,
|
|
|
|
|
|
TwoFactorEnabled = user.TwoFactorEnabled,
|
2026-10-02 13:58:22 +00:00
|
|
|
|
IsVerified = user.GetIsVerified(),
|
2026-02-24 20:44:16 +00:00
|
|
|
|
userRoleNames = userRoleNames,
|
|
|
|
|
|
LockoutEnabled = user.LockoutEnabled,
|
|
|
|
|
|
LockoutEnd = user.LockoutEnd,
|
2026-04-27 21:29:03 +00:00
|
|
|
|
LockUser = user.LockoutEnabled && user.LockoutEnd.HasValue && user.LockoutEnd.Value.DateTime > DateTime.Now,
|
2026-02-24 20:44:16 +00:00
|
|
|
|
LoginEndDate = user.GetLoginEndDate(),
|
|
|
|
|
|
ConcurrencyStamp = user.ConcurrencyStamp,
|
|
|
|
|
|
LastPasswordChangeTime = user.LastPasswordChangeTime,
|
2026-06-11 11:38:48 +00:00
|
|
|
|
Avatar = user.GetAvatar(),
|
2026-10-02 23:11:39 +00:00
|
|
|
|
// Rapor dosyasi ortak esleme yerine yalnizca detayda doldurulur; ortak esleme intranet listelerine de akar.
|
|
|
|
|
|
DisabilityReport = user.GetDisabilityReport(),
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
EmailConfirmed = user.EmailConfirmed,
|
|
|
|
|
|
PhoneNumberConfirmed = user.PhoneNumberConfirmed,
|
|
|
|
|
|
AccessFailedCount = user.AccessFailedCount,
|
|
|
|
|
|
ShouldChangePasswordOnNextLogin = user.ShouldChangePasswordOnNextLogin,
|
|
|
|
|
|
CreationTime = user.CreationTime,
|
|
|
|
|
|
LastModificationTime = user.LastModificationTime,
|
2026-05-05 07:23:02 +00:00
|
|
|
|
|
2026-05-06 19:07:30 +00:00
|
|
|
|
}.MapIdentityExtraProperties(user);
|
2026-02-24 20:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-04 14:35:18 +00:00
|
|
|
|
public async Task UpdatePermissionAsync(UserInfoViewModel UserInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
var roles = UserInfo.Roles.Where(r => r.IsAssigned).Select(r => r.Name).ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
var user = await UserManager.GetByIdAsync(UserInfo.Id);
|
|
|
|
|
|
await UserManager.SetRolesAsync(user, roles);
|
|
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
|
public async Task UpdateLockoutAsync(UserInfoViewModel UserInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
var user = await UserManager.GetByIdAsync(UserInfo.Id);
|
|
|
|
|
|
if (UserInfo.LockUser)
|
|
|
|
|
|
{
|
|
|
|
|
|
await UserManager.SetLockoutEnabledAsync(user, true);
|
2026-04-27 21:29:03 +00:00
|
|
|
|
await UserManager.SetLockoutEndDateAsync(user, DateTime.Now.AddYears(1000));
|
2026-02-24 20:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
await UserManager.SetLockoutEndDateAsync(user, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Admin Verification
|
|
|
|
|
|
user.SetIsVerified(UserInfo.IsVerified);
|
|
|
|
|
|
|
|
|
|
|
|
//Two Factor Enabled
|
|
|
|
|
|
await UserManager.SetTwoFactorEnabledAsync(user, UserInfo.TwoFactorEnabled);
|
|
|
|
|
|
|
|
|
|
|
|
//LoginEndDate
|
|
|
|
|
|
user.SetLoginEndDate(UserInfo.LoginEndDate);
|
2026-04-26 19:05:19 +00:00
|
|
|
|
user.SetWorkHour(UserInfo.WorkHour);
|
2026-02-24 20:44:16 +00:00
|
|
|
|
user.SetIsActive(UserInfo.IsActive);
|
2026-05-27 22:30:13 +00:00
|
|
|
|
user.SetLastPasswordChangeTime(UserInfo.LastPasswordChangeTime);
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
user.SetEmailConfirmed(UserInfo.EmailConfirmed);
|
|
|
|
|
|
user.SetPhoneNumberConfirmed(UserInfo.PhoneNumberConfirmed);
|
|
|
|
|
|
user.SetShouldChangePasswordOnNextLogin(UserInfo.ShouldChangePasswordOnNextLogin);
|
|
|
|
|
|
|
|
|
|
|
|
if (UserInfo.AccessFailedCount == 0 && user.AccessFailedCount > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
await UserManager.ResetAccessFailedCountAsync(user);
|
|
|
|
|
|
}
|
|
|
|
|
|
await UserManager.SetLockoutEnabledAsync(user, UserInfo.LockoutEnabled);
|
|
|
|
|
|
await UserManager.UpdateAsync(user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateUserAsync(UserInfoViewModel UserInfo)
|
|
|
|
|
|
{
|
2026-10-02 23:11:39 +00:00
|
|
|
|
// 4857 s. Is Kanunu md. 15: deneme suresi en fazla iki ay, toplu sozlesmeyle dort ay.
|
|
|
|
|
|
// Hangi sinirin gecerli oldugu sozlesmeye bagli oldugu icin ust sinir dort aydir.
|
|
|
|
|
|
if (UserInfo.HireDate.HasValue && UserInfo.ProbationEndDate.HasValue
|
|
|
|
|
|
&& (UserInfo.ProbationEndDate < UserInfo.HireDate || UserInfo.ProbationEndDate > UserInfo.HireDate.Value.AddMonths(4)))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new UserFriendlyException(L["Abp.Identity.User.ProbationPeriodInvalid"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
|
var user = await UserManager.GetByIdAsync(UserInfo.Id);
|
|
|
|
|
|
|
|
|
|
|
|
user.Name = UserInfo.Name;
|
|
|
|
|
|
user.Surname = UserInfo.Surname;
|
|
|
|
|
|
user.SetPhoneNumber(UserInfo.PhoneNumber, user.PhoneNumberConfirmed);
|
|
|
|
|
|
user.SetRocketUsername(UserInfo.RocketUsername);
|
2026-08-28 12:03:36 +00:00
|
|
|
|
user.SetTelegramChatId(UserInfo.TelegramChatId);
|
2026-04-26 19:05:19 +00:00
|
|
|
|
user.SetWorkHour(UserInfo.WorkHour);
|
2026-05-04 12:14:16 +00:00
|
|
|
|
user.SetDepartmentId(UserInfo.DepartmentId);
|
|
|
|
|
|
user.SetJobPositionId(UserInfo.JobPositionId);
|
2026-05-05 07:23:02 +00:00
|
|
|
|
user.SetNationality(UserInfo.Nationality);
|
2026-09-30 22:54:21 +00:00
|
|
|
|
user.SetGender(UserInfo.Gender);
|
2026-05-05 07:23:02 +00:00
|
|
|
|
user.SetSskNo(UserInfo.SskNo);
|
|
|
|
|
|
user.SetHireDate(UserInfo.HireDate);
|
|
|
|
|
|
user.SetTerminationDate(UserInfo.TerminationDate);
|
|
|
|
|
|
user.SetIdentityNumber(UserInfo.IdentityNumber);
|
|
|
|
|
|
user.SetSerialNo(UserInfo.SerialNo);
|
|
|
|
|
|
user.SetProvince(UserInfo.Province);
|
|
|
|
|
|
user.SetDistrict(UserInfo.District);
|
|
|
|
|
|
user.SetVillage(UserInfo.Village);
|
|
|
|
|
|
user.SetVolumeNo(UserInfo.VolumeNo);
|
|
|
|
|
|
user.SetFamilySequenceNo(UserInfo.FamilySequenceNo);
|
|
|
|
|
|
user.SetSequenceNo(UserInfo.SequenceNo);
|
|
|
|
|
|
user.SetIssuedPlace(UserInfo.IssuedPlace);
|
|
|
|
|
|
user.SetIssuedDate(UserInfo.IssuedDate);
|
|
|
|
|
|
user.SetBirthPlace(UserInfo.BirthPlace);
|
|
|
|
|
|
user.SetBirthDate(UserInfo.BirthDate);
|
|
|
|
|
|
user.SetFatherName(UserInfo.FatherName);
|
|
|
|
|
|
user.SetMotherName(UserInfo.MotherName);
|
|
|
|
|
|
user.SetMaritalStatus(UserInfo.MaritalStatus);
|
|
|
|
|
|
user.SetMarriageDate(UserInfo.MarriageDate);
|
|
|
|
|
|
user.SetHomeAddress(UserInfo.HomeAddress);
|
|
|
|
|
|
user.SetEducationLevel(UserInfo.EducationLevel);
|
|
|
|
|
|
user.SetBloodType(UserInfo.BloodType);
|
2026-10-01 07:01:21 +00:00
|
|
|
|
user.SetMotherHealthStatus(UserInfo.MotherHealthStatus);
|
|
|
|
|
|
user.SetMotherHealthNote(UserInfo.MotherHealthNote);
|
|
|
|
|
|
user.SetFatherHealthStatus(UserInfo.FatherHealthStatus);
|
|
|
|
|
|
user.SetFatherHealthNote(UserInfo.FatherHealthNote);
|
|
|
|
|
|
user.SetSiblingHealthStatus(UserInfo.SiblingHealthStatus);
|
|
|
|
|
|
user.SetSiblingHealthNote(UserInfo.SiblingHealthNote);
|
|
|
|
|
|
user.SetChildHealthStatus(UserInfo.ChildHealthStatus);
|
|
|
|
|
|
user.SetChildHealthNote(UserInfo.ChildHealthNote);
|
|
|
|
|
|
user.SetChronicDisease(UserInfo.ChronicDisease);
|
|
|
|
|
|
user.SetTetanusVaccination(UserInfo.TetanusVaccination);
|
|
|
|
|
|
user.SetHepatitisVaccination(UserInfo.HepatitisVaccination);
|
|
|
|
|
|
user.SetOtherVaccination(UserInfo.OtherVaccination);
|
|
|
|
|
|
user.SetLabBiologicalAnalysis(UserInfo.LabBiologicalAnalysis);
|
|
|
|
|
|
user.SetLabBlood(UserInfo.LabBlood);
|
|
|
|
|
|
user.SetLabUrine(UserInfo.LabUrine);
|
|
|
|
|
|
user.SetLabRadiological(UserInfo.LabRadiological);
|
|
|
|
|
|
user.SetLabRadiologicalPhysiological(UserInfo.LabRadiologicalPhysiological);
|
|
|
|
|
|
user.SetLabAudiometry(UserInfo.LabAudiometry);
|
|
|
|
|
|
user.SetLabPulmonaryFunction(UserInfo.LabPulmonaryFunction);
|
|
|
|
|
|
user.SetLabPsychologicalTests(UserInfo.LabPsychologicalTests);
|
|
|
|
|
|
user.SetLabOther(UserInfo.LabOther);
|
|
|
|
|
|
user.SetExamSensoryOrgans(UserInfo.ExamSensoryOrgans);
|
|
|
|
|
|
user.SetExamEye(UserInfo.ExamEye);
|
|
|
|
|
|
user.SetExamEnt(UserInfo.ExamEnt);
|
|
|
|
|
|
user.SetExamSkin(UserInfo.ExamSkin);
|
|
|
|
|
|
user.SetExamCardiovascular(UserInfo.ExamCardiovascular);
|
|
|
|
|
|
user.SetExamRespiratory(UserInfo.ExamRespiratory);
|
|
|
|
|
|
user.SetExamDigestive(UserInfo.ExamDigestive);
|
|
|
|
|
|
user.SetExamUrogenital(UserInfo.ExamUrogenital);
|
|
|
|
|
|
user.SetExamMusculoskeletal(UserInfo.ExamMusculoskeletal);
|
|
|
|
|
|
user.SetExamNeurological(UserInfo.ExamNeurological);
|
|
|
|
|
|
user.SetExamPsychiatric(UserInfo.ExamPsychiatric);
|
|
|
|
|
|
user.SetExamOther(UserInfo.ExamOther);
|
|
|
|
|
|
user.SetExamBloodPressure(UserInfo.ExamBloodPressure);
|
|
|
|
|
|
user.SetExamPulse(UserInfo.ExamPulse);
|
|
|
|
|
|
user.SetExamHeight(UserInfo.ExamHeight);
|
|
|
|
|
|
user.SetExamWeight(UserInfo.ExamWeight);
|
|
|
|
|
|
user.SetComplaintProductiveCough(UserInfo.ComplaintProductiveCough);
|
|
|
|
|
|
user.SetComplaintDyspnea(UserInfo.ComplaintDyspnea);
|
|
|
|
|
|
user.SetComplaintChestPain(UserInfo.ComplaintChestPain);
|
|
|
|
|
|
user.SetComplaintPalpitation(UserInfo.ComplaintPalpitation);
|
|
|
|
|
|
user.SetComplaintBackPain(UserInfo.ComplaintBackPain);
|
|
|
|
|
|
user.SetComplaintDiarrheaConstipation(UserInfo.ComplaintDiarrheaConstipation);
|
|
|
|
|
|
user.SetComplaintJointPain(UserInfo.ComplaintJointPain);
|
|
|
|
|
|
user.SetDiagnosisHeartDisease(UserInfo.DiagnosisHeartDisease);
|
|
|
|
|
|
user.SetDiagnosisDiabetes(UserInfo.DiagnosisDiabetes);
|
|
|
|
|
|
user.SetDiagnosisKidneyDisease(UserInfo.DiagnosisKidneyDisease);
|
|
|
|
|
|
user.SetDiagnosisJaundice(UserInfo.DiagnosisJaundice);
|
|
|
|
|
|
user.SetDiagnosisPepticUlcer(UserInfo.DiagnosisPepticUlcer);
|
|
|
|
|
|
user.SetDiagnosisHearingLoss(UserInfo.DiagnosisHearingLoss);
|
|
|
|
|
|
user.SetDiagnosisVisionImpairment(UserInfo.DiagnosisVisionImpairment);
|
|
|
|
|
|
user.SetDiagnosisNervousSystemDisease(UserInfo.DiagnosisNervousSystemDisease);
|
|
|
|
|
|
user.SetDiagnosisSkinDisease(UserInfo.DiagnosisSkinDisease);
|
|
|
|
|
|
user.SetDiagnosisFoodPoisoning(UserInfo.DiagnosisFoodPoisoning);
|
|
|
|
|
|
user.SetHospitalized(UserInfo.Hospitalized);
|
|
|
|
|
|
user.SetHospitalizedNote(UserInfo.HospitalizedNote);
|
|
|
|
|
|
user.SetHadSurgery(UserInfo.HadSurgery);
|
|
|
|
|
|
user.SetHadSurgeryNote(UserInfo.HadSurgeryNote);
|
|
|
|
|
|
user.SetHadWorkAccident(UserInfo.HadWorkAccident);
|
|
|
|
|
|
user.SetHadWorkAccidentNote(UserInfo.HadWorkAccidentNote);
|
|
|
|
|
|
user.SetOccupationalDiseaseExam(UserInfo.OccupationalDiseaseExam);
|
|
|
|
|
|
user.SetOccupationalDiseaseExamNote(UserInfo.OccupationalDiseaseExamNote);
|
|
|
|
|
|
user.SetDisabilityPension(UserInfo.DisabilityPension);
|
|
|
|
|
|
user.SetDisabilityPensionNote(UserInfo.DisabilityPensionNote);
|
|
|
|
|
|
user.SetUnderTreatment(UserInfo.UnderTreatment);
|
|
|
|
|
|
user.SetUnderTreatmentNote(UserInfo.UnderTreatmentNote);
|
|
|
|
|
|
user.SetSmoking(UserInfo.Smoking);
|
|
|
|
|
|
user.SetSmokingNote(UserInfo.SmokingNote);
|
|
|
|
|
|
user.SetAlcohol(UserInfo.Alcohol);
|
|
|
|
|
|
user.SetAlcoholNote(UserInfo.AlcoholNote);
|
|
|
|
|
|
user.SetFitForWorkJob(UserInfo.FitForWorkJob);
|
|
|
|
|
|
user.SetFitForWorkCondition(UserInfo.FitForWorkCondition);
|
|
|
|
|
|
user.SetFitnessDoctorId(UserInfo.FitnessDoctorId);
|
|
|
|
|
|
user.SetShiftWorkFit(UserInfo.ShiftWorkFit);
|
|
|
|
|
|
user.SetNightWorkFit(UserInfo.NightWorkFit);
|
|
|
|
|
|
user.SetShiftNightDoctorId(UserInfo.ShiftNightDoctorId);
|
2026-10-02 23:11:39 +00:00
|
|
|
|
user.SetSecondaryEmail(UserInfo.SecondaryEmail);
|
|
|
|
|
|
user.SetSecondaryPhoneNumber(UserInfo.SecondaryPhoneNumber);
|
|
|
|
|
|
user.SetMilitaryStatus(UserInfo.MilitaryStatus);
|
|
|
|
|
|
user.SetMilitaryPostponeEndDate(UserInfo.MilitaryPostponeEndDate);
|
|
|
|
|
|
user.SetIsDisabled(UserInfo.IsDisabled);
|
|
|
|
|
|
user.SetDisabilityRate(UserInfo.DisabilityRate);
|
|
|
|
|
|
user.SetDisabilityReport(UserInfo.DisabilityReport);
|
|
|
|
|
|
user.SetDisabilityReportFileName(UserInfo.DisabilityReportFileName);
|
|
|
|
|
|
user.SetPassportNo(UserInfo.PassportNo);
|
|
|
|
|
|
user.SetPassportExpiryDate(UserInfo.PassportExpiryDate);
|
|
|
|
|
|
user.SetWorkPermitNo(UserInfo.WorkPermitNo);
|
|
|
|
|
|
user.SetWorkPermitEndDate(UserInfo.WorkPermitEndDate);
|
|
|
|
|
|
user.SetRegistrationNo(UserInfo.RegistrationNo);
|
|
|
|
|
|
user.SetEmploymentType(UserInfo.EmploymentType);
|
|
|
|
|
|
user.SetContractType(UserInfo.ContractType);
|
|
|
|
|
|
user.SetContractEndDate(UserInfo.ContractEndDate);
|
|
|
|
|
|
user.SetProbationEndDate(UserInfo.ProbationEndDate);
|
|
|
|
|
|
user.SetSeniorityStartDate(UserInfo.SeniorityStartDate);
|
|
|
|
|
|
user.SetTerminationReasonId(UserInfo.TerminationReasonId);
|
|
|
|
|
|
user.SetTerminationNote(UserInfo.TerminationNote);
|
|
|
|
|
|
user.SetShiftId(UserInfo.ShiftId);
|
|
|
|
|
|
user.SetPdksCardNo(UserInfo.PdksCardNo);
|
|
|
|
|
|
user.SetDrivingLicenseClass(UserInfo.DrivingLicenseClass);
|
|
|
|
|
|
user.SetDrivingLicenseNo(UserInfo.DrivingLicenseNo);
|
|
|
|
|
|
user.SetDrivingLicenseIssueDate(UserInfo.DrivingLicenseIssueDate);
|
|
|
|
|
|
user.SetDrivingLicenseExpiryDate(UserInfo.DrivingLicenseExpiryDate);
|
2026-06-10 21:38:20 +00:00
|
|
|
|
user.SetAvatar(UserInfo.Avatar);
|
2026-07-31 17:55:45 +00:00
|
|
|
|
user.SetUserType(UserInfo.UserType);
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
2026-07-31 17:55:45 +00:00
|
|
|
|
(await UserManager.UpdateAsync(user)).CheckErrors();
|
2026-02-24 20:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-02 23:11:39 +00:00
|
|
|
|
[Authorize(IdentityPermissions.Users.Update)]
|
|
|
|
|
|
public async Task<UserFinancialDto> GetFinancialAsync(Guid id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var user = await UserManager.GetByIdAsync(id);
|
|
|
|
|
|
|
|
|
|
|
|
return new UserFinancialDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = user.Id,
|
|
|
|
|
|
BankName = user.GetBankName(),
|
|
|
|
|
|
Iban = user.GetIban(),
|
|
|
|
|
|
SalaryType = user.GetSalaryType(),
|
|
|
|
|
|
GrossSalary = user.GetGrossSalary(),
|
|
|
|
|
|
SalaryCurrency = user.GetSalaryCurrency(),
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize(IdentityPermissions.Users.Update)]
|
|
|
|
|
|
public async Task UpdateFinancialAsync(UserFinancialDto input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var user = await UserManager.GetByIdAsync(input.Id);
|
|
|
|
|
|
|
|
|
|
|
|
user.SetBankName(input.BankName);
|
|
|
|
|
|
user.SetIban(input.Iban?.Replace(" ", string.Empty).ToUpperInvariant());
|
|
|
|
|
|
user.SetSalaryType(input.SalaryType);
|
|
|
|
|
|
user.SetGrossSalary(input.GrossSalary);
|
|
|
|
|
|
user.SetSalaryCurrency(input.SalaryCurrency);
|
|
|
|
|
|
|
|
|
|
|
|
(await UserManager.UpdateAsync(user)).CheckErrors();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-07 20:45:39 +00:00
|
|
|
|
[Authorize(IdentityPermissions.Users.Update)]
|
|
|
|
|
|
public async Task UpdateAvatarAsync([FromForm] UserAvatarUpdateInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var user = await UserManager.GetByIdAsync(input.UserId);
|
|
|
|
|
|
var fileName = $"{user.Id}.jpg";
|
|
|
|
|
|
|
|
|
|
|
|
if (input.Avatar is null || input.Avatar.ContentLength == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
await BlobCdnManager.DeleteAsync(BlobContainerNames.Avatar, fileName);
|
2026-06-10 21:38:20 +00:00
|
|
|
|
user.SetAvatar(null);
|
2026-06-07 20:45:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
await BlobCdnManager.SaveAsync(BlobContainerNames.Avatar, fileName, input.Avatar.GetStream());
|
2026-06-10 21:38:20 +00:00
|
|
|
|
user.SetAvatar(AvatarProvider.GetAvatar(configuration, user.TenantId?.ToString(), user.Id.ToString()));
|
2026-06-07 20:45:39 +00:00
|
|
|
|
}
|
2026-06-10 21:38:20 +00:00
|
|
|
|
|
|
|
|
|
|
await UserManager.UpdateAsync(user);
|
2026-06-07 20:45:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
|
public async Task<List<PermissionDefinitionRecord>> GetPermissionList()
|
|
|
|
|
|
{
|
|
|
|
|
|
var list = await permissionRepository.GetListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
return [.. list.OrderBy(p => p.Name)];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-10 09:19:57 +00:00
|
|
|
|
public async Task<List<PermissionGrantedUsersDto>> GetPermissionGrantedUsersAsync(string permissionName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(permissionName))
|
|
|
|
|
|
{
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
permissionName = permissionName.Trim();
|
|
|
|
|
|
|
|
|
|
|
|
var permissions = (await permissionRepository.GetListAsync())
|
|
|
|
|
|
.Where(p => p.Name == permissionName || p.ParentName == permissionName)
|
|
|
|
|
|
.OrderBy(p => p.ParentName == null ? 0 : 1)
|
|
|
|
|
|
.ThenBy(p => p.Name)
|
|
|
|
|
|
.Take(200)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var permissionNames = permissions.Select(p => p.Name).ToHashSet();
|
|
|
|
|
|
if (permissionNames.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var grants = (await permissionGrantRepository.GetListAsync())
|
|
|
|
|
|
.Where(g => permissionNames.Contains(g.Name) && (g.ProviderName == "R" || g.ProviderName == "U"))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var roleNames = grants
|
|
|
|
|
|
.Where(g => g.ProviderName == "R")
|
|
|
|
|
|
.Select(g => g.ProviderKey)
|
|
|
|
|
|
.Where(key => !string.IsNullOrWhiteSpace(key))
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var roles = roleNames.Count == 0
|
|
|
|
|
|
? []
|
|
|
|
|
|
: (await identityRoleRepository.GetListAsync())
|
|
|
|
|
|
.Where(r => roleNames.Contains(r.Name))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var roleIdByName = roles.ToDictionary(r => r.Name, r => r.Id);
|
|
|
|
|
|
var roleNameById = roles.ToDictionary(r => r.Id, r => r.Name);
|
|
|
|
|
|
|
|
|
|
|
|
var roleIds = roleIdByName.Values.ToHashSet();
|
|
|
|
|
|
var directUserIds = grants
|
|
|
|
|
|
.Where(g => g.ProviderName == "U" && Guid.TryParse(g.ProviderKey, out _))
|
|
|
|
|
|
.Select(g => Guid.Parse(g.ProviderKey))
|
|
|
|
|
|
.ToHashSet();
|
|
|
|
|
|
|
|
|
|
|
|
var users = (await identityUserRepository.GetListAsync(includeDetails: true))
|
|
|
|
|
|
.Where(user =>
|
|
|
|
|
|
directUserIds.Contains(user.Id) ||
|
|
|
|
|
|
(user.Roles?.Any(userRole => roleIds.Contains(userRole.RoleId)) ?? false))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return permissions.Select(permission =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var permissionGrants = grants.Where(g => g.Name == permission.Name).ToList();
|
|
|
|
|
|
var permissionRoleNames = permissionGrants
|
|
|
|
|
|
.Where(g => g.ProviderName == "R")
|
|
|
|
|
|
.Select(g => g.ProviderKey)
|
|
|
|
|
|
.Where(roleName => !string.IsNullOrWhiteSpace(roleName) && roleIdByName.ContainsKey(roleName))
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.OrderBy(roleName => roleName)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
var permissionRoleIds = permissionRoleNames.Select(roleName => roleIdByName[roleName]).ToHashSet();
|
|
|
|
|
|
var permissionDirectUserIds = permissionGrants
|
|
|
|
|
|
.Where(g => g.ProviderName == "U" && Guid.TryParse(g.ProviderKey, out _))
|
|
|
|
|
|
.Select(g => Guid.Parse(g.ProviderKey))
|
|
|
|
|
|
.ToHashSet();
|
|
|
|
|
|
|
|
|
|
|
|
var permissionUsers = users
|
|
|
|
|
|
.Where(user =>
|
|
|
|
|
|
permissionDirectUserIds.Contains(user.Id) ||
|
|
|
|
|
|
(user.Roles?.Any(userRole => permissionRoleIds.Contains(userRole.RoleId)) ?? false))
|
|
|
|
|
|
.Select(user =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var userRoleNames = (user.Roles ?? [])
|
|
|
|
|
|
.Where(userRole => permissionRoleIds.Contains(userRole.RoleId))
|
|
|
|
|
|
.Select(userRole => roleNameById[userRole.RoleId])
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.OrderBy(roleName => roleName)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return new PermissionGrantedUserDto
|
|
|
|
|
|
{
|
|
|
|
|
|
TenantId = user.TenantId,
|
|
|
|
|
|
Id = user.Id,
|
|
|
|
|
|
UserName = user.UserName,
|
|
|
|
|
|
Name = user.Name,
|
|
|
|
|
|
Surname = user.Surname,
|
|
|
|
|
|
FullName = $"{user.Name} {user.Surname}".Trim(),
|
|
|
|
|
|
Email = user.Email,
|
|
|
|
|
|
IsActive = user.IsActive,
|
|
|
|
|
|
IsDirectGrant = permissionDirectUserIds.Contains(user.Id),
|
|
|
|
|
|
RoleNames = userRoleNames
|
|
|
|
|
|
};
|
|
|
|
|
|
})
|
|
|
|
|
|
.OrderBy(user => user.UserName)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return new PermissionGrantedUsersDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = permission.Name,
|
|
|
|
|
|
ParentName = permission.ParentName,
|
|
|
|
|
|
DisplayName = permission.DisplayName,
|
|
|
|
|
|
IsEnabled = permission.IsEnabled,
|
|
|
|
|
|
RoleNames = permissionRoleNames,
|
|
|
|
|
|
Users = permissionUsers
|
|
|
|
|
|
};
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
|
public async Task CreateClaimUserAsync(UserClaimModel input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var user = await identityUserRepository.GetAsync(input.UserId);
|
|
|
|
|
|
|
|
|
|
|
|
user.AddClaim(guidGenerator, new Claim(input.ClaimType, input.ClaimValue));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task DeleteClaimUser(Guid id, Guid userId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var user = await identityUserRepository.GetAsync(userId);
|
|
|
|
|
|
var claim = user.Claims.FirstOrDefault(a => a.Id == id);
|
|
|
|
|
|
|
|
|
|
|
|
user.Claims.Remove(claim);
|
|
|
|
|
|
}
|
2026-04-28 12:43:19 +00:00
|
|
|
|
|
|
|
|
|
|
public async Task KickUserAsync(Guid userId)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (CurrentTenant.Change(CurrentTenant.Id))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 1. AbpSessions temizle
|
|
|
|
|
|
var sessions = await identitySessionRepository.GetListAsync(userId: userId);
|
|
|
|
|
|
foreach (var session in sessions)
|
|
|
|
|
|
await identitySessionRepository.DeleteAsync(session);
|
|
|
|
|
|
|
|
|
|
|
|
// 2. OpenIddict tokenlarını revoke et
|
|
|
|
|
|
await foreach (var token in openIddictTokenManager.FindBySubjectAsync(userId.ToString()))
|
|
|
|
|
|
await openIddictTokenManager.TryRevokeAsync(token);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-24 20:44:16 +00:00
|
|
|
|
}
|