Skip to content

Commit

Permalink
update global settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nhathoang989 committed Oct 1, 2023
1 parent 780fa10 commit 9a225ad
Show file tree
Hide file tree
Showing 27 changed files with 155 additions and 114 deletions.
7 changes: 5 additions & 2 deletions src/applications/Mixcore/Controllers/InitController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Mix.Shared.Models.Configurations;
using Mix.Shared.Services;
using Mixcore.Domain.Constants;

Expand All @@ -7,6 +8,7 @@ namespace Mixcore.Controllers
public class InitController : MixControllerBase
{
private readonly MixEndpointService _mixEndpointService;
private readonly GlobalSettingsModel _globalConfig;
public InitController(
IHttpContextAccessor httpContextAccessor,
IMixCmsService mixCmsService,
Expand All @@ -17,21 +19,22 @@ public InitController(
: base(httpContextAccessor, mixCmsService, ipSecurityConfigService, tenantService, configuration)
{
_mixEndpointService = mixEndpointService;
_globalConfig = configuration.GetSection(MixAppSettingsSection.GlobalSettings).Get<GlobalSettingsModel>()!;
}

[HttpGet]
[Route("init")]
[Route("init/{page}")]
public IActionResult Index(string page)
{
if (!GlobalConfigService.Instance.AppSettings.IsInit)
if (!_globalConfig.IsInit)
{
return Redirect("/");
}
else
{
page ??= "";
var initStatus = GlobalConfigService.Instance.AppSettings.InitStatus;
var initStatus = _globalConfig.InitStatus;

switch (initStatus)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
"ValidateIssuerSigningKey": true,
"TokenType": "Bearer",
"Audience": "mix-core",
"SecretKey": "7fdc91305d594f29bb9d2860163f4d27",
"ClientId": "00000000-0000-0000-0000-000000000000",
"SecretKey": "61cf4651c35a4dfab0bb2cea9181db53",
"Issuer": "mix-core",
"Issuers": "mix-core",
"Audiences": "mix-core",
"RequireUniqueEmail": false,
"RequireConfirmedEmail": false,
"ConfirmedEmailUrl": null,
"ConfirmedEmailUrlSuccess": null,
"ConfirmedEmailUrlFail": null,
"TokenLifespan": 3,
"Facebook": {
"AppId": "",
"AppSecret": ""
Expand All @@ -20,13 +27,19 @@
"AppId": "",
"AppSecret": ""
},
"Twitter": {
"Microsoft": {
"AppId": "",
"AppSecret": ""
},
"Microsoft": {
"Twitter": {
"AppId": "",
"AppSecret": ""
},
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"ClientId": null,
"TenantId": null,
"Scopes": null
}
}
}
30 changes: 15 additions & 15 deletions src/applications/Mixcore/mixcontent/shared/appconfigs/endpoint.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"Account": "", // https://localhost:5002
"Common": "", // https://localhost:5004
"Portal": "", // https://localhost:5006
"Theme": "", // https://localhost:5008
"Mixcore": "", //
"Messenger": "", // https://localhost:5012
"Scheduler": "", // https://localhost:5014
"Grpc": "", // https://localhost:5016
"Storage": "", // https://localhost:5018
"Store": "https://store.mixcore.org",
"UniversalPortal": "https://universal.mixcore.net",
"UniversalPortalDev": "https://mix-portal-angular.vercel.app",
"LocalPortalDev": "http://localhost:4200"
}
{
"Account": null,
"Common": null,
"Portal": null,
"Theme": null,
"Mixcore": null,
"Messenger": null,
"Scheduler": null,
"Grpc": null,
"Storage": "",
"Store": "https://store.mixcore.org",
"UniversalPortal": "https://universal.mixcore.net",
"UniversalPortalDev": "https://mix-portal-angular.vercel.app",
"LocalPortalDev": "http://localhost:4200"
}
33 changes: 18 additions & 15 deletions src/applications/Mixcore/mixcontent/shared/appconfigs/global.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"IsInit": true,
"IsLogStream": false,
"IsEncryptApi": false,
"EnableOcelot": false,
"PortalThemeSettings": null,
"IsMaintenance": false,
"IsHttps": false,
"MaxPageSize": 100,
"ResponseCache": 5,
"InitStatus": "Blank",
"DefaultCulture": "en-us",
"Domain": "",
"ApiEncryptKey": "NElUempOSmx4QVlXRFRmSys5Z0lpZz09LERBSENTUUlZWEVNYVRJRlErc256bE9Ibmo1Z0wwcm5PRm9iMDlXSEJSM0U9",
"LastUpdateConfiguration": null
}
"GlobalSettings": {
"IsInit": true,
"IsLogStream": false,
"IsUpdateSystemDatabases": true,
"IsEncryptApi": false,
"EnableOcelot": false,
"PortalThemeSettings": null,
"IsMaintenance": false,
"IsHttps": false,
"MaxPageSize": 100,
"ResponseCache": 5,
"InitStatus": "Blank",
"DefaultCulture": "en-us",
"Domain": "",
"ApiEncryptKey": "NElUempOSmx4QVlXRFRmSys5Z0lpZz09LERBSENTUUlZWEVNYVRJRlErc256bE9Ibmo1Z0wwcm5PRm9iMDlXSEJSM0U9",
"LastUpdateConfiguration": null
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Payments":{

"Payments": {
"IsActive": false
}
}
2 changes: 1 addition & 1 deletion src/modules/mix.common/Controllers/SharedApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public ActionResult GetGlobalSettings()

[HttpPost]
[Route("global-settings")]
public ActionResult GetSettings([FromBody] GlobalConfigurations settings)
public ActionResult GetSettings([FromBody] GlobalSettingsModel settings)
{
GlobalConfigService.Instance.AppSettings = settings;
GlobalConfigService.Instance.SaveSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SharedTenantApiController(

[HttpGet]
[Route("get-global-settings")]
public ActionResult<GlobalSettings> GetSharedSettings()
public ActionResult<Models.GlobalSettings> GetSharedSettings()
{
var settings = CommonHelper.GetAppSettings(_authConfigurations, CurrentTenant);
return Ok(settings);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mix.common/Domain/Helpers/CommonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Mix.Common.Domain.Helpers
{
public class CommonHelper
{
internal static GlobalSettings GetAppSettings(MixAuthenticationConfigurations authConfigurations, MixTenantSystemModel currentTenant)
internal static Common.Models.GlobalSettings GetAppSettings(MixAuthenticationConfigurations authConfigurations, MixTenantSystemModel currentTenant)
{
//var cultures = _cultureService.Cultures;
//var culture = _cultureService.LoadCulture(lang);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/core/mix-heart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class MixDbEventService
private DatabaseService _databaseService;
private MixPermissionService _mixPermissionService;
public List<MixDbEventSubscriberViewModel> Subscribers;
private readonly GlobalConfigurations _globalConfig;
private readonly GlobalSettingsModel _globalConfig;
private readonly HttpService _httpService;
public MixDbEventService(DatabaseService databaseService, HttpService httpService,
IPortalHubClientService portalHub,
Expand All @@ -48,7 +48,7 @@ public MixDbEventService(DatabaseService databaseService, HttpService httpServic
IConfiguration configuration)
{
_databaseService = databaseService;
_globalConfig = configuration.Get<GlobalConfigurations>()!;
_globalConfig = configuration.GetSection(MixAppSettingsSection.GlobalSettings).Get<GlobalSettingsModel>()!;
LoadEvents();
_httpService = httpService;
PortalHub = portalHub;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mix.library/Base/MixControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class MixControllerBase : Controller
protected bool IsValid = true;
protected string RedirectUrl;
protected readonly IPSecurityConfigService IpSecurityConfigService;
protected readonly GlobalConfigurations GlobalConfig;
protected readonly GlobalSettingsModel GlobalConfig;
protected readonly IMixCmsService MixCmsService;
protected IMixTenantService TenantService;
protected MixTenantSystemModel CurrentTenant => Session.Get<MixTenantSystemModel>(MixRequestQueryKeywords.Tenant);
Expand Down Expand Up @@ -52,7 +52,7 @@ protected MixControllerBase(
ViewData[MixRequestQueryKeywords.Tenant] = CurrentTenant;
MixCmsService = mixCmsService;
TenantService = tenantService;
GlobalConfig = Configuration.Get<GlobalConfigurations>();
GlobalConfig = configuration.GetSection(MixAppSettingsSection.GlobalSettings).Get<GlobalSettingsModel>()!;
}

private void LoadCulture()
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mix.library/Middlewares/AuditlogMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class AuditlogMiddleware
private IAuditLogService _auditlogService;
private AuditLogDataModel _auditlogData;
private IConfiguration _configuration;
private GlobalConfigurations _globalConfig;
private GlobalSettingsModel _globalConfig;
private bool _isLog { get; set; }
public AuditlogMiddleware(RequestDelegate next, IConfiguration configuration, IAuditLogService auditlogService)
{
_configuration = configuration;
_globalConfig = _configuration.Get<GlobalConfigurations>();
_globalConfig = _configuration.Get<GlobalSettingsModel>();
_next = next;
_auditlogData = new();
_auditlogService = auditlogService;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mix.library/Middlewares/UnitOfWorkMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class UnitOfWorkMiddleware
{
private readonly RequestDelegate _next;
private static readonly List<Type> UowInfos = new();
private GlobalConfigurations _globalConfig;
private GlobalSettingsModel _globalConfig;
public UnitOfWorkMiddleware(RequestDelegate next, IConfiguration configuration)
{
_next = next;
_globalConfig = configuration.Get<GlobalConfigurations>();
_globalConfig = configuration.Get<GlobalSettingsModel>();
}

public static void AddUnitOfWork<T>() where T : IUnitOfWorkInfo
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mix.library/Services/MixIdentityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class MixIdentityService : IMixIdentityService
protected readonly SignInManager<MixUser> SignInManager;
protected readonly RoleManager<MixRole> RoleManager;
protected readonly AuthConfigService AuthConfigService;
protected readonly GlobalConfigurations GlobalConfig;
protected readonly GlobalSettingsModel GlobalConfig;
protected readonly FirebaseService FirebaseService;
protected readonly IMixDbDataService MixDbDataService;
protected readonly MixRepoDbRepository RepoDbRepository;
Expand Down Expand Up @@ -95,7 +95,7 @@ public MixIdentityService(
_accContext = accContext;
MixDbUow = mixDbUow;
MixDbDataService = mixDbDataService;
GlobalConfig = Configuration.Get<GlobalConfigurations>();
GlobalConfig = Configuration.Get<GlobalSettingsModel>();
}

public virtual async Task<bool> Any(Guid userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static IServiceCollection AddMixAuthorize<TDbContext>(this IServiceCollec
where TDbContext : DbContext
{
AuthConfigService authConfigService = services.GetService<AuthConfigService>();
var _globalConfig = configuration.Get<GlobalConfigurations>()!;
var _globalConfig = configuration.Get<GlobalSettingsModel>()!;
if (_globalConfig.IsInit)
{
authConfigService.AppSettings.SecretKey = Guid.NewGuid().ToString("N");
Expand Down
3 changes: 2 additions & 1 deletion src/platform/mix.library/Startup/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using Mix.Database.Services;
using Mix.RepoDb.Interfaces;
using Mix.RepoDb.Services;
using Mix.Shared.Models.Configurations;

namespace Microsoft.Extensions.DependencyInjection
{
public static partial class ServiceCollectionExtensions
{

private static void ApplyMigrations(this IServiceCollection services, Mix.Shared.Models.Configurations.GlobalConfigurations options)
private static void ApplyMigrations(this IServiceCollection services, GlobalSettingsModel options)
{
if (!options.IsInit)
{
Expand Down
17 changes: 11 additions & 6 deletions src/platform/mix.library/Startup/_ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Mix.Mixdb.Event.Services;
using Mix.Service.Interfaces;
using Mix.Shared;
using Mix.Shared.Interfaces;
using Mix.Shared.Models.Configurations;
using Mix.SignalR.Interfaces;
using System.Reflection;
Expand All @@ -29,7 +30,12 @@ public static List<Assembly> MixAssemblies

public static IServiceCollection AddMixServices(this IServiceCollection services, Assembly executingAssembly, IConfiguration configuration)
{
var globalConfig = configuration.Get<GlobalConfigurations>();
var globalConfig = configuration.GetSection(MixAppSettingsSection.GlobalSettings)
.Get<GlobalSettingsModel>();
services.AddOptions<GlobalSettingsModel>()
.Bind(configuration.GetSection(MixAppSettingsSection.GlobalSettings))
.ValidateDataAnnotations();

services.AddMvc().AddSessionStateTempDataProvider();
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSession(options =>
Expand Down Expand Up @@ -74,7 +80,7 @@ public static IServiceCollection AddMixServices(this IServiceCollection services
services.TryAddSingleton<IPortalHubClientService, PortalHubClientService>();
services.TryAddSingleton<IMixDbCommandHubClientService, MixDbCommandHubClientService>();
services.TryAddSingleton<MixDbEventService>();
services.AddMixRepoDb();
services.AddMixRepoDb(globalConfig);

UnitOfWorkMiddleware.AddUnitOfWork<UnitOfWorkInfo<MixCacheDbContext>>();
return services;
Expand All @@ -84,8 +90,7 @@ public static IServiceCollection AddMixServices(this IServiceCollection services
public static IServiceCollection AddMixTestServices(this IServiceCollection services, Assembly executingAssembly, IConfiguration configuration)
{
// Clone Settings from shared folder
var options = new GlobalConfigurations();
configuration.GetSection("GlobalConfigurations").Bind(options);
var globalConfig = configuration.GetSection(MixAppSettingsSection.GlobalSettings).Get<GlobalSettingsModel>()!;

services.AddMvc().AddSessionStateTempDataProvider();
services.AddSession();
Expand All @@ -97,7 +102,7 @@ public static IServiceCollection AddMixTestServices(this IServiceCollection serv
services.AddHttpClient();
services.AddLogging();

services.ApplyMigrations(options);
services.ApplyMigrations(globalConfig);

services.AddQueues(executingAssembly, configuration);

Expand All @@ -119,7 +124,7 @@ public static IServiceCollection AddMixTestServices(this IServiceCollection serv

services.TryAddSingleton<IMixMemoryCacheService, MixMemoryCacheService>();
services.TryAddSingleton<IPortalHubClientService, PortalHubClientService>();
services.AddMixRepoDb();
services.AddMixRepoDb(globalConfig);

UnitOfWorkMiddleware.AddUnitOfWork<UnitOfWorkInfo<MixCacheDbContext>>();
return services;
Expand Down
3 changes: 2 additions & 1 deletion src/platform/mix.log/ServiceCollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Mix.Constant.Constants;
using Mix.Database.Entities.AuditLog;
using Mix.Database.Entities.Queue;
using Mix.Log.Lib.Interfaces;
Expand All @@ -27,7 +28,7 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddMixLog(this IServiceCollection services, IConfiguration configuration)
{
var globalConfigs = configuration.Get<GlobalConfigurations>();
var globalConfigs = configuration.GetSection(MixAppSettingsSection.GlobalSettings).Get<GlobalSettingsModel>()!;

services.AddDbContext<AuditLogDbContext>();
services.AddDbContext<MixQueueDbContext>();
Expand Down
5 changes: 3 additions & 2 deletions src/platform/mix.repodb/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Mix.RepoDb.Repositories;
using Mix.RepoDb.Services;
using Mix.RepoDb.Subscribers;
using Mix.Shared.Models.Configurations;
using Mix.Shared.Services;
using RepoDb;
using RepoDb.Interfaces;
Expand All @@ -12,7 +13,7 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddMixRepoDb(this IServiceCollection services)
public static IServiceCollection AddMixRepoDb(this IServiceCollection services, GlobalSettingsModel globalConfig)
{
services.TryAddScoped<ICache, MemoryCache>();
services.TryAddScoped<IMixDbDataService, MixDbDataService>();
Expand All @@ -21,7 +22,7 @@ public static IServiceCollection AddMixRepoDb(this IServiceCollection services)
services.AddHostedService<MixRepoDbPublisher>();
services.AddHostedService<MixRepoDbSubscriber>();

if (!GlobalConfigService.Instance.AppSettings.IsInit)
if (!globalConfig.IsInit && globalConfig.IsUpdateSystemDatabases)
{
var mixDbService = services.GetService<IMixDbService>();
mixDbService.MigrateSystemDatabases().GetAwaiter().GetResult();
Expand Down
Loading

0 comments on commit 9a225ad

Please sign in to comment.