using System; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Sozsoft.Platform.Entities; using Sozsoft.Platform.Identity; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; using Volo.Abp.Users; namespace Sozsoft.Platform.Extensions; public class PlatformApplicationConfigurationContributor : IApplicationConfigurationContributor, ITransientDependency { public async Task ContributeAsync(ApplicationConfigurationContributorContext context) { var hostEnvironment = context.ServiceProvider.GetRequiredService(); context.ApplicationConfiguration.SetProperty("environment", hostEnvironment.EnvironmentName); var configuration = context.ServiceProvider.GetRequiredService(); context.ApplicationConfiguration.SetProperty("apiVersion", configuration.GetValue("App:Version")); // Uygulamanın çalışan sürümü: istemcinin tek sürüm kaynağı (ayrı bir // version.json isteği yoktur). Yalnızca EN SON sürüm taşınır; tam liste // ChangeLog ekranının kendi endpoint'inden (/api/app/change-log) gelir, // aksi halde her config isteğinde bütün changelog gönderilirdi. var changeLogRepository = context.ServiceProvider.GetRequiredService>(); var changeLogs = await changeLogRepository.GetListAsync(x => x.IsPublished); var latest = changeLogs .OrderByDescending(note => note.ReleaseDate) .ThenByDescending(note => note.Version) .FirstOrDefault(); context.ApplicationConfiguration.SetProperty("changeLogs", new { uiVersion = latest?.Version, tags = latest?.GetChangeLog() ?? [] }); // GetListAsync boş liste döner, null dönmez — bu yüzden null kontrolü yok. // Veritabanı erişilemezse çağrı exception atar; bu durum istek boru hattında, // buraya gelinmeden 503 ile karşılanır (bkz. PlatformHttpApiHostModule). var routeRepository = context.ServiceProvider.GetRequiredService>(); context.ApplicationConfiguration.SetProperty("routes", await routeRepository.GetListAsync()); var customComponentRepository = context.ServiceProvider.GetRequiredService>(); context.ApplicationConfiguration.SetProperty( "customComponents", await customComponentRepository.GetListAsync()); // Public site menusu: ziyaretci menu ucunu cagiramaz ([Authorize]), bu yuzden // rotalar ve custom component'ler gibi anonim erisilen konfigurasyonla tasinir. var menuRepository = context.ServiceProvider.GetRequiredService>(); var publicMenus = await menuRepository.GetListAsync( menu => menu.ModuleId == PlatformConsts.PublicSite.ModuleId && !menu.IsDisabled); context.ApplicationConfiguration.SetProperty("publicMenus", publicMenus .OrderBy(menu => menu.Order) .Select(menu => new { code = menu.Code, displayName = menu.DisplayName, url = menu.Url, icon = menu.Icon, order = menu.Order, parentCode = menu.ParentCode, cssClass = menu.CssClass, target = menu.Target, requiredPermissionName = menu.RequiredPermissionName }) .ToList()); var currentUser = context.ServiceProvider.GetRequiredService(); if (currentUser.Id.HasValue) { var sessionRepository = context.ServiceProvider.GetRequiredService(); var sessions = await sessionRepository.GetListAsync(userId: currentUser.Id.Value); var claimSessionId = currentUser.FindClaim(PlatformClaimTypes.SessionId.Key)?.Value; var sessionId = sessions.Exists(session => session.SessionId == claimSessionId) ? claimSessionId : sessions.OrderByDescending(session => session.SignedIn).FirstOrDefault()?.SessionId; context.ApplicationConfiguration.CurrentUser.SessionId = sessionId; context.ApplicationConfiguration.SetProperty("currentUserSessionId", sessionId); } } }