diff --git a/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs index 82186385..70188b2d 100644 --- a/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Client/Extensions/OqtaneServiceCollectionExtensions.cs @@ -57,6 +57,8 @@ namespace Microsoft.Extensions.DependencyInjection services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); // providers diff --git a/Oqtane.Client/Modules/Admin/Register/Index.razor b/Oqtane.Client/Modules/Admin/Register/Index.razor index 2f7c47e7..4f99e453 100644 --- a/Oqtane.Client/Modules/Admin/Register/Index.razor +++ b/Oqtane.Client/Modules/Admin/Register/Index.razor @@ -3,10 +3,11 @@ @inherits ModuleBase @inject NavigationManager NavigationManager @inject IUserService UserService -@inject IStringLocalizer Localizer -@inject IStringLocalizer SharedLocalizer @inject ISettingService SettingService @inject ITimeZoneService TimeZoneService +@inject ILanguageService LanguageService +@inject IStringLocalizer Localizer +@inject IStringLocalizer SharedLocalizer @if (_initialized) { @@ -71,6 +72,18 @@ +
+ +
+ +
+

@@ -95,6 +108,8 @@ @code { private bool _initialized = false; private List _timezones; + private IEnumerable _languages; + private string _passwordrequirements; private string _username = string.Empty; private ElementReference form; @@ -106,6 +121,7 @@ private string _email = string.Empty; private string _displayname = string.Empty; private string _timezoneid = string.Empty; + private string _culturecode = string.Empty; private bool _userCreated = false; private bool _allowsitelogin = true; @@ -113,10 +129,13 @@ protected override async Task OnInitializedAsync() { + _timezones = TimeZoneService.GetTimeZones(); + _languages = await LanguageService.GetLanguagesAsync(PageState.Site.SiteId); + _passwordrequirements = await UserService.GetPasswordRequirementsAsync(PageState.Site.SiteId); _allowsitelogin = bool.Parse(SettingService.GetSetting(PageState.Site.Settings, "LoginOptions:AllowSiteLogin", "true")); - _timezones = TimeZoneService.GetTimeZones(); _timezoneid = PageState.Site.TimeZoneId; + _culturecode = PageState.Site.CultureCode; _initialized = true; } @@ -147,6 +166,7 @@ Email = _email, DisplayName = (_displayname == string.Empty ? _username : _displayname), TimeZoneId = _timezoneid, + CultureCode = _culturecode, PhotoFileId = null }; user = await UserService.AddUserAsync(user); diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index d49d90ed..852062cd 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -11,12 +11,15 @@ @inject IThemeService ThemeService @inject ISettingService SettingService @inject ITimeZoneService TimeZoneService +@inject ILocalizationService LocalizationService @inject IServiceProvider ServiceProvider @inject IStringLocalizer Localizer @inject INotificationService NotificationService @inject IJobService JobService @inject IStringLocalizer SharedLocalizer @inject IOutputCacheService CacheService +@inject ISiteGroupDefinitionService SiteGroupDefinitionService +@inject ISiteGroupService SiteGroupService @if (_initialized) { @@ -29,22 +32,7 @@
- -
- -
-
-
- +
+
+ +
+ +
+
@if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) {
@@ -333,57 +333,6 @@ @if (_aliases != null && UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) { -
-
-
- -
- - -
-   -   - @Localizer["AliasName"] - @Localizer["AliasDefault"] -
- - @if (context.AliasId != _aliasid) - { - - @if (_aliasid == -1) - { - - } - - - @if (_aliasid == -1) - { - - } - - @context.Name - @((context.IsDefault) ? SharedLocalizer["Yes"] : SharedLocalizer["No"]) - } - else - { - - - - - - - - - } - -
-
-
-
-
@@ -438,6 +387,170 @@
+
+
+ @if (!_addAlias) + { +
+ +
+
+ + @if (!_addAlias) + { + + } +
+
+
+ } + @if (_aliasid != -1 || _addAlias) + { +
+ +
+ +
+
+
+ +
+ +
+
+ + } +
+
+
+ @if (_aliasid != -1 || _addAlias) + { + + } + @if (_aliasid != -1 && !_addAlias) + { + + } + @if (_addAlias) + { + + } +
+
+
+
+
+
+ @if (!_addSiteGroupDefinition) + { +
+ +
+
+ + @if (!_addSiteGroupDefinition) + { + + } +
+
+
+ } + @if (_siteGroupDefinitionId != -1 || _addSiteGroupDefinition) + { + @if (!_addSiteGroupDefinition) + { +
+ +
+ +
+
+ } + @if (_member == "Primary") + { +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ } + @if (_member == "Secondary") + { +
+ +
+ +
+
+
+ +
+ +
+
+ } + } +
+
+
+ @if ((_siteGroupDefinitionId != -1 || _addSiteGroupDefinition) && _member != "False") + { + + } + @if ((_siteGroupDefinitionId != -1 && !_addSiteGroupDefinition) && _member != "False") + { + + } + @if (_addSiteGroupDefinition) + { + + } +
+
+
+
@@ -464,6 +577,10 @@
+ @if (_siteGroupDefinitions.Any(item => item.PrimarySiteId == PageState.Site.SiteId && item.Synchronization)) + { + + }

@@ -478,10 +595,11 @@ private List _containers = new List(); private List _pages; private List _timezones; + private IEnumerable _cultures; private string _name = string.Empty; - private string _homepageid = "-"; private string _timezoneid = string.Empty; + private string _culturecode = string.Empty; private string _isdeleted; private string _sitemap = ""; private string _siteguid = ""; @@ -531,6 +649,7 @@ private int _aliasid = -1; private string _aliasname; private string _defaultalias; + private bool _addAlias = false; private string _rendermode = RenderModes.Interactive; private string _enhancednavigation = "True"; @@ -538,6 +657,16 @@ private string _prerender = "True"; private string _hybrid = "False"; + private List _siteGroupDefinitions = new List(); + private int _siteGroupDefinitionId = -1; + private string _groupName = string.Empty; + private string _member = "Primary"; + private string _synchronization = "True"; + private string _synchronize = "True"; + private string _notifyRoleName = RoleNames.Admin; + private string _localization = "False"; + private bool _addSiteGroupDefinition = false; + private string _tenant = string.Empty; private string _database = string.Empty; private string _connectionstring = string.Empty; @@ -564,16 +693,14 @@ if (site != null) { _timezones = TimeZoneService.GetTimeZones(); + _cultures = await LocalizationService.GetCulturesAsync(false); var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); _pages = await PageService.GetPagesAsync(PageState.Site.SiteId); _name = site.Name; _timezoneid = site.TimeZoneId; - if (site.HomePageId != null) - { - _homepageid = site.HomePageId.Value.ToString(); - } + _culturecode = site.CultureCode; _isdeleted = site.IsDeleted.ToString(); _sitemap = PageState.Alias.Protocol + PageState.Alias.Name + "/sitemap.xml"; _siteguid = site.SiteGuid; @@ -652,7 +779,7 @@ } // aliases - await GetAliases(); + await LoadAliases(); // hosting model _rendermode = site.RenderMode; @@ -676,6 +803,12 @@ } } + // site groups + if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + { + await LoadSiteGroups(); + } + // audit _createdby = site.CreatedBy; _createdon = site.CreatedOn; @@ -743,7 +876,7 @@ { site.Name = _name; site.TimeZoneId = _timezoneid; - site.HomePageId = (_homepageid != "-" ? int.Parse(_homepageid) : null); + site.CultureCode = _culturecode; site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted)); // appearance @@ -992,95 +1125,100 @@ } } - private async Task GetAliases() + private async Task LoadAliases() { - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + _aliases = await AliasService.GetAliasesAsync(); + _aliases = _aliases.Where(item => item.SiteId == PageState.Site.SiteId && item.TenantId == PageState.Alias.TenantId).OrderBy(item => item.AliasId).ToList(); + _aliasid = -1; + _addAlias = false; + } + + private async void AliasChanged(ChangeEventArgs e) + { + _aliasid = int.Parse(e.Value.ToString()); + if (_aliasid != -1) { - _aliases = await AliasService.GetAliasesAsync(); - _aliases = _aliases.Where(item => item.SiteId == PageState.Site.SiteId && item.TenantId == PageState.Alias.TenantId).OrderBy(item => item.AliasId).ToList(); + var alias = _aliases.FirstOrDefault(item => item.AliasId == _aliasid); + if (alias != null) + { + _aliasname = alias.Name; + _defaultalias = alias.IsDefault.ToString(); + } } + else + { + _aliasname = ""; + _defaultalias = "False"; + } + StateHasChanged(); } private void AddAlias() { - _aliases.Add(new Alias { AliasId = 0, Name = "", IsDefault = false }); - _aliasid = 0; + _aliasid = -1; _aliasname = ""; _defaultalias = "False"; + _addAlias = true; StateHasChanged(); } - private void EditAlias(Alias alias) + private async Task DeleteAlias() { - _aliasid = alias.AliasId; - _aliasname = alias.Name; - _defaultalias = alias.IsDefault.ToString(); + await AliasService.DeleteAliasAsync(_aliasid); + await LoadAliases(); StateHasChanged(); } - private async Task DeleteAlias(Alias alias) - { - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) - { - await AliasService.DeleteAliasAsync(alias.AliasId); - await GetAliases(); - StateHasChanged(); - } - } - private async Task SaveAlias() { - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + if (!string.IsNullOrEmpty(_aliasname)) { - if (!string.IsNullOrEmpty(_aliasname)) + var aliases = await AliasService.GetAliasesAsync(); + + int protocolIndex = _aliasname.IndexOf("://", StringComparison.OrdinalIgnoreCase); + if (protocolIndex != -1) { - var aliases = await AliasService.GetAliasesAsync(); + _aliasname = _aliasname.Substring(protocolIndex + 3); + } - int protocolIndex = _aliasname.IndexOf("://", StringComparison.OrdinalIgnoreCase); - if (protocolIndex != -1) + var alias = aliases.FirstOrDefault(item => item.Name == _aliasname); + + bool unique = (alias == null || alias.AliasId == _aliasid); + + if (unique) + { + if (_aliasid == 0) { - _aliasname = _aliasname.Substring(protocolIndex + 3); + alias = new Alias { SiteId = PageState.Site.SiteId, TenantId = PageState.Alias.TenantId, Name = _aliasname, IsDefault = bool.Parse(_defaultalias) }; + await AliasService.AddAliasAsync(alias); } - - var alias = aliases.FirstOrDefault(item => item.Name == _aliasname); - - bool unique = (alias == null || alias.AliasId == _aliasid); - - if (unique) + else { - if (_aliasid == 0) + alias = _aliases.SingleOrDefault(item => item.AliasId == _aliasid); + if (alias != null) { - alias = new Alias { SiteId = PageState.Site.SiteId, TenantId = PageState.Alias.TenantId, Name = _aliasname, IsDefault = bool.Parse(_defaultalias) }; - await AliasService.AddAliasAsync(alias); - } - else - { - alias = _aliases.SingleOrDefault(item => item.AliasId == _aliasid); - if (alias != null) - { - alias.Name = _aliasname; - alias.IsDefault = bool.Parse(_defaultalias); - await AliasService.UpdateAliasAsync(alias); - } + alias.Name = _aliasname; + alias.IsDefault = bool.Parse(_defaultalias); + await AliasService.UpdateAliasAsync(alias); } + } - await GetAliases(); - _aliasid = -1; - _aliasname = ""; - StateHasChanged(); - } - else // Duplicate alias - { - AddModuleMessage(Localizer["Message.Aliases.Taken"], MessageType.Warning); - await ScrollToPageTop(); - } + await LoadAliases(); + _aliasid = -1; + _aliasname = ""; + StateHasChanged(); + } + else // Duplicate alias + { + AddModuleMessage(Localizer["Message.Aliases.Taken"], MessageType.Warning); + await ScrollToPageTop(); } } } private async Task CancelAlias() { - await GetAliases(); + await LoadAliases(); _aliasid = -1; _aliasname = ""; StateHasChanged(); @@ -1090,4 +1228,181 @@ await CacheService.EvictByTag(Constants.SitemapOutputCacheTag); AddModuleMessage(Localizer["Success.SiteMap.CacheEvicted"], MessageType.Success); } + + private async Task LoadSiteGroups() + { + _siteGroupDefinitions = await SiteGroupDefinitionService.GetSiteGroupDefinitionsAsync(); + _siteGroupDefinitionId = -1; + _addSiteGroupDefinition = false; + StateHasChanged(); + } + + private async void SiteGroupChanged(ChangeEventArgs e) + { + _siteGroupDefinitionId = int.Parse(e.Value.ToString()); + if (_siteGroupDefinitionId != -1) + { + var group = _siteGroupDefinitions.FirstOrDefault(item => item.SiteGroupDefinitionId == _siteGroupDefinitionId); + if (group != null) + { + _groupName = group.Name; + _member = (group.PrimarySiteId == PageState.Site.SiteId) ? "Primary" : "Secondary"; + _synchronization = group.Synchronization.ToString(); + _localization = group.Localization.ToString(); + } + + var siteGroup = await SiteGroupService.GetSiteGroupAsync(PageState.Site.SiteId, _siteGroupDefinitionId); + if (siteGroup != null) + { + _synchronize = siteGroup.Synchronize.ToString(); + _notifyRoleName = siteGroup.NotifyRoleName; + } + else + { + _member = "False"; + _synchronize = "True"; + _notifyRoleName = RoleNames.Admin; + } + } + StateHasChanged(); + } + + private async void MemberChanged(ChangeEventArgs e) + { + _member = e.Value.ToString(); + StateHasChanged(); + } + + private async Task AddSiteGroup() + { + _groupName = ""; + _member = "Primary"; + _addSiteGroupDefinition = true; + } + + private async Task SaveSiteGroup() + { + SiteGroupDefinition siteGroupDefinition = null; + + if (_siteGroupDefinitionId == -1) + { + if (!string.IsNullOrEmpty(_groupName)) + { + siteGroupDefinition = new Models.SiteGroupDefinition + { + Name = _groupName, + PrimarySiteId = PageState.Site.SiteId, + Synchronization = bool.Parse(_synchronization), + Localization = bool.Parse(_localization), + Synchronize = false + }; + siteGroupDefinition = await SiteGroupDefinitionService.AddSiteGroupDefinitionAsync(siteGroupDefinition); + } + } + else + { + siteGroupDefinition = _siteGroupDefinitions.FirstOrDefault(item => item.SiteGroupDefinitionId == _siteGroupDefinitionId); + if (siteGroupDefinition != null && !string.IsNullOrEmpty(_groupName)) + { + if (_member == "False") + { + var siteGroup = await SiteGroupService.GetSiteGroupAsync(PageState.Site.SiteId, siteGroupDefinition.SiteGroupDefinitionId); + if (siteGroup != null) + { + await SiteGroupService.DeleteSiteGroupAsync(siteGroup.SiteGroupId); + } + siteGroupDefinition = null; + } + else + { + siteGroupDefinition.Name = _groupName; + siteGroupDefinition.PrimarySiteId = (_member == "Primary") ? PageState.Site.SiteId : siteGroupDefinition.PrimarySiteId; + siteGroupDefinition.Synchronization = bool.Parse(_synchronization); + siteGroupDefinition.Localization = bool.Parse(_localization); + siteGroupDefinition = await SiteGroupDefinitionService.UpdateSiteGroupDefinitionAsync(siteGroupDefinition); + } + } + else + { + siteGroupDefinition = null; + } + } + + if (siteGroupDefinition != null) + { + var siteGroup = await SiteGroupService.GetSiteGroupAsync(PageState.Site.SiteId, siteGroupDefinition.SiteGroupDefinitionId); + if (siteGroup == null) + { + siteGroup = new SiteGroup + { + SiteGroupDefinitionId = siteGroupDefinition.SiteGroupDefinitionId, + SiteId = PageState.Site.SiteId, + Synchronize = bool.Parse(_synchronize), + NotifyRoleName= _notifyRoleName + }; + await SiteGroupService.AddSiteGroupAsync(siteGroup); + } + else + { + siteGroup.Synchronize = bool.Parse(_synchronize); + siteGroup.NotifyRoleName = _notifyRoleName; + await SiteGroupService.UpdateSiteGroupAsync(siteGroup); + } + + await LoadSiteGroups(); + } + else + { + AddModuleMessage(Localizer["Message.Required.GroupName"], MessageType.Warning); + await ScrollToPageTop(); + } + } + + private async Task CancelSiteGroup() + { + _groupName = ""; + await LoadSiteGroups(); + } + + private async Task DeleteSiteGroup() + { + if (_siteGroupDefinitionId != -1) + { + var siteGroup = await SiteGroupService.GetSiteGroupAsync(PageState.Site.SiteId, _siteGroupDefinitionId); + if (siteGroup != null) + { + await SiteGroupService.DeleteSiteGroupAsync(siteGroup.SiteGroupDefinitionId); + } + + var siteGroups = await SiteGroupService.GetSiteGroupsAsync(-1, _siteGroupDefinitionId); + if (!siteGroups.Any()) + { + await SiteGroupDefinitionService.DeleteSiteGroupDefinitionAsync(_siteGroupDefinitionId); + } + + await LoadSiteGroups(); + } + } + + private async Task SynchronizeSite() + { + // enable synchronization job if it is not enabled already + var jobs = await JobService.GetJobsAsync(); + var job = jobs.FirstOrDefault(item => item.JobType == "Oqtane.Infrastructure.SynchronizationJob, Oqtane.Server"); + if (job != null && !job.IsEnabled) + { + job.IsEnabled = true; + await JobService.UpdateJobAsync(job); + } + + // mark secondary sites for synchronization + foreach (var group in _siteGroupDefinitions.Where(item => item.PrimarySiteId == PageState.Site.SiteId && item.Synchronization)) + { + group.Synchronize = true; + await SiteGroupDefinitionService.UpdateSiteGroupDefinitionAsync(group); + } + + AddModuleMessage(Localizer["Message.Site.Synchronize"], MessageType.Success); + await ScrollToPageTop(); + } } diff --git a/Oqtane.Client/Modules/Admin/Sites/Add.razor b/Oqtane.Client/Modules/Admin/Sites/Add.razor index 383a839e..e97aadfc 100644 --- a/Oqtane.Client/Modules/Admin/Sites/Add.razor +++ b/Oqtane.Client/Modules/Admin/Sites/Add.razor @@ -6,7 +6,6 @@ @inject ITenantService TenantService @inject IAliasService AliasService @inject ISiteService SiteService -@inject IThemeService ThemeService @inject ISiteTemplateService SiteTemplateService @inject IUserService UserService @inject IInstallationService InstallationService @@ -29,33 +28,9 @@ else
- +
- -
-
-
- -
- -
-
-
- -
- +
@@ -70,26 +45,6 @@ else
-
- -
- -
-
-
- -
- -
-
@@ -186,9 +141,6 @@ else private bool _showConnectionString = false; private string _connectionString = string.Empty; - private List _themeList; - private List _themes = new List(); - private List _containers = new List(); private List _siteTemplates; private List _tenants; private string _tenantid = "-"; @@ -200,11 +152,7 @@ else private string _name = string.Empty; private string _urls = string.Empty; - private string _themetype = "-"; - private string _containertype = "-"; private string _sitetemplatetype = "-"; - private string _rendermode = RenderModes.Static; - private string _runtime = Runtimes.Server; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host; @@ -215,19 +163,11 @@ else { _tenantid = _tenants.First(item => item.Name == TenantNames.Master).TenantId.ToString(); } - _urls = PageState.Alias.Name; - _themeList = await ThemeService.GetThemesAsync(PageState.Site.SiteId); - _themes = ThemeService.GetThemeControls(_themeList); - if (_themes.Any(item => item.TypeName == Constants.DefaultTheme)) - { - _themetype = Constants.DefaultTheme; - _containers = ThemeService.GetContainerControls(_themeList, _themetype); - _containertype = _containers.First().TypeName; - } + _urls = PageState.Alias.Name + "/sitename"; _siteTemplates = await SiteTemplateService.GetSiteTemplatesAsync(); - if (_siteTemplates.Any(item => item.TypeName == Constants.DefaultSiteTemplate)) + if (_siteTemplates.Any(item => item.TypeName == Constants.EmptySiteTemplate)) { - _sitetemplatetype = Constants.DefaultSiteTemplate; + _sitetemplatetype = Constants.EmptySiteTemplate; } _databases = await DatabaseService.GetDatabasesAsync(); @@ -281,37 +221,13 @@ else StateHasChanged(); } - private async void ThemeChanged(ChangeEventArgs e) - { - try - { - _themetype = (string)e.Value; - if (_themetype != "-") - { - _containers = ThemeService.GetContainerControls(_themeList, _themetype); - _containertype = _containers.First().TypeName; - } - else - { - _containers = new List(); - _containertype = "-"; - } - StateHasChanged(); - } - catch (Exception ex) - { - await logger.LogError(ex, "Error Loading Containers For Theme {ThemeType} {Error}", _themetype, ex.Message); - AddModuleMessage(Localizer["Error.Theme.LoadContainers"], MessageType.Error); - } - } - private async Task SaveSite() { validated = true; var interop = new Interop(JSRuntime); if (await interop.FormValid(form)) { - if (_tenantid != "-" && _name != string.Empty && _urls != string.Empty && _themetype != "-" && _containertype != "-" && _sitetemplatetype != "-") + if (_tenantid != "-" && _name != string.Empty && _urls != string.Empty && _sitetemplatetype != "-") { _urls = Regex.Replace(_urls, @"\r\n?|\n", ","); var duplicates = new List(); @@ -399,12 +315,12 @@ else { config.SiteName = _name; config.Aliases = _urls; - config.DefaultTheme = _themetype; - config.DefaultContainer = _containertype; + config.DefaultTheme = Constants.DefaultTheme; + config.DefaultContainer = Constants.DefaultContainer; config.DefaultAdminContainer = ""; config.SiteTemplate = _sitetemplatetype; - config.RenderMode = _rendermode; - config.Runtime = _runtime; + config.RenderMode = RenderModes.Static; + config.Runtime = Runtimes.Server; config.Register = false; ShowProgressIndicator(); diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor index 705de755..cf8bac43 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor @@ -10,6 +10,7 @@ @inject IFileService FileService @inject IFolderService FolderService @inject ITimeZoneService TimeZoneService +@inject ILanguageService LanguageService @inject IJSRuntime jsRuntime @inject IServiceProvider ServiceProvider @inject IStringLocalizer Localizer @@ -58,6 +59,18 @@
+
+ +
+ +
+
@@ -448,6 +461,9 @@ @code { public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View; + private List _timezones; + private IEnumerable _languages; + private bool _initialized = false; private bool _allowtwofactor = false; private bool _allowpasskeys = false; @@ -458,8 +474,8 @@ private string _displayname = string.Empty; private FileManager _filemanager; private int _folderid = -1; - private List _timezones; private string _timezoneid = string.Empty; + private string _culturecode = string.Empty; private int _photofileid = -1; private File _photo = null; private string _imagefiles = string.Empty; @@ -493,12 +509,15 @@ if (PageState.User != null) { + _timezones = TimeZoneService.GetTimeZones(); + _languages = await LanguageService.GetLanguagesAsync(PageState.Site.SiteId); + // identity section _username = PageState.User.Username; _email = PageState.User.Email; _displayname = PageState.User.DisplayName; - _timezones = TimeZoneService.GetTimeZones(); _timezoneid = PageState.User.TimeZoneId; + _culturecode = PageState.User.CultureCode; var folder = await FolderService.GetFolderAsync(ModuleState.SiteId, PageState.User.FolderPath); if (folder != null) { @@ -572,6 +591,7 @@ user.Email = _email; user.DisplayName = (_displayname == string.Empty ? _username : _displayname); user.TimeZoneId = _timezoneid; + user.CultureCode = _culturecode; user.PhotoFileId = _filemanager.GetFileId(); if (user.PhotoFileId == -1) { diff --git a/Oqtane.Client/Modules/Admin/Users/Add.razor b/Oqtane.Client/Modules/Admin/Users/Add.razor index 6e19d832..0eea6f43 100644 --- a/Oqtane.Client/Modules/Admin/Users/Add.razor +++ b/Oqtane.Client/Modules/Admin/Users/Add.razor @@ -6,6 +6,7 @@ @inject IProfileService ProfileService @inject ISettingService SettingService @inject ITimeZoneService TimeZoneService +@inject ILanguageService LanguageService @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer @@ -55,6 +56,18 @@
+
+ +
+ +
+
@@ -129,12 +142,15 @@ @code { private List _timezones; + private IEnumerable _languages; + private bool _initialized = false; private string _username = string.Empty; private string _email = string.Empty; private string _confirmed = "True"; private string _displayname = string.Empty; private string _timezoneid = string.Empty; + private string _culturecode = string.Empty; private string _notify = "True"; private List _profiles; private Dictionary _settings; @@ -147,6 +163,11 @@ try { _timezones = TimeZoneService.GetTimeZones(); + _languages = await LanguageService.GetLanguagesAsync(PageState.Site.SiteId); + + _timezoneid = PageState.Site.TimeZoneId; + _culturecode = PageState.Site.CultureCode; + _profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId); foreach (var profile in _profiles) { @@ -157,8 +178,9 @@ profile.Options = string.Join(",", options.OrderBy(item => item.Value).Select(kvp => $"{kvp.Key}:{kvp.Value}")); } } + _settings = new Dictionary(); - _timezoneid = PageState.Site.TimeZoneId; + _initialized = true; } catch (Exception ex) @@ -194,6 +216,7 @@ user.EmailConfirmed = bool.Parse(_confirmed); user.DisplayName = string.IsNullOrWhiteSpace(_displayname) ? _username : _displayname; user.TimeZoneId = _timezoneid; + user.CultureCode = _culturecode; user.PhotoFileId = null; user.SuppressNotification = !bool.Parse(_notify); diff --git a/Oqtane.Client/Modules/Admin/Users/Edit.razor b/Oqtane.Client/Modules/Admin/Users/Edit.razor index db0ea36b..d629c8bb 100644 --- a/Oqtane.Client/Modules/Admin/Users/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Users/Edit.razor @@ -7,6 +7,7 @@ @inject ISettingService SettingService @inject IFileService FileService @inject ITimeZoneService TimeZoneService +@inject ILanguageService LanguageService @inject IServiceProvider ServiceProvider @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer @@ -55,6 +56,18 @@
+
+ +
+ +
+
@if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) {
@@ -224,13 +237,16 @@ private bool _allowpasskeys = false; private bool _allowexternallogin = false; + private List _timezones; + private IEnumerable _languages; + private int _userid; private string _username = string.Empty; private string _email = string.Empty; private string _confirmed = string.Empty; private string _displayname = string.Empty; - private List _timezones; private string _timezoneid = string.Empty; + private string _culturecode = string.Empty; private string _isdeleted; private string _lastlogin; private string _lastipaddress; @@ -270,12 +286,15 @@ var user = await UserService.GetUserAsync(_userid, PageState.Site.SiteId); if (user != null) { + _timezones = TimeZoneService.GetTimeZones(); + _languages = await LanguageService.GetLanguagesAsync(PageState.Site.SiteId); + _username = user.Username; _email = user.Email; _confirmed = user.EmailConfirmed.ToString(); _displayname = user.DisplayName; - _timezones = TimeZoneService.GetTimeZones(); _timezoneid = PageState.User.TimeZoneId; + _culturecode = PageState.User.CultureCode; _isdeleted = user.IsDeleted.ToString(); _lastlogin = string.Format("{0:MMM dd yyyy HH:mm:ss}", UtcToLocal(user.LastLoginOn)); _lastipaddress = user.LastIPAddress; @@ -344,6 +363,7 @@ user.EmailConfirmed = bool.Parse(_confirmed); user.DisplayName = string.IsNullOrWhiteSpace(_displayname) ? _username : _displayname; user.TimeZoneId = _timezoneid; + user.CultureCode = _culturecode; if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) { user.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted)); diff --git a/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs b/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs index f2f0674c..600374cf 100644 --- a/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs +++ b/Oqtane.Client/Modules/HtmlText/Services/HtmlTextService.cs @@ -7,6 +7,20 @@ using Oqtane.Shared; namespace Oqtane.Modules.HtmlText.Services { + [PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")] + public interface IHtmlTextService + { + Task> GetHtmlTextsAsync(int moduleId); + + Task GetHtmlTextAsync(int moduleId); + + Task GetHtmlTextAsync(int htmlTextId, int moduleId); + + Task AddHtmlTextAsync(Models.HtmlText htmltext); + + Task DeleteHtmlTextAsync(int htmlTextId, int moduleId); + } + [PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")] public class HtmlTextService : ServiceBase, IHtmlTextService, IClientService { diff --git a/Oqtane.Client/Modules/HtmlText/Services/IHtmlTextService.cs b/Oqtane.Client/Modules/HtmlText/Services/IHtmlTextService.cs deleted file mode 100644 index 838d5240..00000000 --- a/Oqtane.Client/Modules/HtmlText/Services/IHtmlTextService.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Oqtane.Documentation; - -namespace Oqtane.Modules.HtmlText.Services -{ - [PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")] - public interface IHtmlTextService - { - Task> GetHtmlTextsAsync(int moduleId); - - Task GetHtmlTextAsync(int moduleId); - - Task GetHtmlTextAsync(int htmlTextId, int moduleId); - - Task AddHtmlTextAsync(Models.HtmlText htmltext); - - Task DeleteHtmlTextAsync(int htmlTextId, int moduleId); - } -} diff --git a/Oqtane.Client/Resources/Modules/Admin/Register/Index.resx b/Oqtane.Client/Resources/Modules/Admin/Register/Index.resx index 47e95add..8ebb5968 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Register/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Register/Index.resx @@ -186,4 +186,10 @@ Your time zone + + Language: + + + Your preferred language. Note that you will only be able to choose from languages supported on this site. + \ No newline at end of file diff --git a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx index 3d41770b..380e951a 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx @@ -319,13 +319,13 @@ The default alias for the site. Requests for non-default aliases will be redirected to the default alias. - Default Alias: + Default? Site Urls - - Url + + Url: Default? @@ -495,4 +495,76 @@ Use TLS When Available + + A url for this site. This can include domain names (ie. domain.com), subdomains (ie. sub.domain.com) or virtual folders (ie. domain.com/folder). + + + Group: + + + The site groups in this tenant (database) + + + Member? + + + Indicates if the current site is a member of the selected group + + + Name: + + + Name of the site group + + + Synchronization? + + + Specifies if the group supports content synchronization between the primary site and other sites in the group + + + Localization? + + + Specifies if each site that is part of the group contains content which is localized in a different language + + + Primary + + + Secondary + + + Compare + + + Update + + + Synchronization: + + + Specifies the synchronization approach from the primary site to the current site + + + Notify Role: + + + Optionally specifies a role in the current site whose users should be notified of content changes in the primary site + + + Delete Site Group + + + Are You Sure You Wish To Delete {0}? + + + Group Name Is Required + + + Site Submitted For Synchronization + + + Synchronize + \ No newline at end of file diff --git a/Oqtane.Client/Resources/Modules/Admin/Sites/Add.resx b/Oqtane.Client/Resources/Modules/Admin/Sites/Add.resx index d32522e9..b09916e1 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Sites/Add.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Sites/Add.resx @@ -133,7 +133,7 @@ Select Theme - The urls for the site (comman delimited). This can include domain names (ie. domain.com), subdomains (ie. sub.domain.com) or a virtual folder (ie. domain.com/folder). + The primary url for the site. This can be a domain name (ie. domain.com), subdomain (ie. sub.domain.com) or a virtual folder (ie. domain.com/folder). Select the default container for the site @@ -142,7 +142,7 @@ Database: - Urls: + Url: Default Theme: diff --git a/Oqtane.Client/Resources/Modules/Admin/UserProfile/Index.resx b/Oqtane.Client/Resources/Modules/Admin/UserProfile/Index.resx index b725fd7f..0486bed8 100644 --- a/Oqtane.Client/Resources/Modules/Admin/UserProfile/Index.resx +++ b/Oqtane.Client/Resources/Modules/Admin/UserProfile/Index.resx @@ -288,4 +288,10 @@ Passkey Could Not Be Created + + Language: + + + Your preferred language. Note that you will only be able to choose from languages supported on this site. + \ No newline at end of file diff --git a/Oqtane.Client/Resources/Modules/Admin/Users/Add.resx b/Oqtane.Client/Resources/Modules/Admin/Users/Add.resx index faf88ee8..f3e4bada 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Users/Add.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Users/Add.resx @@ -168,4 +168,10 @@ Indicates if the user's email is verified + + Language: + + + + \ No newline at end of file diff --git a/Oqtane.Client/Resources/Modules/Admin/Users/Edit.resx b/Oqtane.Client/Resources/Modules/Admin/Users/Edit.resx index 807b932d..3e80cf7c 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Users/Edit.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Users/Edit.resx @@ -252,4 +252,10 @@ You Do Not Have Any External Logins For This Site + + Language: + + + The user's preferred language. Note that you will only be able to choose from languages supported on this site. + \ No newline at end of file diff --git a/Oqtane.Client/Services/LocalizationService.cs b/Oqtane.Client/Services/LocalizationService.cs index ee537d60..97948b40 100644 --- a/Oqtane.Client/Services/LocalizationService.cs +++ b/Oqtane.Client/Services/LocalizationService.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Oqtane.Documentation; @@ -26,6 +27,9 @@ namespace Oqtane.Services private string Apiurl => CreateApiUrl("Localization"); - public async Task> GetCulturesAsync(bool installed) => await GetJsonAsync>($"{Apiurl}?installed={installed}"); + public async Task> GetCulturesAsync(bool installed) + { + return await GetJsonAsync>($"{Apiurl}?installed={installed}"); + } } } diff --git a/Oqtane.Client/Services/SiteGroupDefinitionService.cs b/Oqtane.Client/Services/SiteGroupDefinitionService.cs new file mode 100644 index 00000000..4f9728e6 --- /dev/null +++ b/Oqtane.Client/Services/SiteGroupDefinitionService.cs @@ -0,0 +1,83 @@ +using Oqtane.Models; +using System.Threading.Tasks; +using System.Net.Http; +using System.Collections.Generic; +using Oqtane.Documentation; +using Oqtane.Shared; +using System.Linq; + +namespace Oqtane.Services +{ + /// + /// Service to manage s on a + /// + public interface ISiteGroupDefinitionService + { + /// + /// Get all s + /// + /// + Task> GetSiteGroupDefinitionsAsync(); + + /// + /// Get one specific + /// + /// ID-reference of a + /// + Task GetSiteGroupDefinitionAsync(int siteGroupDefinitionId); + + /// + /// Add / save a new to the database. + /// + /// + /// + Task AddSiteGroupDefinitionAsync(SiteGroupDefinition siteGroupDefinition); + + /// + /// Update a in the database. + /// + /// + /// + Task UpdateSiteGroupDefinitionAsync(SiteGroupDefinition siteGroupDefinition); + + /// + /// Delete a in the database. + /// + /// ID-reference of a + /// + Task DeleteSiteGroupDefinitionAsync(int siteGroupDefinitionId); + } + + [PrivateApi("Don't show in the documentation, as everything should use the Interface")] + public class SiteGroupDefinitionService : ServiceBase, ISiteGroupDefinitionService + { + public SiteGroupDefinitionService(HttpClient http, SiteState siteState) : base(http, siteState) { } + + private string Apiurl => CreateApiUrl("SiteGroupDefinition"); + + public async Task> GetSiteGroupDefinitionsAsync() + { + return await GetJsonAsync>($"{Apiurl}", Enumerable.Empty().ToList()); + } + + public async Task GetSiteGroupDefinitionAsync(int siteGroupDefinitionId) + { + return await GetJsonAsync($"{Apiurl}/{siteGroupDefinitionId}"); + } + + public async Task AddSiteGroupDefinitionAsync(SiteGroupDefinition siteGroupDefinition) + { + return await PostJsonAsync(Apiurl, siteGroupDefinition); + } + + public async Task UpdateSiteGroupDefinitionAsync(SiteGroupDefinition siteGroupDefinition) + { + return await PutJsonAsync($"{Apiurl}/{siteGroupDefinition.SiteGroupDefinitionId}", siteGroupDefinition); + } + + public async Task DeleteSiteGroupDefinitionAsync(int siteGroupDefinitionId) + { + await DeleteAsync($"{Apiurl}/{siteGroupDefinitionId}"); + } + } +} diff --git a/Oqtane.Client/Services/SiteGroupService.cs b/Oqtane.Client/Services/SiteGroupService.cs new file mode 100644 index 00000000..8cae99f7 --- /dev/null +++ b/Oqtane.Client/Services/SiteGroupService.cs @@ -0,0 +1,104 @@ +using Oqtane.Models; +using System.Threading.Tasks; +using System.Net.Http; +using System.Collections.Generic; +using Oqtane.Documentation; +using Oqtane.Shared; +using System.Linq; + +namespace Oqtane.Services +{ + /// + /// Service to manage s on a + /// + public interface ISiteGroupService + { + /// + /// Get all s + /// + /// + Task> GetSiteGroupsAsync(int siteId, int siteGroupDefinitionId); + + /// + /// Get one specific + /// + /// ID-reference of a + /// + Task GetSiteGroupAsync(int siteSiteGroupDefinitionId); + + /// + /// Get one specific + /// + /// ID-reference of a + /// ID-reference of a + /// + Task GetSiteGroupAsync(int siteId, int siteGroupDefinitionId); + + /// + /// Add / save a new to the database. + /// + /// + /// + Task AddSiteGroupAsync(SiteGroup siteGroup); + + /// + /// Update a in the database. + /// + /// + /// + Task UpdateSiteGroupAsync(SiteGroup siteGroup); + + /// + /// Delete a in the database. + /// + /// ID-reference of a + /// + Task DeleteSiteGroupAsync(int siteSiteGroupDefinitionId); + } + + [PrivateApi("Don't show in the documentation, as everything should use the Interface")] + public class SiteGroupService : ServiceBase, ISiteGroupService + { + public SiteGroupService(HttpClient http, SiteState siteState) : base(http, siteState) { } + + private string Apiurl => CreateApiUrl("SiteGroup"); + + public async Task> GetSiteGroupsAsync(int siteId, int siteGroupDefinitionId) + { + return await GetJsonAsync>($"{Apiurl}?siteid={siteId}&groupid={siteGroupDefinitionId}", Enumerable.Empty().ToList()); + } + + public async Task GetSiteGroupAsync(int siteSiteGroupDefinitionId) + { + return await GetJsonAsync($"{Apiurl}/{siteSiteGroupDefinitionId}"); + } + + public async Task GetSiteGroupAsync(int siteId, int siteGroupDefinitionId) + { + var siteGroups = await GetSiteGroupsAsync(siteId, siteGroupDefinitionId); + if (siteGroups != null && siteGroups.Count > 0) + { + return siteGroups[0]; + } + else + { + return null; + } + } + + public async Task AddSiteGroupAsync(SiteGroup siteGroup) + { + return await PostJsonAsync(Apiurl, siteGroup); + } + + public async Task UpdateSiteGroupAsync(SiteGroup siteGroup) + { + return await PutJsonAsync($"{Apiurl}/{siteGroup.SiteGroupDefinitionId}", siteGroup); + } + + public async Task DeleteSiteGroupAsync(int siteSiteGroupDefinitionId) + { + await DeleteAsync($"{Apiurl}/{siteSiteGroupDefinitionId}"); + } + } +} diff --git a/Oqtane.Client/Themes/Controls/Theme/ControlPanel.razor b/Oqtane.Client/Themes/Controls/Theme/ControlPanel.razor index 762e457a..78fb7a40 100644 --- a/Oqtane.Client/Themes/Controls/Theme/ControlPanel.razor +++ b/Oqtane.Client/Themes/Controls/Theme/ControlPanel.razor @@ -4,11 +4,6 @@ @inject IPageService PageService @inject ISettingService SettingService -@if (ShowLanguageSwitcher) -{ - -} - @if (ShowEditMode && (_showEditMode || (PageState.Page.IsPersonalizable && PageState.User != null && UserSecurity.IsAuthorized(PageState.User, RoleNames.Registered)))) {
@@ -53,9 +48,11 @@ [Parameter] public string BodyClass { get; set; } = "offcanvas-body overflow-auto"; + // deprecated in 10.1.0 - UI culture is set in user's profile [Parameter] public bool ShowLanguageSwitcher { get; set; } = true; + // deprecated in 10.1.0 - UI culture is set in user's profile [Parameter] public string LanguageDropdownAlignment { get; set; } = string.Empty; // Empty or Left or Right diff --git a/Oqtane.Client/Themes/Controls/Theme/LanguageSelector.razor b/Oqtane.Client/Themes/Controls/Theme/LanguageSelector.razor new file mode 100644 index 00000000..4a8e1277 --- /dev/null +++ b/Oqtane.Client/Themes/Controls/Theme/LanguageSelector.razor @@ -0,0 +1,37 @@ +@using System.Globalization +@using Oqtane.Models +@using System.Linq +@namespace Oqtane.Themes.Controls +@inherits ThemeControlBase +@inject ILocalizationService LocalizationService +@inject NavigationManager NavigationManager + +@if (PageState.Site.Languages.Count() > 1) +{ +
+ + +
+} + +@code{ + private string MenuAlignment = string.Empty; + + [Parameter] + public string DropdownAlignment { get; set; } = string.Empty; // Empty or Left or Right + + [Parameter] + public string ButtonClass { get; set; } = "btn-outline-secondary"; + + protected override async Task OnParametersSetAsync() + { + MenuAlignment = DropdownAlignment.ToLower() == "right" ? "dropdown-menu-end" : string.Empty; + } +} diff --git a/Oqtane.Client/Themes/OqtaneTheme/Themes/Default.razor b/Oqtane.Client/Themes/OqtaneTheme/Themes/Default.razor index f4fe08d6..b54570ed 100644 --- a/Oqtane.Client/Themes/OqtaneTheme/Themes/Default.razor +++ b/Oqtane.Client/Themes/OqtaneTheme/Themes/Default.razor @@ -11,6 +11,7 @@ +
diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor index fb7d4fc3..64e2f59d 100644 --- a/Oqtane.Client/UI/SiteRouter.razor +++ b/Oqtane.Client/UI/SiteRouter.razor @@ -233,15 +233,8 @@ if (page == null && route.PagePath == "") // naked path refers to site home page { - if (site.HomePageId != null) - { - page = site.Pages.FirstOrDefault(item => item.PageId == site.HomePageId); - } - if (page == null) - { - // fallback to use the first page in the collection - page = site.Pages.FirstOrDefault(); - } + // fallback to use the first page in the collection + page = site.Pages.FirstOrDefault(); } if (page == null) { diff --git a/Oqtane.Server/Components/App.razor b/Oqtane.Server/Components/App.razor index fe668866..666dcef1 100644 --- a/Oqtane.Server/Components/App.razor +++ b/Oqtane.Server/Components/App.razor @@ -157,15 +157,8 @@ var page = site.Pages.FirstOrDefault(item => item.Path.Equals(route.PagePath, StringComparison.OrdinalIgnoreCase)); if (page == null && route.PagePath == "") // naked path refers to site home page { - if (site.HomePageId != null) - { - page = site.Pages.FirstOrDefault(item => item.PageId == site.HomePageId); - } - if (page == null) - { - // fallback to use the first page in the collection - page = site.Pages.FirstOrDefault(); - } + // fallback to use the first page in the collection + page = site.Pages.FirstOrDefault(); } if (page == null) { diff --git a/Oqtane.Server/Controllers/LocalizationController.cs b/Oqtane.Server/Controllers/LocalizationController.cs index 5a572ba2..7dd1452d 100644 --- a/Oqtane.Server/Controllers/LocalizationController.cs +++ b/Oqtane.Server/Controllers/LocalizationController.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using Microsoft.AspNetCore.Mvc; +using Oqtane.Extensions; using Oqtane.Infrastructure; using Oqtane.Models; +using Oqtane.Repository; using Oqtane.Shared; namespace Oqtane.Controllers @@ -13,10 +15,16 @@ namespace Oqtane.Controllers public class LocalizationController : Controller { private readonly ILocalizationManager _localizationManager; + private readonly ISiteRepository _siteRepository; + private readonly ISiteGroupRepository _siteGroupRepository; + private readonly IAliasRepository _aliasRepository; - public LocalizationController(ILocalizationManager localizationManager) + public LocalizationController(ILocalizationManager localizationManager, ISiteRepository siteRepository, ISiteGroupRepository siteGroupRepository, IAliasRepository aliasRepository) { _localizationManager = localizationManager; + _siteRepository = siteRepository; + _siteGroupRepository = siteGroupRepository; + _aliasRepository = aliasRepository; } // GET: api/localization @@ -32,13 +40,20 @@ namespace Oqtane.Controllers { culturecodes = _localizationManager.GetSupportedCultures(); } + var cultures = culturecodes.Select(c => new Culture { Name = CultureInfo.GetCultureInfo(c).Name, DisplayName = CultureInfo.GetCultureInfo(c).DisplayName, IsDefault = _localizationManager.GetDefaultCulture() .Equals(CultureInfo.GetCultureInfo(c).Name, StringComparison.OrdinalIgnoreCase) - }); + }).ToList(); + + if (cultures.Count == 0) + { + cultures.Add(new Culture { Name = "en", DisplayName = "English", IsDefault = true }); + } + return cultures.OrderBy(item => item.DisplayName); } } diff --git a/Oqtane.Server/Controllers/SiteGroupController.cs b/Oqtane.Server/Controllers/SiteGroupController.cs new file mode 100644 index 00000000..e59f57d8 --- /dev/null +++ b/Oqtane.Server/Controllers/SiteGroupController.cs @@ -0,0 +1,123 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Oqtane.Enums; +using Oqtane.Infrastructure; +using Oqtane.Models; +using Oqtane.Repository; +using Oqtane.Shared; + +namespace Oqtane.Controllers +{ + [Route(ControllerRoutes.ApiRoute)] + public class SiteGroupController : Controller + { + private readonly ISiteGroupRepository _siteGroupRepository; + private readonly ISyncManager _syncManager; + private readonly ILogManager _logger; + private readonly Alias _alias; + + public SiteGroupController(ISiteGroupRepository siteGroupRepository, ISyncManager syncManager, ILogManager logger, ITenantManager tenantManager) + { + _siteGroupRepository = siteGroupRepository; + _syncManager = syncManager; + _logger = logger; + _alias = tenantManager.GetAlias(); + } + + // GET: api/?siteid=x&groupid=y + [HttpGet] + [Authorize(Roles = RoleNames.Host)] + public IEnumerable Get(string siteid, string groupid) + { + if (int.TryParse(siteid, out int SiteId) && int.TryParse(groupid, out int SiteGroupDefinitionId)) + { + return _siteGroupRepository.GetSiteGroups(SiteId, SiteGroupDefinitionId).ToList(); + } + else + { + _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Get Attempt for SiteId {SiteId} And SiteGroupDefinitionId {SiteGroupDefinitionId}", siteid, groupid); + HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; + return null; + } + } + + // GET api//5 + [HttpGet("{id}")] + [Authorize(Roles = RoleNames.Host)] + public SiteGroup Get(int id) + { + var siteGroup = _siteGroupRepository.GetSiteGroup(id); + if (siteGroup != null) + { + return siteGroup; + } + else + { + HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; + return null; + } + } + + // POST api/ + [HttpPost] + [Authorize(Roles = RoleNames.Host)] + public SiteGroup Post([FromBody] SiteGroup siteGroup) + { + if (ModelState.IsValid) + { + siteGroup = _siteGroupRepository.AddSiteGroup(siteGroup); + _syncManager.AddSyncEvent(_alias, EntityNames.SiteGroup, siteGroup.SiteGroupDefinitionId, SyncEventActions.Create); + _logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Group Added {SiteGroup}", siteGroup); + } + else + { + _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Post Attempt {SiteGroup}", siteGroup); + HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; + siteGroup = null; + } + return siteGroup; + } + + // PUT api//5 + [HttpPut("{id}")] + [Authorize(Roles = RoleNames.Host)] + public SiteGroup Put(int id, [FromBody] SiteGroup siteGroup) + { + if (ModelState.IsValid && siteGroup.SiteGroupDefinitionId == id && _siteGroupRepository.GetSiteGroup(siteGroup.SiteGroupDefinitionId, false) != null) + { + siteGroup = _siteGroupRepository.UpdateSiteGroup(siteGroup); + _syncManager.AddSyncEvent(_alias, EntityNames.SiteGroup, siteGroup.SiteGroupDefinitionId, SyncEventActions.Update); + _logger.Log(LogLevel.Information, this, LogFunction.Update, "Site Group Updated {SiteGroup}", siteGroup); + } + else + { + _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Put Attempt {SiteGroup}", siteGroup); + HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; + siteGroup = null; + } + return siteGroup; + } + + // DELETE api//5 + [HttpDelete("{id}")] + [Authorize(Roles = RoleNames.Host)] + public void Delete(int id) + { + var siteGroup = _siteGroupRepository.GetSiteGroup(id); + if (siteGroup != null) + { + _siteGroupRepository.DeleteSiteGroup(id); + _syncManager.AddSyncEvent(_alias, EntityNames.SiteGroup, siteGroup.SiteGroupDefinitionId, SyncEventActions.Delete); + _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Group Deleted {SiteGroupDefinitionId}", id); + } + else + { + _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Delete Attempt {SiteGroupDefinitionId}", id); + HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; + } + } + } +} diff --git a/Oqtane.Server/Controllers/SiteGroupDefinitionController.cs b/Oqtane.Server/Controllers/SiteGroupDefinitionController.cs new file mode 100644 index 00000000..ed419755 --- /dev/null +++ b/Oqtane.Server/Controllers/SiteGroupDefinitionController.cs @@ -0,0 +1,114 @@ +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Oqtane.Enums; +using Oqtane.Models; +using Oqtane.Shared; +using Oqtane.Infrastructure; +using Oqtane.Repository; +using System.Net; +using System.Linq; + +namespace Oqtane.Controllers +{ + [Route(ControllerRoutes.ApiRoute)] + public class SiteGroupDefinitionController : Controller + { + private readonly ISiteGroupDefinitionRepository _siteGroupDefinitionRepository; + private readonly ISyncManager _syncManager; + private readonly ILogManager _logger; + private readonly Alias _alias; + + public SiteGroupDefinitionController(ISiteGroupDefinitionRepository siteGroupDefinitionRepository, ISyncManager syncManager, ILogManager logger, ITenantManager tenantManager) + { + _siteGroupDefinitionRepository = siteGroupDefinitionRepository; + _syncManager = syncManager; + _logger = logger; + _alias = tenantManager.GetAlias(); + } + + // GET: api/ + [HttpGet] + [Authorize(Roles = RoleNames.Host)] + public IEnumerable Get() + { + return _siteGroupDefinitionRepository.GetSiteGroupDefinitions().ToList(); + } + + // GET api//5 + [HttpGet("{id}")] + [Authorize(Roles = RoleNames.Host)] + public SiteGroupDefinition Get(int id) + { + var group = _siteGroupDefinitionRepository.GetSiteGroupDefinition(id); + if (group != null) + { + return group; + } + else + { + HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; + return null; + } + } + + // POST api/ + [HttpPost] + [Authorize(Roles = RoleNames.Host)] + public SiteGroupDefinition Post([FromBody] SiteGroupDefinition siteGroupDefinition) + { + if (ModelState.IsValid) + { + siteGroupDefinition = _siteGroupDefinitionRepository.AddSiteGroupDefinition(siteGroupDefinition); + _syncManager.AddSyncEvent(_alias, EntityNames.SiteGroupDefinition, siteGroupDefinition.SiteGroupDefinitionId, SyncEventActions.Create); + _logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Group Definition Added {Group}", siteGroupDefinition); + } + else + { + _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Definition Post Attempt {Group}", siteGroupDefinition); + HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; + siteGroupDefinition = null; + } + return siteGroupDefinition; + } + + // PUT api//5 + [HttpPut("{id}")] + [Authorize(Roles = RoleNames.Host)] + public SiteGroupDefinition Put(int id, [FromBody] SiteGroupDefinition siteGroupDefinition) + { + if (ModelState.IsValid && siteGroupDefinition.SiteGroupDefinitionId == id && _siteGroupDefinitionRepository.GetSiteGroupDefinition(siteGroupDefinition.SiteGroupDefinitionId, false) != null) + { + siteGroupDefinition = _siteGroupDefinitionRepository.UpdateSiteGroupDefinition(siteGroupDefinition); + _syncManager.AddSyncEvent(_alias, EntityNames.SiteGroupDefinition, siteGroupDefinition.SiteGroupDefinitionId, SyncEventActions.Update); + _logger.Log(LogLevel.Information, this, LogFunction.Update, "Site Group Definition Updated {Group}", siteGroupDefinition); + } + else + { + _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Definition Put Attempt {Group}", siteGroupDefinition); + HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; + siteGroupDefinition = null; + } + return siteGroupDefinition; + } + + // DELETE api//5 + [HttpDelete("{id}")] + [Authorize(Roles = RoleNames.Host)] + public void Delete(int id) + { + var siteGroupDefinition = _siteGroupDefinitionRepository.GetSiteGroupDefinition(id); + if (siteGroupDefinition != null) + { + _siteGroupDefinitionRepository.DeleteSiteGroupDefinition(id); + _syncManager.AddSyncEvent(_alias, EntityNames.SiteGroupDefinition, siteGroupDefinition.SiteGroupDefinitionId, SyncEventActions.Delete); + _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Group Definition Deleted {siteGroupDefinitionId}", id); + } + else + { + _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Definition Delete Attempt {siteGroupDefinitionId}", id); + HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; + } + } + } +} diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index 8d0c3f75..a541ebfd 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -233,6 +233,8 @@ namespace Microsoft.Extensions.DependencyInjection services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); // providers services.AddScoped(); @@ -282,6 +284,8 @@ namespace Microsoft.Extensions.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); // managers services.AddTransient(); diff --git a/Oqtane.Server/Infrastructure/DatabaseManager.cs b/Oqtane.Server/Infrastructure/DatabaseManager.cs index 87d6aab0..69d37b3f 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -594,7 +594,8 @@ namespace Oqtane.Infrastructure Prerender = (rendermode == RenderModes.Interactive), Hybrid = false, EnhancedNavigation = true, - TenantId = tenant.TenantId + CultureCode = "en", + TenantId = tenant.TenantId // required for site creation }; site = sites.AddSite(site); diff --git a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs index 5d0ba275..48589187 100644 --- a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs +++ b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs @@ -121,11 +121,23 @@ namespace Oqtane.Infrastructure { if (settingRepository.GetSettingValue(settings, "SMTPAuthentication", "Basic") == "Basic") { - // it is possible to use basic without any authentication (not recommended) if (settingRepository.GetSettingValue(settings, "SMTPUsername", "") != "" && settingRepository.GetSettingValue(settings, "SMTPPassword", "") != "") { - await client.AuthenticateAsync(settingRepository.GetSettingValue(settings, "SMTPUsername", ""), + try + { + await client.AuthenticateAsync(settingRepository.GetSettingValue(settings, "SMTPUsername", ""), settingRepository.GetSettingValue(settings, "SMTPPassword", "")); + } + catch (Exception ex) + { + log += "SMTP Not Configured Properly In Site Settings - Basic Authentication Failed Using Username And Password - " + ex.Message + "
"; + valid = false; + } + + } + else + { + // it is possible to use basic without any authentication (not recommended) } } else diff --git a/Oqtane.Server/Infrastructure/Jobs/SynchronizationJob.cs b/Oqtane.Server/Infrastructure/Jobs/SynchronizationJob.cs new file mode 100644 index 00000000..8325d1a1 --- /dev/null +++ b/Oqtane.Server/Infrastructure/Jobs/SynchronizationJob.cs @@ -0,0 +1,778 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using Microsoft.Extensions.DependencyInjection; +using Oqtane.Models; +using Oqtane.Modules; +using Oqtane.Repository; +using Oqtane.Shared; + +namespace Oqtane.Infrastructure +{ + public class SynchronizationJob : HostedServiceBase + { + // JobType = "Oqtane.Infrastructure.SynchronizationJob, Oqtane.Server" + + // synchronization only supports sites in the same tenant (database) + // module title is used as a key to identify module instances on a page (ie. using "-" as a module title is problematic ie. content as configuration) + // relies on Module.ModifiedOn to be set if the module content changes (for efficiency) + // modules must implement ISynchronizable interface (new interface as IPortable was generally only implemented in an additive manner) + + // define settings that should not be synchronized (should be extensible in the future) + List excludedSettings = new List() { + new Setting { EntityName = EntityNames.Site, SettingName = "Search_LastIndexedOn" } + }; + + public SynchronizationJob(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory) + { + Name = "Synchronization Job"; + Frequency = "m"; // minute + Interval = 1; + IsEnabled = false; + } + + // job is executed for each tenant in installation + public override string ExecuteJob(IServiceProvider provider) + { + string log = ""; + + var siteGroupDefinitionRepository = provider.GetRequiredService(); + var siteGroupRepository = provider.GetRequiredService(); + var siteRepository = provider.GetRequiredService(); + var aliasRepository = provider.GetRequiredService(); + var tenantManager = provider.GetRequiredService(); + var settingRepository = provider.GetRequiredService(); + + List siteGroups = null; + List sites = null; + List aliases = null; + + // get groups + var groups = siteGroupDefinitionRepository.GetSiteGroupDefinitions(); + + // iterate through groups which need to be synchronized + foreach (var group in groups.Where(item => item.Synchronize)) + { + // get data + if (siteGroups == null) + { + siteGroups = siteGroupRepository.GetSiteGroups().ToList(); + sites = siteRepository.GetSites().ToList(); + aliases = aliasRepository.GetAliases().ToList(); + } + + var aliasName = "https://" + aliases.First(item => item.TenantId == tenantManager.GetTenant().TenantId && item.SiteId == group.PrimarySiteId && item.IsDefault).Name; + log += $"Processing Primary Site: {sites.First(item => item.SiteId == group.PrimarySiteId).Name} - {aliasName}
"; + + // get primary site + var primarySite = sites.FirstOrDefault(item => item.SiteId == group.PrimarySiteId); + if (primarySite != null) + { + // update flag to prevent job from processing group again + group.Synchronize = false; + siteGroupDefinitionRepository.UpdateSiteGroupDefinition(group); + + // iterate through sites in group + foreach (var siteGroup in siteGroups.Where(item => item.SiteGroupDefinitionId == group.SiteGroupDefinitionId && item.SiteId != group.PrimarySiteId)) + { + // get secondary site + var secondarySite = sites.FirstOrDefault(item => item.SiteId == siteGroup.SiteId); + if (secondarySite != null) + { + // get default alias for site + siteGroup.AliasName = "https://" + aliases.First(item => item.TenantId == tenantManager.GetTenant().TenantId && item.SiteId == siteGroup.SiteId && item.IsDefault).Name; + + // initialize SynchronizedOn + if (siteGroup.SynchronizedOn == null) + { + siteGroup.SynchronizedOn = DateTime.MinValue; + } + + // replicate site + var siteLog = ReplicateSite(provider, tenantManager, settingRepository, siteGroup, primarySite, secondarySite); + + // set synchronized on date/time + siteGroup.SynchronizedOn = DateTime.UtcNow; + siteGroupRepository.UpdateSiteGroup(siteGroup); + + log += $"Processed Target Site: {secondarySite.Name} - {siteGroup.AliasName}
" + siteLog; + } + else + { + log += $"Site Group Has A SiteId {siteGroup.SiteId} Which Does Not Exist
"; + } + } + } + else + { + log += $"Site Group Has A PrimarySiteId {group.PrimarySiteId} Which Does Not Exist
"; + } + } + + if (string.IsNullOrEmpty(log)) + { + log = "No Site Groups Require Replication
"; + } + + return log; + } + + private string ReplicateSite(IServiceProvider provider, ITenantManager tenantManager, ISettingRepository settingRepository, SiteGroup siteGroup, Site primarySite, Site secondarySite) + { + var log = ""; + + // replicate roles/users + log += ReplicateRoles(provider, settingRepository, siteGroup, primarySite.SiteId, secondarySite.SiteId); + + // replicate folders/files + log += ReplicateFolders(provider, settingRepository, siteGroup, primarySite.SiteId, secondarySite.SiteId); + + // replicate pages/modules + log += ReplicatePages(provider, settingRepository, tenantManager, siteGroup, primarySite.SiteId, secondarySite.SiteId); + + // replicate site + if (primarySite.ModifiedOn > siteGroup.SynchronizedOn) + { + secondarySite.TimeZoneId = primarySite.TimeZoneId; + if (secondarySite.LogoFileId != primarySite.LogoFileId) + { + secondarySite.LogoFileId = ResolveFileId(provider, primarySite.LogoFileId, secondarySite.SiteId); + } + if (secondarySite.FaviconFileId != primarySite.FaviconFileId) + { + secondarySite.FaviconFileId = ResolveFileId(provider, primarySite.FaviconFileId, secondarySite.SiteId); ; + } + secondarySite.DefaultThemeType = primarySite.DefaultThemeType; + secondarySite.DefaultContainerType = primarySite.DefaultContainerType; + secondarySite.AdminContainerType = primarySite.AdminContainerType; + secondarySite.PwaIsEnabled = primarySite.PwaIsEnabled; + if (secondarySite.PwaAppIconFileId != primarySite.PwaAppIconFileId) + { + secondarySite.PwaAppIconFileId = ResolveFileId(provider, primarySite.PwaAppIconFileId, secondarySite.SiteId); ; + } + if (secondarySite.PwaSplashIconFileId != primarySite.PwaSplashIconFileId) + { + secondarySite.PwaSplashIconFileId = ResolveFileId(provider, primarySite.PwaSplashIconFileId, secondarySite.SiteId); ; + } + secondarySite.AllowRegistration = primarySite.AllowRegistration; + secondarySite.VisitorTracking = primarySite.VisitorTracking; + secondarySite.CaptureBrokenUrls = primarySite.CaptureBrokenUrls; + secondarySite.SiteGuid = primarySite.SiteGuid; + secondarySite.RenderMode = primarySite.RenderMode; + secondarySite.Runtime = primarySite.Runtime; + secondarySite.Prerender = primarySite.Prerender; + secondarySite.Hybrid = primarySite.Hybrid; + secondarySite.EnhancedNavigation = primarySite.EnhancedNavigation; + secondarySite.Version = primarySite.Version; + secondarySite.HeadContent = primarySite.HeadContent; + secondarySite.BodyContent = primarySite.BodyContent; + secondarySite.CreatedBy = primarySite.CreatedBy; + secondarySite.CreatedOn = primarySite.CreatedOn; + secondarySite.ModifiedBy = primarySite.ModifiedBy; + secondarySite.ModifiedOn = primarySite.ModifiedOn; + secondarySite.IsDeleted = primarySite.IsDeleted; + secondarySite.DeletedBy = primarySite.DeletedBy; + secondarySite.DeletedOn = primarySite.DeletedOn; + + var siteRepository = provider.GetRequiredService(); + if (siteGroup.Synchronize) + { + siteRepository.UpdateSite(secondarySite); + } + log += Log(siteGroup, $"Secondary Site Updated: {secondarySite.Name}"); + } + + // site settings + log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Site, primarySite.SiteId, secondarySite.SiteId); + + if (siteGroup.SynchronizedOn == DateTime.MinValue || !string.IsNullOrEmpty(log)) + { + // clear cache for secondary site if any content was replicated + var syncManager = provider.GetRequiredService(); + var alias = new Alias { TenantId = tenantManager.GetTenant().TenantId, SiteId = secondarySite.SiteId }; + syncManager.AddSyncEvent(alias, EntityNames.Site, secondarySite.SiteId, SyncEventActions.Refresh); + } + + if (!string.IsNullOrEmpty(log) && !string.IsNullOrEmpty(siteGroup.NotifyRoleName)) + { + // send change log to users in role + SendNotifications(provider, secondarySite.SiteId, secondarySite.Name, siteGroup.NotifyRoleName, log); + } + + return log; + } + + private int? ResolveFileId(IServiceProvider provider, int? fileId, int siteId) + { + if (fileId != null) + { + var fileRepository = provider.GetRequiredService(); + var file = fileRepository.GetFile(fileId.Value); + fileId = fileRepository.GetFile(siteId, file.Folder.Path, file.Name).FileId; + } + return fileId; + } + + private string ReplicateRoles(IServiceProvider provider, ISettingRepository settingRepository, SiteGroup siteGroup, int primarySiteId, int secondarySiteId) + { + // get roles + var roleRepository = provider.GetRequiredService(); + var primaryRoles = roleRepository.GetRoles(primarySiteId); + var secondaryRoles = roleRepository.GetRoles(secondarySiteId).ToList(); + var log = ""; + + foreach (var primaryRole in primaryRoles) + { + var role = secondaryRoles.FirstOrDefault(item => item.Name == primaryRole.Name); + + var secondaryRole = role; + if (secondaryRole == null) + { + secondaryRole = new Role(); + secondaryRole.SiteId = secondarySiteId; + } + + if (role == null || primaryRole.ModifiedOn > siteGroup.SynchronizedOn) + { + // set all properties + secondaryRole.Name = primaryRole.Name; + secondaryRole.Description = primaryRole.Description; + secondaryRole.IsAutoAssigned = primaryRole.IsAutoAssigned; + secondaryRole.IsSystem = primaryRole.IsSystem; + + if (role == null) + { + if (siteGroup.Synchronize) + { + roleRepository.AddRole(secondaryRole); + } + log += Log(siteGroup, $"Role Added: {secondaryRole.Name}"); + } + else + { + if (siteGroup.Synchronize) + { + roleRepository.UpdateRole(secondaryRole); + } + log += Log(siteGroup, $"Role Updated: {secondaryRole.Name}"); + secondaryRoles.Remove(role); + } + } + } + + // remove roles in the secondary site which do not exist in the primary site + foreach (var secondaryRole in secondaryRoles.Where(item => !primaryRoles.Select(item => item.Name).Contains(item.Name))) + { + if (siteGroup.Synchronize) + { + roleRepository.DeleteRole(secondaryRole.RoleId); + } + log += Log(siteGroup, $"Role Deleted: {secondaryRole.Name}"); + } + + // settings + log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Role, primarySiteId, secondarySiteId); + + return log; + } + + private string ReplicateFolders(IServiceProvider provider, ISettingRepository settingRepository, SiteGroup siteGroup, int primarySiteId, int secondarySiteId) + { + var folderRepository = provider.GetRequiredService(); + var fileRepository = provider.GetRequiredService(); + var log = ""; + + // get folders (ignore personalized) + var primaryFolders = folderRepository.GetFolders(primarySiteId).Where(item => !item.Path.StartsWith("Users/")); + var secondaryFolders = folderRepository.GetFolders(secondarySiteId).Where(item => !item.Path.StartsWith("Users/")).ToList(); + + // iterate through folders + foreach (var primaryFolder in primaryFolders) + { + var folder = secondaryFolders.FirstOrDefault(item => item.Path == primaryFolder.Path); + + var secondaryFolder = folder; + if (secondaryFolder == null) + { + secondaryFolder = new Folder(); + secondaryFolder.SiteId = secondarySiteId; + } + + if (folder == null || primaryFolder.ModifiedOn > siteGroup.SynchronizedOn) + { + // set all properties + secondaryFolder.ParentId = null; + if (primaryFolder.ParentId != null) + { + var parentFolder = folderRepository.GetFolder(secondarySiteId, primaryFolders.First(item => item.FolderId == primaryFolder.ParentId).Path); + if (parentFolder != null) + { + secondaryFolder.ParentId = parentFolder.FolderId; + } + } + secondaryFolder.Type = primaryFolder.Type; + secondaryFolder.Name = primaryFolder.Name; + secondaryFolder.Order = primaryFolder.Order; + secondaryFolder.ImageSizes = primaryFolder.ImageSizes; + secondaryFolder.Capacity = primaryFolder.Capacity; + secondaryFolder.ImageSizes = primaryFolder.ImageSizes; + secondaryFolder.IsSystem = primaryFolder.IsSystem; + secondaryFolder.PermissionList = ReplicatePermissions(primaryFolder.PermissionList, secondarySiteId); + + if (folder == null) + { + if (siteGroup.Synchronize) + { + folderRepository.AddFolder(secondaryFolder); + } + log += Log(siteGroup, $"Folder Added: {secondaryFolder.Path}"); + } + else + { + if (siteGroup.Synchronize) + { + folderRepository.UpdateFolder(secondaryFolder); + } + log += Log(siteGroup, $"Folder Updated: {secondaryFolder.Path}"); + secondaryFolders.Remove(folder); + } + } + + // folder settings + log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Folder, primaryFolder.FolderId, secondaryFolder.FolderId); + + // get files for folder + var primaryFiles = fileRepository.GetFiles(primaryFolder.FolderId); + var secondaryFiles = fileRepository.GetFiles(secondaryFolder.FolderId).ToList(); + + foreach (var primaryFile in primaryFiles) + { + var file = secondaryFiles.FirstOrDefault(item => item.Name == primaryFile.Name); + + var secondaryFile = file; + if (secondaryFile == null) + { + secondaryFile = new Models.File(); + secondaryFile.FolderId = secondaryFolder.FolderId; + secondaryFile.Name = primaryFile.Name; + } + + if (file == null || primaryFile.ModifiedOn > siteGroup.SynchronizedOn) + { + // set all properties + secondaryFile.Extension = primaryFile.Extension; + secondaryFile.Size = primaryFile.Size; + secondaryFile.ImageHeight = primaryFile.ImageHeight; + secondaryFile.ImageWidth = primaryFile.ImageWidth; + secondaryFile.Description = primaryFile.Description; + + if (file == null) + { + if (siteGroup.Synchronize) + { + fileRepository.AddFile(secondaryFile); + ReplicateFile(folderRepository, primaryFolder, primaryFile, secondaryFolder, secondaryFile); + } + log += Log(siteGroup, $"File Added: {siteGroup.AliasName}{secondaryFolder.Path}{secondaryFile.Name}"); + } + else + { + if (siteGroup.Synchronize) + { + fileRepository.UpdateFile(secondaryFile); + ReplicateFile(folderRepository, primaryFolder, primaryFile, secondaryFolder, secondaryFile); + } + log += Log(siteGroup, $"File Updated: {siteGroup.AliasName}{secondaryFolder.Path}{secondaryFile.Name}"); + secondaryFiles.Remove(file); + } + } + } + + // remove files in the secondary site which do not exist in the primary site + foreach (var secondaryFile in secondaryFiles.Where(item => !primaryFiles.Select(item => item.Name).Contains(item.Name))) + { + if (siteGroup.Synchronize) + { + fileRepository.DeleteFile(secondaryFile.FileId); + var secondaryPath = Path.Combine(folderRepository.GetFolderPath(secondaryFolder), secondaryFile.Name); + System.IO.File.Delete(secondaryPath); + } + log += Log(siteGroup, $"File Deleted: {siteGroup.AliasName}{secondaryFolder.Path}{secondaryFile.Name}"); + } + } + + // remove folders in the secondary site which do not exist in the primary site + foreach (var secondaryFolder in secondaryFolders.Where(item => !primaryFolders.Select(item => item.Path).Contains(item.Path))) + { + if (siteGroup.Synchronize) + { + folderRepository.DeleteFolder(secondaryFolder.FolderId); + } + log += Log(siteGroup, $"Folder Deleted: {secondaryFolder.Path}"); + } + + return log; + } + + private void ReplicateFile(IFolderRepository folderRepository, Folder primaryFolder, Models.File primaryFile, Folder secondaryFolder, Models.File secondaryFile) + { + var primaryPath = Path.Combine(folderRepository.GetFolderPath(primaryFolder), primaryFile.Name); + var secondaryPath = Path.Combine(folderRepository.GetFolderPath(secondaryFolder), secondaryFile.Name); + System.IO.File.Copy(primaryPath, secondaryPath, true); + } + + private string ReplicatePages(IServiceProvider provider, ISettingRepository settingRepository, ITenantManager tenantManager, SiteGroup siteGroup, int primarySiteId, int secondarySiteId) + { + var pageRepository = provider.GetRequiredService(); + var pageModuleRepository = provider.GetRequiredService(); + var moduleRepository = provider.GetRequiredService(); + var log = ""; + + List primaryPageModules = null; + List secondaryPageModules = null; + + int tenantId = tenantManager.GetTenant().TenantId; + + // get pages (ignore personalized) + var primaryPages = pageRepository.GetPages(primarySiteId).Where(item => item.UserId == null); + var secondaryPages = pageRepository.GetPages(secondarySiteId).Where(item => item.UserId == null).ToList(); + + // iterate through primary pages + foreach (var primaryPage in primaryPages) + { + var page = secondaryPages.FirstOrDefault(item => item.Path == primaryPage.Path); + + var secondaryPage = page; + if (secondaryPage == null) + { + secondaryPage = new Page(); + secondaryPage.SiteId = secondarySiteId; + } + + if (page == null || primaryPage.ModifiedOn > siteGroup.SynchronizedOn) + { + // set all properties + secondaryPage.Path = primaryPage.Path; + secondaryPage.Name = primaryPage.Name; + secondaryPage.ParentId = null; + if (primaryPage.ParentId != null) + { + var parentPage = pageRepository.GetPage(primaryPages.First(item => item.PageId == primaryPage.ParentId).Path, secondarySiteId); + if (parentPage != null) + { + secondaryPage.ParentId = parentPage.PageId; + } + } + secondaryPage.Title = primaryPage.Title; + secondaryPage.Order = primaryPage.Order; + secondaryPage.Url = primaryPage.Url; + secondaryPage.ThemeType = primaryPage.ThemeType; + secondaryPage.DefaultContainerType = primaryPage.DefaultContainerType; + secondaryPage.HeadContent = primaryPage.HeadContent; + secondaryPage.BodyContent = primaryPage.BodyContent; + secondaryPage.Icon = primaryPage.Icon; + secondaryPage.IsNavigation = primaryPage.IsNavigation; + secondaryPage.IsClickable = primaryPage.IsClickable; + secondaryPage.UserId = null; + secondaryPage.IsPersonalizable = primaryPage.IsPersonalizable; + secondaryPage.EffectiveDate = primaryPage.EffectiveDate; + secondaryPage.ExpiryDate = primaryPage.ExpiryDate; + secondaryPage.CreatedBy = primaryPage.CreatedBy; + secondaryPage.CreatedOn = primaryPage.CreatedOn; + secondaryPage.ModifiedBy = primaryPage.ModifiedBy; + secondaryPage.ModifiedOn = primaryPage.ModifiedOn; + secondaryPage.DeletedBy = primaryPage.DeletedBy; + secondaryPage.DeletedOn = primaryPage.DeletedOn; + secondaryPage.IsDeleted = primaryPage.IsDeleted; + secondaryPage.PermissionList = ReplicatePermissions(primaryPage.PermissionList, secondarySiteId); + + if (page == null) + { + if (siteGroup.Synchronize) + { + secondaryPage = pageRepository.AddPage(secondaryPage); + } + log += Log(siteGroup, $"Page Added: {siteGroup.AliasName}{secondaryPage.Path}"); + } + else + { + if (siteGroup.Synchronize) + { + secondaryPage = pageRepository.UpdatePage(secondaryPage); + } + log += Log(siteGroup, $"Page Updated: {siteGroup.AliasName}{secondaryPage.Path}"); + secondaryPages.Remove(page); + } + } + + // page settings + log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Page, primaryPage.PageId, secondaryPage.PageId); + + // modules + if (primaryPageModules == null) + { + tenantManager.SetAlias(tenantId, primarySiteId); // required by ModuleDefinitionRepository.LoadModuleDefinitions() + primaryPageModules = pageModuleRepository.GetPageModules(primarySiteId).ToList(); + } + if (secondaryPageModules == null) + { + tenantManager.SetAlias(tenantId, secondarySiteId); // required by ModuleDefinitionRepository.LoadModuleDefinitions() + secondaryPageModules = pageModuleRepository.GetPageModules(secondarySiteId).ToList(); + } + foreach (var primaryPageModule in primaryPageModules.Where(item => item.PageId == primaryPage.PageId)) + { + var pageModule = secondaryPageModules.FirstOrDefault(item => item.PageId == secondaryPage.PageId && item.Module.ModuleDefinitionName == primaryPageModule.Module.ModuleDefinitionName && item.Title.ToLower() == primaryPageModule.Title.ToLower()); + + var secondaryPageModule = pageModule; + if (secondaryPageModule == null) + { + secondaryPageModule = new PageModule(); + secondaryPageModule.PageId = secondaryPage.PageId; + secondaryPageModule.Module = new Module(); + secondaryPageModule.Module.SiteId = secondarySiteId; + secondaryPageModule.Module.ModuleDefinitionName = primaryPageModule.Module.ModuleDefinitionName; + } + + if (pageModule == null || primaryPageModule.ModifiedOn > siteGroup.SynchronizedOn || primaryPageModule.Module.ModifiedOn > siteGroup.SynchronizedOn) + { + // set all properties + secondaryPageModule.Title = primaryPageModule.Title; + secondaryPageModule.Pane = primaryPageModule.Pane; + secondaryPageModule.Order = primaryPageModule.Order; + secondaryPageModule.ContainerType = primaryPageModule.ContainerType; + secondaryPageModule.Header = primaryPageModule.Header; + secondaryPageModule.Footer = primaryPageModule.Footer; + secondaryPageModule.IsDeleted = primaryPageModule.IsDeleted; + secondaryPageModule.Module.PermissionList = ReplicatePermissions(primaryPageModule.Module.PermissionList, secondarySiteId); + secondaryPageModule.Module.AllPages = false; + secondaryPageModule.Module.IsDeleted = false; + + var updateContent = false; + + if (pageModule == null) + { + // check if module exists + var module = secondaryPageModules.FirstOrDefault(item => item.Module.ModuleDefinitionName == primaryPageModule.Module.ModuleDefinitionName && item.Title.ToLower() == primaryPageModule.Title.ToLower())?.Module; + if (module == null) + { + // add new module + if (siteGroup.Synchronize) + { + module = moduleRepository.AddModule(secondaryPageModule.Module); + updateContent = true; + } + log += Log(siteGroup, $"Module Added: {module.Title} - {siteGroup.AliasName}{secondaryPage.Path}"); + } + if (module != null) + { + secondaryPageModule.ModuleId = module.ModuleId; + secondaryPageModule.Module = null; // remove tracking + if (siteGroup.Synchronize) + { + secondaryPageModule = pageModuleRepository.AddPageModule(secondaryPageModule); + } + log += Log(siteGroup, $"Page Module Added: {module.Title} - {siteGroup.AliasName}{secondaryPage.Path}"); + secondaryPageModule.Module = module; + } + } + else + { + // update existing module + if (primaryPageModule.Module.ModifiedOn > siteGroup.SynchronizedOn) + { + if (siteGroup.Synchronize) + { + moduleRepository.UpdateModule(secondaryPageModule.Module); + updateContent = true; + } + log += Log(siteGroup, $"Module Updated: {secondaryPageModule.Title} - {siteGroup.AliasName}{secondaryPage.Path}"); + } + if (primaryPageModule.ModifiedOn > siteGroup.SynchronizedOn) + { + if (siteGroup.Synchronize) + { + secondaryPageModule = pageModuleRepository.UpdatePageModule(secondaryPageModule); + } + log += Log(siteGroup, $"Page Module Updated: {secondaryPageModule.Title} - {siteGroup.AliasName}{secondaryPage.Path}"); + secondaryPageModules.Remove(pageModule); + } + } + + // module content + if (updateContent && primaryPageModule.Module.ModuleDefinition.ServerManagerType != "") + { + Type moduleType = Type.GetType(primaryPageModule.Module.ModuleDefinition.ServerManagerType); + if (moduleType != null && moduleType.GetInterface(nameof(ISynchronizable)) != null) + { + try + { + var moduleObject = ActivatorUtilities.CreateInstance(provider, moduleType); + var primaryModuleContent = ((ISynchronizable)moduleObject).ExtractModule(primaryPageModule.Module); + var secondaryModuleContent = ((ISynchronizable)moduleObject).ExtractModule(secondaryPageModule.Module); + if (primaryModuleContent != secondaryModuleContent) + { + if (siteGroup.Synchronize) + { + ((ISynchronizable)moduleObject).LoadModule(secondaryPageModule.Module, primaryModuleContent, primaryPageModule.Module.ModuleDefinition.Version); + } + log += Log(siteGroup, $"Module Content Updated: {secondaryPageModule.Title} - {siteGroup.AliasName}{secondaryPage.Path}"); + } + } + catch + { + // error exporting/importing + } + } + } + } + + // module settings + log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Module, primaryPageModule.ModuleId, secondaryPageModule.ModuleId); + } + } + + // remove modules in the secondary site which do not exist in the primary site + foreach (var secondaryPageModule in secondaryPageModules) + { + var primaryPageId = -1; + var secondaryPage = secondaryPages.FirstOrDefault(item => item.PageId == secondaryPageModule.PageId); + if (secondaryPage != null) + { + var primaryPage = primaryPages.FirstOrDefault(item => item.Path == secondaryPage.Path); + if (primaryPage != null) + { + primaryPageId = primaryPage.PageId; + } + } + if (!primaryPageModules.Any(item => item.PageId == primaryPageId && item.Module.ModuleDefinitionName == secondaryPageModule.Module.ModuleDefinitionName && item.Title.ToLower() == secondaryPageModule.Title.ToLower())) + { + if (siteGroup.Synchronize) + { + pageModuleRepository.DeletePageModule(secondaryPageModule.PageModuleId); + } + log += Log(siteGroup, $"Page Module Deleted: {secondaryPageModule.Title} - {siteGroup.AliasName}{secondaryPageModule.Page.Path}"); + } + } + + // remove pages in the secondary site which do not exist in the primary site + foreach (var secondaryPage in secondaryPages.Where(item => !primaryPages.Select(item => item.Path).Contains(item.Path))) + { + if (siteGroup.Synchronize) + { + pageRepository.DeletePage(secondaryPage.PageId); + } + log += Log(siteGroup, $"Page Deleted: {siteGroup.AliasName}{secondaryPage.Path}"); + } + + if (siteGroup.SynchronizedOn == DateTime.MinValue || !string.IsNullOrEmpty(log)) + { + // clear cache for secondary site if any content was replicated + var syncManager = provider.GetRequiredService(); + var alias = new Alias { TenantId = tenantManager.GetTenant().TenantId, SiteId = secondarySiteId }; + syncManager.AddSyncEvent(alias, EntityNames.Site, secondarySiteId, SyncEventActions.Refresh); + } + + return log; + } + + private List ReplicatePermissions(List permissionList, int siteId) + { + return permissionList.Select(item => new Permission + { + SiteId = siteId, + PermissionName = item.PermissionName, + RoleName = item.RoleName, + UserId = item.UserId, + IsAuthorized = item.IsAuthorized, + CreatedBy = item.CreatedBy, + CreatedOn = item.CreatedOn, + ModifiedBy = item.ModifiedBy, + ModifiedOn = item.ModifiedOn + }).ToList(); + } + + private string ReplicateSettings(ISettingRepository settingRepository, SiteGroup siteGroup, string entityName, int primaryEntityId, int secondaryEntityId) + { + var log = ""; + var updated = false; + + var secondarySettings = settingRepository.GetSettings(entityName, secondaryEntityId).ToList(); + foreach (var primarySetting in settingRepository.GetSettings(entityName, primaryEntityId)) + { + var secondarySetting = secondarySettings.FirstOrDefault(item => item.SettingName == primarySetting.SettingName); + if (secondarySetting == null) + { + secondarySetting = new Setting(); + secondarySetting.EntityName = primarySetting.EntityName; + secondarySetting.EntityId = secondaryEntityId; + secondarySetting.SettingName = primarySetting.SettingName; + secondarySetting.SettingValue = primarySetting.SettingValue; + secondarySetting.IsPrivate = primarySetting.IsPrivate; + if (siteGroup.Synchronize && !excludedSettings.Any(item => item.EntityName == secondarySetting.EntityName && item.SettingName == secondarySetting.SettingName)) + { + settingRepository.AddSetting(secondarySetting); + updated = true; + } + } + else + { + if (secondarySetting.SettingValue != primarySetting.SettingValue || secondarySetting.IsPrivate != primarySetting.IsPrivate) + { + secondarySetting.SettingValue = primarySetting.SettingValue; + secondarySetting.IsPrivate = primarySetting.IsPrivate; + if (siteGroup.Synchronize && !excludedSettings.Any(item => item.EntityName == secondarySetting.EntityName && item.SettingName == secondarySetting.SettingName)) + { + settingRepository.UpdateSetting(secondarySetting); + updated = true; + } + } + secondarySettings.Remove(secondarySetting); + } + } + + // any remaining secondary settings need to be deleted + foreach (var secondarySetting in secondarySettings) + { + if (siteGroup.Synchronize && !excludedSettings.Any(item => item.EntityName == secondarySetting.EntityName && item.SettingName == secondarySetting.SettingName)) + { + settingRepository.DeleteSetting(secondarySetting.EntityName, secondarySetting.SettingId); + updated = true; + } + } + + if (updated) + { + log += Log(siteGroup, $"{entityName} Settings Updated"); + } + + return log; + } + + private void SendNotifications(IServiceProvider provider, int siteId, string siteName, string roleName, string log) + { + var userRoleRepository = provider.GetRequiredService(); + var notificationRepository = provider.GetRequiredService(); + + foreach (var userRole in userRoleRepository.GetUserRoles(roleName, siteId)) + { + var notification = new Notification(siteId, userRole.User, $"{siteName} Change Log", log); + notificationRepository.AddNotification(notification); + } + } + + private string Log(SiteGroup siteGroup, string content) + { + // not necessary to log initial replication + if (siteGroup.SynchronizedOn != DateTime.MinValue) + { + return content + "
"; + } + else + { + return ""; + } + } + } +} diff --git a/Oqtane.Server/Infrastructure/LocalizationManager.cs b/Oqtane.Server/Infrastructure/LocalizationManager.cs index 3dfc0b54..50bda160 100644 --- a/Oqtane.Server/Infrastructure/LocalizationManager.cs +++ b/Oqtane.Server/Infrastructure/LocalizationManager.cs @@ -41,7 +41,9 @@ namespace Oqtane.Infrastructure public string[] GetSupportedCultures() { - return CultureInfo.GetCultures(CultureTypes.AllCultures).Select(item => item.Name).OrderBy(c => c).ToArray(); + return CultureInfo.GetCultures(CultureTypes.AllCultures) + .Where(item => item.Name.Length == 2) // major languages only (this could be configurable) + .Select(item => item.Name).OrderBy(c => c).ToArray(); } public string[] GetInstalledCultures() diff --git a/Oqtane.Server/Migrations/EntityBuilders/SiteGroupDefinitionEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/SiteGroupDefinitionEntityBuilder.cs new file mode 100644 index 00000000..72974ecb --- /dev/null +++ b/Oqtane.Server/Migrations/EntityBuilders/SiteGroupDefinitionEntityBuilder.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations.Operations; +using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; + +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global + +namespace Oqtane.Migrations.EntityBuilders +{ + public class SiteGroupDefinitionEntityBuilder : AuditableBaseEntityBuilder + { + private const string _entityTableName = "SiteGroupDefinition"; + private readonly PrimaryKey _primaryKey = new("PK_SiteGroupDefinition", x => x.SiteGroupDefinitionId); + + public SiteGroupDefinitionEntityBuilder(MigrationBuilder migrationBuilder, IDatabase database) : base(migrationBuilder, database) + { + EntityTableName = _entityTableName; + PrimaryKey = _primaryKey; + } + + protected override SiteGroupDefinitionEntityBuilder BuildTable(ColumnsBuilder table) + { + SiteGroupDefinitionId = AddAutoIncrementColumn(table, "SiteGroupDefinitionId"); + Name = AddStringColumn(table, "Name", 200); + PrimarySiteId = AddIntegerColumn(table, "PrimarySiteId"); + Synchronization = AddBooleanColumn(table, "Synchronization"); + Synchronize = AddBooleanColumn(table, "Synchronize"); + Localization = AddBooleanColumn(table, "Localization"); + + AddAuditableColumns(table); + + return this; + } + + public OperationBuilder SiteGroupDefinitionId { get; set; } + + public OperationBuilder Name { get; set; } + + public OperationBuilder PrimarySiteId { get; set; } + + public OperationBuilder Synchronization { get; set; } + + public OperationBuilder Synchronize { get; set; } + + public OperationBuilder Localization { get; set; } + } +} diff --git a/Oqtane.Server/Migrations/EntityBuilders/SiteGroupEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/SiteGroupEntityBuilder.cs new file mode 100644 index 00000000..ed063737 --- /dev/null +++ b/Oqtane.Server/Migrations/EntityBuilders/SiteGroupEntityBuilder.cs @@ -0,0 +1,52 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations.Operations; +using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; + +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global + +namespace Oqtane.Migrations.EntityBuilders +{ + public class SiteGroupEntityBuilder : AuditableBaseEntityBuilder + { + private const string _entityTableName = "SiteGroup"; + private readonly PrimaryKey _primaryKey = new("PK_SiteGroup", x => x.SiteGroupId); + private readonly ForeignKey _groupForeignKey = new("FK_SiteGroup_SiteGroupDefinition", x => x.SiteGroupDefinitionId, "SiteGroupDefinition", "SiteGroupDefinitionId", ReferentialAction.Cascade); + private readonly ForeignKey _siteForeignKey = new("FK_SiteGroup_Site", x => x.SiteId, "Site", "SiteId", ReferentialAction.Cascade); + + public SiteGroupEntityBuilder(MigrationBuilder migrationBuilder, IDatabase database) : base(migrationBuilder, database) + { + EntityTableName = _entityTableName; + PrimaryKey = _primaryKey; + ForeignKeys.Add(_groupForeignKey); + ForeignKeys.Add(_siteForeignKey); + } + + protected override SiteGroupEntityBuilder BuildTable(ColumnsBuilder table) + { + SiteGroupId = AddAutoIncrementColumn(table, "SiteGroupId"); + SiteGroupDefinitionId = AddIntegerColumn(table, "SiteGroupDefinitionId"); + SiteId = AddIntegerColumn(table, "SiteId"); + Synchronize = AddBooleanColumn(table, "Synchronize"); + NotifyRoleName = AddStringColumn(table, "NotifyRoleName", 256, true); + SynchronizedOn = AddDateTimeColumn(table, "SynchronizedOn", true); + + AddAuditableColumns(table); + + return this; + } + + public OperationBuilder SiteGroupId { get; set; } + + public OperationBuilder SiteGroupDefinitionId { get; set; } + + public OperationBuilder SiteId { get; set; } + + public OperationBuilder Synchronize { get; set; } + + public OperationBuilder NotifyRoleName { get; set; } + + public OperationBuilder SynchronizedOn { get; set; } + } +} diff --git a/Oqtane.Server/Migrations/Tenant/10010001_AddSiteGroups.cs b/Oqtane.Server/Migrations/Tenant/10010001_AddSiteGroups.cs new file mode 100644 index 00000000..42255ce8 --- /dev/null +++ b/Oqtane.Server/Migrations/Tenant/10010001_AddSiteGroups.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; +using Oqtane.Migrations.EntityBuilders; +using Oqtane.Repository; + +namespace Oqtane.Migrations.Tenant +{ + [DbContext(typeof(TenantDBContext))] + [Migration("Tenant.10.01.00.01")] + public class AddSiteGroups : MultiDatabaseMigration + { + public AddSiteGroups(IDatabase database) : base(database) + { + } + + protected override void Up(MigrationBuilder migrationBuilder) + { + var siteGroupDefinitionEntityBuilder = new SiteGroupDefinitionEntityBuilder(migrationBuilder, ActiveDatabase); + siteGroupDefinitionEntityBuilder.Create(); + + var siteGroupEntityBuilder = new SiteGroupEntityBuilder(migrationBuilder, ActiveDatabase); + siteGroupEntityBuilder.Create(); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + // not implemented + } + } +} diff --git a/Oqtane.Server/Migrations/Tenant/10010002_AddCultureCode.cs b/Oqtane.Server/Migrations/Tenant/10010002_AddCultureCode.cs new file mode 100644 index 00000000..0b411227 --- /dev/null +++ b/Oqtane.Server/Migrations/Tenant/10010002_AddCultureCode.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; +using Oqtane.Migrations.EntityBuilders; +using Oqtane.Repository; + +namespace Oqtane.Migrations.Tenant +{ + [DbContext(typeof(TenantDBContext))] + [Migration("Tenant.10.01.00.02")] + public class AddCultureCode : MultiDatabaseMigration + { + public AddCultureCode(IDatabase database) : base(database) + { + } + + protected override void Up(MigrationBuilder migrationBuilder) + { + var siteEntityBuilder = new SiteEntityBuilder(migrationBuilder, ActiveDatabase); + siteEntityBuilder.AddStringColumn("CultureCode", 10, true); + + var userEntityBuilder = new UserEntityBuilder(migrationBuilder, ActiveDatabase); + userEntityBuilder.AddStringColumn("CultureCode", 10, true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + // not implemented + } + } +} diff --git a/Oqtane.Server/Migrations/Tenant/10010003_RemoveHomePageId.cs b/Oqtane.Server/Migrations/Tenant/10010003_RemoveHomePageId.cs new file mode 100644 index 00000000..bbc79ac5 --- /dev/null +++ b/Oqtane.Server/Migrations/Tenant/10010003_RemoveHomePageId.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; +using Oqtane.Migrations.EntityBuilders; +using Oqtane.Repository; + +namespace Oqtane.Migrations.Tenant +{ + [DbContext(typeof(TenantDBContext))] + [Migration("Tenant.10.01.00.03")] + public class RemoveHomePageId : MultiDatabaseMigration + { + public RemoveHomePageId(IDatabase database) : base(database) + { + } + + protected override void Up(MigrationBuilder migrationBuilder) + { + var siteEntityBuilder = new SiteEntityBuilder(migrationBuilder, ActiveDatabase); + siteEntityBuilder.DropColumn("HomePageId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + // not implemented + } + } +} diff --git a/Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs b/Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs index 67f05805..da556510 100644 --- a/Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs +++ b/Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs @@ -19,7 +19,7 @@ using Microsoft.Extensions.Caching.Memory; namespace Oqtane.Modules.HtmlText.Manager { [PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")] - public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable, ISearchable + public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable, ISynchronizable, ISearchable { private readonly IHtmlTextRepository _htmlText; private readonly IDBContextDependencies _DBContextDependencies; @@ -41,7 +41,45 @@ namespace Oqtane.Modules.HtmlText.Manager _cache = cache; } + // IInstallable implementation + public bool Install(Tenant tenant, string version) + { + if (tenant.DBType == Constants.DefaultDBType && version == "1.0.1") + { + // version 1.0.0 used SQL scripts rather than migrations, so we need to seed the migration history table + _sqlRepository.ExecuteNonQuery(tenant, MigrationUtils.BuildInsertScript("HtmlText.01.00.00.00")); + } + return Migrate(new HtmlTextContext(_DBContextDependencies), tenant, MigrationType.Up); + } + + public bool Uninstall(Tenant tenant) + { + return Migrate(new HtmlTextContext(_DBContextDependencies), tenant, MigrationType.Down); + } + + // IPortable implementation public string ExportModule(Module module) + { + return GetModuleContent(module); + } + + public void ImportModule(Module module, string content, string version) + { + SaveModuleContent(module, content, version); + } + + // ISynchronizable implementation + public string ExtractModule(Module module) + { + return GetModuleContent(module); + } + + public void LoadModule(Module module, string content, string version) + { + SaveModuleContent(module, content, version); + } + + private string GetModuleContent(Module module) { string content = ""; var htmltexts = _htmlText.GetHtmlTexts(module.ModuleId); @@ -53,6 +91,23 @@ namespace Oqtane.Modules.HtmlText.Manager return content; } + private void SaveModuleContent(Module module, string content, string version) + { + content = WebUtility.HtmlDecode(content); + var htmlText = new Models.HtmlText(); + htmlText.ModuleId = module.ModuleId; + htmlText.Content = content; + _htmlText.AddHtmlText(htmlText); + + //clear the cache for the module + var alias = _tenantManager.GetAlias(); + if (alias != null) + { + _cache.Remove($"HtmlText:{alias.SiteKey}:{module.ModuleId}"); + } + } + + // ISearchable implementation public Task> GetSearchContentsAsync(PageModule pageModule, DateTime lastIndexedOn) { var searchContents = new List(); @@ -70,36 +125,5 @@ namespace Oqtane.Modules.HtmlText.Manager return Task.FromResult(searchContents); } - - public void ImportModule(Module module, string content, string version) - { - content = WebUtility.HtmlDecode(content); - var htmlText = new Models.HtmlText(); - htmlText.ModuleId = module.ModuleId; - htmlText.Content = content; - _htmlText.AddHtmlText(htmlText); - - //clear the cache for the module - var alias = _tenantManager.GetAlias(); - if(alias != null) - { - _cache.Remove($"HtmlText:{alias.SiteKey}:{module.ModuleId}"); - } - } - - public bool Install(Tenant tenant, string version) - { - if (tenant.DBType == Constants.DefaultDBType && version == "1.0.1") - { - // version 1.0.0 used SQL scripts rather than migrations, so we need to seed the migration history table - _sqlRepository.ExecuteNonQuery(tenant, MigrationUtils.BuildInsertScript("HtmlText.01.00.00.00")); - } - return Migrate(new HtmlTextContext(_DBContextDependencies), tenant, MigrationType.Up); - } - - public bool Uninstall(Tenant tenant) - { - return Migrate(new HtmlTextContext(_DBContextDependencies), tenant, MigrationType.Down); - } } } diff --git a/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextRepository.cs b/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextRepository.cs index cfeb8eb3..4c320455 100644 --- a/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextRepository.cs +++ b/Oqtane.Server/Modules/HtmlText/Repository/HtmlTextRepository.cs @@ -2,17 +2,29 @@ using System.Linq; using Oqtane.Documentation; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; +using Oqtane.Repository; namespace Oqtane.Modules.HtmlText.Repository { + [PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")] + public interface IHtmlTextRepository + { + IEnumerable GetHtmlTexts(int moduleId); + Models.HtmlText GetHtmlText(int htmlTextId); + Models.HtmlText AddHtmlText(Models.HtmlText htmlText); + void DeleteHtmlText(int htmlTextId); + } + [PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")] public class HtmlTextRepository : IHtmlTextRepository, ITransientService { private readonly IDbContextFactory _factory; + private readonly IModuleRepository _moduleRepository; - public HtmlTextRepository(IDbContextFactory factory) + public HtmlTextRepository(IDbContextFactory factory, IModuleRepository moduleRepository) { _factory = factory; + _moduleRepository = moduleRepository; } public IEnumerable GetHtmlTexts(int moduleId) @@ -32,6 +44,11 @@ namespace Oqtane.Modules.HtmlText.Repository using var db = _factory.CreateDbContext(); db.HtmlText.Add(htmlText); db.SaveChanges(); + + // update module ModifiedOn date + var module = _moduleRepository.GetModule(htmlText.ModuleId); + _moduleRepository.UpdateModule(module); + return htmlText; } @@ -39,8 +56,15 @@ namespace Oqtane.Modules.HtmlText.Repository { using var db = _factory.CreateDbContext(); Models.HtmlText htmlText = db.HtmlText.FirstOrDefault(item => item.HtmlTextId == htmlTextId); - if (htmlText != null) db.HtmlText.Remove(htmlText); - db.SaveChanges(); + if (htmlText != null) + { + db.HtmlText.Remove(htmlText); + db.SaveChanges(); + + // update module ModifiedOn date + var module = _moduleRepository.GetModule(htmlText.ModuleId); + _moduleRepository.UpdateModule(module); + } } } } diff --git a/Oqtane.Server/Modules/HtmlText/Repository/IHtmlTextRepository.cs b/Oqtane.Server/Modules/HtmlText/Repository/IHtmlTextRepository.cs deleted file mode 100644 index d586f0ef..00000000 --- a/Oqtane.Server/Modules/HtmlText/Repository/IHtmlTextRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; -using Oqtane.Documentation; - -namespace Oqtane.Modules.HtmlText.Repository -{ - [PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")] - public interface IHtmlTextRepository - { - IEnumerable GetHtmlTexts(int moduleId); - Models.HtmlText GetHtmlText(int htmlTextId); - Models.HtmlText AddHtmlText(Models.HtmlText htmlText); - void DeleteHtmlText(int htmlTextId); - } -} diff --git a/Oqtane.Server/Modules/ISynchronizable.cs b/Oqtane.Server/Modules/ISynchronizable.cs new file mode 100644 index 00000000..7dce3284 --- /dev/null +++ b/Oqtane.Server/Modules/ISynchronizable.cs @@ -0,0 +1,13 @@ +using Oqtane.Models; + +namespace Oqtane.Modules +{ + public interface ISynchronizable + { + // You Must Set The "ServerManagerType" In Your IModule Interface + + string ExtractModule(Module module); + + void LoadModule(Module module, string content, string version); + } +} diff --git a/Oqtane.Server/Repository/Context/TenantDBContext.cs b/Oqtane.Server/Repository/Context/TenantDBContext.cs index 47932d7d..0c970c3b 100644 --- a/Oqtane.Server/Repository/Context/TenantDBContext.cs +++ b/Oqtane.Server/Repository/Context/TenantDBContext.cs @@ -134,5 +134,7 @@ namespace Oqtane.Repository public virtual DbSet SearchContentWord { get; set; } public virtual DbSet SearchWord { get; set; } public virtual DbSet MigrationHistory { get; set; } + public virtual DbSet SiteGroupDefinition { get; set; } + public virtual DbSet SiteGroup { get; set; } } } diff --git a/Oqtane.Server/Repository/SiteGroupDefinitionRepository.cs b/Oqtane.Server/Repository/SiteGroupDefinitionRepository.cs new file mode 100644 index 00000000..1d1019be --- /dev/null +++ b/Oqtane.Server/Repository/SiteGroupDefinitionRepository.cs @@ -0,0 +1,75 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore; +using Oqtane.Models; + +namespace Oqtane.Repository +{ + public interface ISiteGroupDefinitionRepository + { + IEnumerable GetSiteGroupDefinitions(); + SiteGroupDefinition AddSiteGroupDefinition(SiteGroupDefinition siteGroupDefinition); + SiteGroupDefinition UpdateSiteGroupDefinition(SiteGroupDefinition siteGroupDefinition); + SiteGroupDefinition GetSiteGroupDefinition(int siteGroupDefinitionId); + SiteGroupDefinition GetSiteGroupDefinition(int siteGroupDefinitionId, bool tracking); + void DeleteSiteGroupDefinition(int siteGroupDefinitionId); + } + + public class SiteGroupDefinitionRepository : ISiteGroupDefinitionRepository + { + private readonly IDbContextFactory _dbContextFactory; + + public SiteGroupDefinitionRepository(IDbContextFactory dbContextFactory) + { + _dbContextFactory = dbContextFactory; + } + + public IEnumerable GetSiteGroupDefinitions() + { + using var db = _dbContextFactory.CreateDbContext(); + return db.SiteGroupDefinition.ToList(); + } + + public SiteGroupDefinition AddSiteGroupDefinition(SiteGroupDefinition siteGroupDefinition) + { + using var db = _dbContextFactory.CreateDbContext(); + db.SiteGroupDefinition.Add(siteGroupDefinition); + db.SaveChanges(); + return siteGroupDefinition; + } + + public SiteGroupDefinition UpdateSiteGroupDefinition(SiteGroupDefinition siteGroupDefinition) + { + using var db = _dbContextFactory.CreateDbContext(); + db.Entry(siteGroupDefinition).State = EntityState.Modified; + db.SaveChanges(); + return siteGroupDefinition; + } + + public SiteGroupDefinition GetSiteGroupDefinition(int siteGroupDefinitionId) + { + return GetSiteGroupDefinition(siteGroupDefinitionId, true); + } + + public SiteGroupDefinition GetSiteGroupDefinition(int siteGroupDefinitionId, bool tracking) + { + using var db = _dbContextFactory.CreateDbContext(); + if (tracking) + { + return db.SiteGroupDefinition.FirstOrDefault(item => item.SiteGroupDefinitionId == siteGroupDefinitionId); + } + else + { + return db.SiteGroupDefinition.AsNoTracking().FirstOrDefault(item => item.SiteGroupDefinitionId == siteGroupDefinitionId); + } + } + + public void DeleteSiteGroupDefinition(int siteGroupDefinitionId) + { + using var db = _dbContextFactory.CreateDbContext(); + SiteGroupDefinition group = db.SiteGroupDefinition.Find(siteGroupDefinitionId); + db.SiteGroupDefinition.Remove(group); + db.SaveChanges(); + } + } +} diff --git a/Oqtane.Server/Repository/SiteGroupRepository.cs b/Oqtane.Server/Repository/SiteGroupRepository.cs new file mode 100644 index 00000000..644cec0c --- /dev/null +++ b/Oqtane.Server/Repository/SiteGroupRepository.cs @@ -0,0 +1,88 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore; +using Oqtane.Models; + +namespace Oqtane.Repository +{ + public interface ISiteGroupRepository + { + IEnumerable GetSiteGroups(); + IEnumerable GetSiteGroups(int siteId, int siteGroupDefinitionId); + SiteGroup AddSiteGroup(SiteGroup siteGroup); + SiteGroup UpdateSiteGroup(SiteGroup siteGroup); + SiteGroup GetSiteGroup(int siteSiteGroupDefinitionId); + SiteGroup GetSiteGroup(int siteSiteGroupDefinitionId, bool tracking); + void DeleteSiteGroup(int siteSiteGroupDefinitionId); + } + + public class SiteGroupRepository : ISiteGroupRepository + { + private readonly IDbContextFactory _dbContextFactory; + + public SiteGroupRepository(IDbContextFactory dbContextFactory) + { + _dbContextFactory = dbContextFactory; + } + + public IEnumerable GetSiteGroups() + { + return GetSiteGroups(-1, -1); + } + + public IEnumerable GetSiteGroups(int siteId, int siteGroupDefinitionId) + { + using var db = _dbContextFactory.CreateDbContext(); + return db.SiteGroup + .Where(item => (siteId == -1 || item.SiteId == siteId) && (siteGroupDefinitionId == -1 || item.SiteGroupDefinitionId == siteGroupDefinitionId)) + .Include(item => item.SiteGroupDefinition) // eager load + .ToList(); + } + + public SiteGroup AddSiteGroup(SiteGroup SiteGroup) + { + using var db = _dbContextFactory.CreateDbContext(); + db.SiteGroup.Add(SiteGroup); + db.SaveChanges(); + return SiteGroup; + } + + public SiteGroup UpdateSiteGroup(SiteGroup SiteGroup) + { + using var db = _dbContextFactory.CreateDbContext(); + db.Entry(SiteGroup).State = EntityState.Modified; + db.SaveChanges(); + return SiteGroup; + } + + public SiteGroup GetSiteGroup(int SiteGroupDefinitionId) + { + return GetSiteGroup(SiteGroupDefinitionId, true); + } + + public SiteGroup GetSiteGroup(int SiteGroupDefinitionId, bool tracking) + { + using var db = _dbContextFactory.CreateDbContext(); + if (tracking) + { + return db.SiteGroup + .Include(item => item.SiteGroupDefinition) // eager load + .FirstOrDefault(item => item.SiteGroupDefinitionId == SiteGroupDefinitionId); + } + else + { + return db.SiteGroup.AsNoTracking() + .Include(item => item.SiteGroupDefinition) // eager load + .FirstOrDefault(item => item.SiteGroupDefinitionId == SiteGroupDefinitionId); + } + } + + public void DeleteSiteGroup(int SiteGroupDefinitionId) + { + using var db = _dbContextFactory.CreateDbContext(); + SiteGroup SiteGroup = db.SiteGroup.Find(SiteGroupDefinitionId); + db.SiteGroup.Remove(SiteGroup); + db.SaveChanges(); + } + } +} diff --git a/Oqtane.Server/Services/SiteService.cs b/Oqtane.Server/Services/SiteService.cs index ef7b32d6..ea232358 100644 --- a/Oqtane.Server/Services/SiteService.cs +++ b/Oqtane.Server/Services/SiteService.cs @@ -21,6 +21,8 @@ namespace Oqtane.Services public class ServerSiteService : ISiteService { private readonly ISiteRepository _sites; + private readonly ISiteGroupRepository _siteGroups; + private readonly IAliasRepository _aliases; private readonly IPageRepository _pages; private readonly IThemeRepository _themes; private readonly IPageModuleRepository _pageModules; @@ -37,9 +39,11 @@ namespace Oqtane.Services private readonly IHttpContextAccessor _accessor; private readonly string _private = "[PRIVATE]"; - public ServerSiteService(ISiteRepository sites, IPageRepository pages, IThemeRepository themes, IPageModuleRepository pageModules, IModuleDefinitionRepository moduleDefinitions, ILanguageRepository languages, IUserManager userManager, IUserPermissions userPermissions, ISettingRepository settings, ITenantManager tenantManager, ISyncManager syncManager, IConfigManager configManager, ILogManager logger, IMemoryCache cache, IHttpContextAccessor accessor) + public ServerSiteService(ISiteRepository sites, ISiteGroupRepository siteGroups, IAliasRepository aliases, IPageRepository pages, IThemeRepository themes, IPageModuleRepository pageModules, IModuleDefinitionRepository moduleDefinitions, ILanguageRepository languages, IUserManager userManager, IUserPermissions userPermissions, ISettingRepository settings, ITenantManager tenantManager, ISyncManager syncManager, IConfigManager configManager, ILogManager logger, IMemoryCache cache, IHttpContextAccessor accessor) { _sites = sites; + _siteGroups = siteGroups; + _aliases = aliases; _pages = pages; _themes = themes; _pageModules = pageModules; @@ -145,12 +149,7 @@ namespace Oqtane.Services site.Settings.Add(Constants.PageManagementModule, modules.FirstOrDefault(item => item.ModuleDefinitionName == Constants.PageManagementModule).ModuleId.ToString()); // languages - site.Languages = _languages.GetLanguages(site.SiteId).ToList(); - var defaultCulture = CultureInfo.GetCultureInfo(Constants.DefaultCulture); - if (!site.Languages.Exists(item => item.Code == defaultCulture.Name)) - { - site.Languages.Add(new Language { Code = defaultCulture.Name, Name = "", Version = Constants.Version, IsDefault = !site.Languages.Any(l => l.IsDefault) }); - } + site.Languages = GetLanguages(site.SiteId, alias.TenantId); // themes site.Themes = _themes.FilterThemes(_themes.GetThemes(site.SiteId).ToList()); @@ -158,6 +157,7 @@ namespace Oqtane.Services // installation date used for fingerprinting static assets site.Fingerprint = Utilities.GenerateSimpleHash(_configManager.GetSetting("InstallationDate", DateTime.UtcNow.ToString("yyyyMMddHHmm"))); + // set tenant site.TenantId = alias.TenantId; } else @@ -311,6 +311,39 @@ namespace Oqtane.Services return modules.OrderBy(item => item.PageId).ThenBy(item => item.Pane).ThenBy(item => item.Order).ToList(); } + private List GetLanguages(int siteId, int tenantId) + { + var languages = new List(); + + var siteGroups = _siteGroups.GetSiteGroups(); + if (siteGroups.Any(item => item.SiteId == siteId && item.SiteGroupDefinition.Localization)) + { + var sites = _sites.GetSites().ToList(); + var aliases = _aliases.GetAliases().ToList(); + + foreach (var siteGroupDefinitionId in siteGroups.Where(item => item.SiteId == siteId && item.SiteGroupDefinition.Localization).Select(item => item.SiteGroupDefinitionId).Distinct().ToList()) + { + foreach (var siteGroup in siteGroups.Where(item => item.SiteGroupDefinitionId == siteGroupDefinitionId)) + { + var site = sites.FirstOrDefault(item => item.SiteId == siteGroup.SiteId); + if (site != null && !string.IsNullOrEmpty(site.CultureCode)) + { + if (!languages.Any(item => item.Code == site.CultureCode)) + { + var alias = aliases.FirstOrDefault(item => item.SiteId == siteGroup.SiteId && item.TenantId == tenantId && item.IsDefault); + if (alias != null) + { + languages.Add(new Language { Code = site.CultureCode, Name = "", AliasName = alias.Name, IsDefault = true }); + } + } + } + } + } + } + + return languages; + } + [Obsolete("This method is deprecated.", false)] public void SetAlias(Alias alias) { diff --git a/Oqtane.Shared/Models/Language.cs b/Oqtane.Shared/Models/Language.cs index 750d8583..306c1eaf 100644 --- a/Oqtane.Shared/Models/Language.cs +++ b/Oqtane.Shared/Models/Language.cs @@ -41,6 +41,12 @@ namespace Oqtane.Models /// public string Version { get; set; } + [NotMapped] + /// + /// The primary alias name for the site with this language + /// + public string AliasName { get; set; } + public Language Clone() { return new Language @@ -50,7 +56,8 @@ namespace Oqtane.Models Name = Name, Code = Code, IsDefault = IsDefault, - Version = Version + Version = Version, + AliasName = AliasName }; } } diff --git a/Oqtane.Shared/Models/Site.cs b/Oqtane.Shared/Models/Site.cs index 4ba4ede5..98a12430 100644 --- a/Oqtane.Shared/Models/Site.cs +++ b/Oqtane.Shared/Models/Site.cs @@ -26,6 +26,11 @@ namespace Oqtane.Models /// public string TimeZoneId { get; set; } + /// + /// The default culture for the site (ie. en-US) + /// + public string CultureCode { get; set; } + /// /// Reference to a which has the Logo for this site. /// Should be an image. @@ -120,11 +125,6 @@ namespace Oqtane.Models /// public string Version { get; set; } - /// - /// The home page of the site - the "/" path will be used by default if no home page is specified - /// - public int? HomePageId { get; set; } - /// /// Content to be included in the head of the page /// @@ -217,6 +217,7 @@ namespace Oqtane.Models SiteId = SiteId, Name = Name, TimeZoneId = TimeZoneId, + CultureCode = CultureCode, LogoFileId = LogoFileId, FaviconFileId = FaviconFileId, DefaultThemeType = DefaultThemeType, @@ -235,7 +236,6 @@ namespace Oqtane.Models Hybrid = Hybrid, EnhancedNavigation = EnhancedNavigation, Version = Version, - HomePageId = HomePageId, HeadContent = HeadContent, BodyContent = BodyContent, IsDeleted = IsDeleted, @@ -262,6 +262,10 @@ namespace Oqtane.Models [NotMapped] [Obsolete("This property is deprecated.", false)] public string DefaultLayoutType { get; set; } + + [NotMapped] + [Obsolete("This property is deprecated.", false)] + public int? HomePageId { get; set; } #endregion } } diff --git a/Oqtane.Shared/Models/SiteGroup.cs b/Oqtane.Shared/Models/SiteGroup.cs new file mode 100644 index 00000000..dffc30b6 --- /dev/null +++ b/Oqtane.Shared/Models/SiteGroup.cs @@ -0,0 +1,49 @@ +using System; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Oqtane.Models +{ + public class SiteGroup : ModelBase + { + /// + /// ID to identify the site group + /// + public int SiteGroupId { get; set; } + + /// + /// Reference to the . + /// + public int SiteGroupDefinitionId { get; set; } + + /// + /// Reference to the . + /// + public int SiteId { get; set; } + + /// + /// Indicates if content should be synchronized for the site (false = compare, true = update) + /// + public bool Synchronize { get; set; } + + /// + /// The role who should be notified of changes to the site (non-primary site only) + /// + public string NotifyRoleName { get; set; } + + /// + /// The last date/time the site was synchronized + /// + public DateTime? SynchronizedOn { get; set; } + + /// + /// The itself. + /// + public SiteGroupDefinition SiteGroupDefinition { get; set; } + + /// + /// The primary alias for the site + /// + [NotMapped] + public string AliasName { get; set; } + } +} diff --git a/Oqtane.Shared/Models/SiteGroupDefinition.cs b/Oqtane.Shared/Models/SiteGroupDefinition.cs new file mode 100644 index 00000000..8436ed68 --- /dev/null +++ b/Oqtane.Shared/Models/SiteGroupDefinition.cs @@ -0,0 +1,35 @@ +namespace Oqtane.Models +{ + public class SiteGroupDefinition : ModelBase + { + /// + /// ID to identify the group + /// + public int SiteGroupDefinitionId { get; set; } + + /// + /// Name of the group + /// + public string Name { get; set; } + + /// + /// SiteId of the primary site in the group + /// + public int PrimarySiteId { get; set; } + + /// + /// Indicates if the group supports synchronization + /// + public bool Synchronization { get; set; } + + /// + /// Specifies if the group needs to be synchronized + /// + public bool Synchronize { get; set; } + + /// + /// Indicates if the group supports localization + /// + public bool Localization { get; set; } + } +} diff --git a/Oqtane.Shared/Models/User.cs b/Oqtane.Shared/Models/User.cs index dd3fa320..e84bb723 100644 --- a/Oqtane.Shared/Models/User.cs +++ b/Oqtane.Shared/Models/User.cs @@ -36,6 +36,11 @@ namespace Oqtane.Models /// public string TimeZoneId { get; set; } + /// + /// The default culture for the user (ie. en-US) + /// + public string CultureCode { get; set; } + /// /// Reference to a containing the users photo. /// @@ -140,6 +145,7 @@ namespace Oqtane.Models DisplayName = DisplayName, Email = Email, TimeZoneId = TimeZoneId, + CultureCode = CultureCode, PhotoFileId = PhotoFileId, LastLoginOn = LastLoginOn, LastIPAddress = LastIPAddress, diff --git a/Oqtane.Shared/Shared/Constants.cs b/Oqtane.Shared/Shared/Constants.cs index 8f52a8db..2df66252 100644 --- a/Oqtane.Shared/Shared/Constants.cs +++ b/Oqtane.Shared/Shared/Constants.cs @@ -4,8 +4,8 @@ namespace Oqtane.Shared { public class Constants { - public static readonly string Version = "10.0.4"; - public const string ReleaseVersions = "1.0.0,1.0.1,1.0.2,1.0.3,1.0.4,2.0.0,2.0.1,2.0.2,2.1.0,2.2.0,2.3.0,2.3.1,3.0.0,3.0.1,3.0.2,3.0.3,3.1.0,3.1.1,3.1.2,3.1.3,3.1.4,3.2.0,3.2.1,3.3.0,3.3.1,3.4.0,3.4.1,3.4.2,3.4.3,4.0.0,4.0.1,4.0.2,4.0.3,4.0.4,4.0.5,4.0.6,5.0.0,5.0.1,5.0.2,5.0.3,5.1.0,5.1.1,5.1.2,5.2.0,5.2.1,5.2.2,5.2.3,5.2.4,6.0.0,6.0.1,6.1.0,6.1.1,6.1.2,6.1.3,6.1.4,6.1.5,6.2.0,6.2.1,10.0.0,10.0.1,10.0.2,10.0.3,10.0.4"; + public static readonly string Version = "10.1.0"; + public const string ReleaseVersions = "1.0.0,1.0.1,1.0.2,1.0.3,1.0.4,2.0.0,2.0.1,2.0.2,2.1.0,2.2.0,2.3.0,2.3.1,3.0.0,3.0.1,3.0.2,3.0.3,3.1.0,3.1.1,3.1.2,3.1.3,3.1.4,3.2.0,3.2.1,3.3.0,3.3.1,3.4.0,3.4.1,3.4.2,3.4.3,4.0.0,4.0.1,4.0.2,4.0.3,4.0.4,4.0.5,4.0.6,5.0.0,5.0.1,5.0.2,5.0.3,5.1.0,5.1.1,5.1.2,5.2.0,5.2.1,5.2.2,5.2.3,5.2.4,6.0.0,6.0.1,6.1.0,6.1.1,6.1.2,6.1.3,6.1.4,6.1.5,6.2.0,6.2.1,10.0.0,10.0.1,10.0.2,10.0.3,10.0.4,10.1.0"; public const string PackageId = "Oqtane.Framework"; public const string ClientId = "Oqtane.Client"; public const string UpdaterPackageId = "Oqtane.Updater"; @@ -36,6 +36,7 @@ namespace Oqtane.Shared public const string AdminSiteTemplate = "Oqtane.Infrastructure.SiteTemplates.AdminSiteTemplate, Oqtane.Server"; public const string DefaultSiteTemplate = "Oqtane.Infrastructure.SiteTemplates.DefaultSiteTemplate, Oqtane.Server"; + public const string EmptySiteTemplate = "Oqtane.Infrastructure.SiteTemplates.EmptySiteTemplate, Oqtane.Server"; public static readonly string[] DefaultHostModuleTypes = new[] { "Upgrade", "Themes", "SystemInfo", "Sql", "Sites", "ModuleDefinitions", "Logs", "Jobs", "ModuleCreator" }; diff --git a/Oqtane.Shared/Shared/EntityNames.cs b/Oqtane.Shared/Shared/EntityNames.cs index 1f9e162d..f7030223 100644 --- a/Oqtane.Shared/Shared/EntityNames.cs +++ b/Oqtane.Shared/Shared/EntityNames.cs @@ -16,6 +16,8 @@ namespace Oqtane.Shared public const string Role = "Role"; public const string Setting = "Setting"; public const string Site = "Site"; + public const string SiteGroup = "SiteGroup"; + public const string SiteGroupDefinition = "SiteGroupDefinition"; public const string Tenant = "Tenant"; public const string Theme = "Theme"; public const string UrlMapping = "UrlMapping";