refactoring of site groups
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Policy;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Enums;
|
||||
@@ -27,18 +28,23 @@ namespace Oqtane.Controllers
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET: api/<controller>?siteid=x&groupid=y
|
||||
// GET: api/<controller>?siteid=x
|
||||
[HttpGet]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public IEnumerable<SiteGroup> Get(string siteid, string groupid)
|
||||
[Authorize(Roles = RoleNames.Admin)]
|
||||
public IEnumerable<SiteGroup> Get(string siteid)
|
||||
{
|
||||
if (int.TryParse(siteid, out int SiteId) && int.TryParse(groupid, out int SiteGroupDefinitionId))
|
||||
if (User.IsInRole(RoleNames.Host) || (int.TryParse(siteid, out int SiteId) && SiteId == _alias.SiteId))
|
||||
{
|
||||
return _siteGroupRepository.GetSiteGroups(SiteId, SiteGroupDefinitionId).ToList();
|
||||
var siteGroups = _siteGroupRepository.GetSiteGroups();
|
||||
if (!User.IsInRole(RoleNames.Host))
|
||||
{
|
||||
siteGroups = siteGroups.Where(item => item.PrimarySiteId == _alias.SiteId);
|
||||
}
|
||||
return siteGroups.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Get Attempt for SiteId {SiteId} And SiteGroupDefinitionId {SiteGroupDefinitionId}", siteid, groupid);
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Get Attempt {SiteId}", siteid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
@@ -49,10 +55,10 @@ namespace Oqtane.Controllers
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public SiteGroup Get(int id)
|
||||
{
|
||||
var siteGroup = _siteGroupRepository.GetSiteGroup(id);
|
||||
if (siteGroup != null)
|
||||
var group = _siteGroupRepository.GetSiteGroup(id);
|
||||
if (group != null)
|
||||
{
|
||||
return siteGroup;
|
||||
return group;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -69,13 +75,12 @@ namespace Oqtane.Controllers
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
siteGroup = _siteGroupRepository.AddSiteGroup(siteGroup);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.SiteGroup, siteGroup.SiteGroupDefinitionId, SyncEventActions.Create);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.Site, siteGroup.SiteId, SyncEventActions.Refresh);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Group Added {SiteGroup}", siteGroup);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.SiteGroup, siteGroup.SiteGroupId, SyncEventActions.Create);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Group Added {Group}", siteGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Post Attempt {SiteGroup}", siteGroup);
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Post Attempt {Group}", siteGroup);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
siteGroup = null;
|
||||
}
|
||||
@@ -84,19 +89,24 @@ namespace Oqtane.Controllers
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
[Authorize(Roles = RoleNames.Admin)]
|
||||
public SiteGroup Put(int id, [FromBody] SiteGroup siteGroup)
|
||||
{
|
||||
if (ModelState.IsValid && siteGroup.SiteGroupDefinitionId == id && _siteGroupRepository.GetSiteGroup(siteGroup.SiteGroupDefinitionId, false) != null)
|
||||
if (ModelState.IsValid && siteGroup.SiteGroupId == id)
|
||||
{
|
||||
if (!User.IsInRole(RoleNames.Host) && siteGroup.Synchronize)
|
||||
{
|
||||
// admins can only update the synchronize field
|
||||
siteGroup = _siteGroupRepository.GetSiteGroup(siteGroup.SiteGroupId, false);
|
||||
siteGroup.Synchronize = true;
|
||||
}
|
||||
siteGroup = _siteGroupRepository.UpdateSiteGroup(siteGroup);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.SiteGroup, siteGroup.SiteGroupDefinitionId, SyncEventActions.Update);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.Site, siteGroup.SiteId, SyncEventActions.Refresh);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Site Group Updated {SiteGroup}", siteGroup);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.SiteGroup, siteGroup.SiteGroupId, SyncEventActions.Update);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Site Group Updated {Group}", siteGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Put Attempt {SiteGroup}", siteGroup);
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Put Attempt {Group}", siteGroup);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
siteGroup = null;
|
||||
}
|
||||
@@ -113,12 +123,11 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
_siteGroupRepository.DeleteSiteGroup(id);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.SiteGroup, siteGroup.SiteGroupId, SyncEventActions.Delete);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.Site, siteGroup.SiteId, SyncEventActions.Refresh);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Group Deleted {SiteGroupId}", id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Group Deleted {siteGroupId}", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Delete Attempt {SiteGroupId}", id);
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Delete Attempt {siteGroupId}", id);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Policy;
|
||||
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 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/<controller>?siteid=x
|
||||
[HttpGet]
|
||||
[Authorize(Roles = RoleNames.Admin)]
|
||||
public IEnumerable<SiteGroupDefinition> Get(string siteid)
|
||||
{
|
||||
if (User.IsInRole(RoleNames.Host) || (int.TryParse(siteid, out int SiteId) && SiteId == _alias.SiteId))
|
||||
{
|
||||
var siteGroupDefinitions = _siteGroupDefinitionRepository.GetSiteGroupDefinitions();
|
||||
if (!User.IsInRole(RoleNames.Host))
|
||||
{
|
||||
siteGroupDefinitions = siteGroupDefinitions.Where(item => item.PrimarySiteId == _alias.SiteId);
|
||||
}
|
||||
return siteGroupDefinitions.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Definition Get Attempt {SiteId}", siteid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// GET api/<controller>/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/<controller>
|
||||
[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/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = RoleNames.Admin)]
|
||||
public SiteGroupDefinition Put(int id, [FromBody] SiteGroupDefinition siteGroupDefinition)
|
||||
{
|
||||
if (ModelState.IsValid && siteGroupDefinition.SiteGroupDefinitionId == id)
|
||||
{
|
||||
if (!User.IsInRole(RoleNames.Host) && siteGroupDefinition.Synchronize)
|
||||
{
|
||||
// admins can only update the synchronize field
|
||||
siteGroupDefinition = _siteGroupDefinitionRepository.GetSiteGroupDefinition(siteGroupDefinition.SiteGroupDefinitionId, false);
|
||||
siteGroupDefinition.Synchronize = true;
|
||||
}
|
||||
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/<controller>/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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
126
Oqtane.Server/Controllers/SiteGroupMemberController.cs
Normal file
126
Oqtane.Server/Controllers/SiteGroupMemberController.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
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 SiteGroupMemberController : Controller
|
||||
{
|
||||
private readonly ISiteGroupMemberRepository _siteGroupMemberRepository;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public SiteGroupMemberController(ISiteGroupMemberRepository siteGroupMemberRepository, ISyncManager syncManager, ILogManager logger, ITenantManager tenantManager)
|
||||
{
|
||||
_siteGroupMemberRepository = siteGroupMemberRepository;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET: api/<controller>?siteid=x&groupid=y
|
||||
[HttpGet]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public IEnumerable<SiteGroupMember> Get(string siteid, string groupid)
|
||||
{
|
||||
if (int.TryParse(siteid, out int SiteId) && int.TryParse(groupid, out int SiteGroupId))
|
||||
{
|
||||
return _siteGroupMemberRepository.GetSiteGroupMembers(SiteId, SiteGroupId).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Member Get Attempt for SiteId {SiteId} And SiteGroupId {SiteGroupId}", siteid, groupid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// GET api/<controller>/5
|
||||
[HttpGet("{id}")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public SiteGroupMember Get(int id)
|
||||
{
|
||||
var siteGroupMember = _siteGroupMemberRepository.GetSiteGroupMember(id);
|
||||
if (siteGroupMember != null)
|
||||
{
|
||||
return siteGroupMember;
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public SiteGroupMember Post([FromBody] SiteGroupMember siteGroupMember)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
siteGroupMember = _siteGroupMemberRepository.AddSiteGroupMember(siteGroupMember);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.SiteGroupMember, siteGroupMember.SiteGroupId, SyncEventActions.Create);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.Site, siteGroupMember.SiteId, SyncEventActions.Refresh);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Group Member Added {SiteGroupMember}", siteGroupMember);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Member Post Attempt {SiteGroupMember}", siteGroupMember);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
siteGroupMember = null;
|
||||
}
|
||||
return siteGroupMember;
|
||||
}
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public SiteGroupMember Put(int id, [FromBody] SiteGroupMember siteGroupMember)
|
||||
{
|
||||
if (ModelState.IsValid && siteGroupMember.SiteGroupId == id && _siteGroupMemberRepository.GetSiteGroupMember(siteGroupMember.SiteGroupId, false) != null)
|
||||
{
|
||||
siteGroupMember = _siteGroupMemberRepository.UpdateSiteGroupMember(siteGroupMember);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.SiteGroupMember, siteGroupMember.SiteGroupId, SyncEventActions.Update);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.Site, siteGroupMember.SiteId, SyncEventActions.Refresh);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Site Group Member Updated {SiteGroupMember}", siteGroupMember);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Member Put Attempt {SiteGroupMember}", siteGroupMember);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
siteGroupMember = null;
|
||||
}
|
||||
return siteGroupMember;
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public void Delete(int id)
|
||||
{
|
||||
var siteGroupMember = _siteGroupMemberRepository.GetSiteGroupMember(id);
|
||||
if (siteGroupMember != null)
|
||||
{
|
||||
_siteGroupMemberRepository.DeleteSiteGroupMember(id);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.SiteGroupMember, siteGroupMember.SiteGroupMemberId, SyncEventActions.Delete);
|
||||
_syncManager.AddSyncEvent(_alias, EntityNames.Site, siteGroupMember.SiteId, SyncEventActions.Refresh);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Group Member Deleted {SiteGroupMemberId}", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Site Group Member Delete Attempt {SiteGroupMemberId}", id);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,8 +233,8 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
services.AddScoped<ICookieConsentService, ServerCookieConsentService>();
|
||||
services.AddScoped<ITimeZoneService, TimeZoneService>();
|
||||
services.AddScoped<IMigrationHistoryService, MigrationHistoryService>();
|
||||
services.AddScoped<ISiteGroupDefinitionService, SiteGroupDefinitionService>();
|
||||
services.AddScoped<ISiteGroupService, SiteGroupService>();
|
||||
services.AddScoped<ISiteGroupMemberService, SiteGroupMemberService>();
|
||||
|
||||
// providers
|
||||
services.AddScoped<ITextEditor, Oqtane.Modules.Controls.QuillJSTextEditor>();
|
||||
@@ -284,8 +284,8 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
services.AddTransient<IUrlMappingRepository, UrlMappingRepository>();
|
||||
services.AddTransient<ISearchContentRepository, SearchContentRepository>();
|
||||
services.AddTransient<IMigrationHistoryRepository, MigrationHistoryRepository>();
|
||||
services.AddTransient<ISiteGroupDefinitionRepository, SiteGroupDefinitionRepository>();
|
||||
services.AddTransient<ISiteGroupRepository, SiteGroupRepository>();
|
||||
services.AddTransient<ISiteGroupMemberRepository, SiteGroupMemberRepository>();
|
||||
|
||||
// managers
|
||||
services.AddTransient<IDBContextDependencies, DBContextDependencies>();
|
||||
|
||||
@@ -38,80 +38,76 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
string log = "";
|
||||
|
||||
var siteGroupDefinitionRepository = provider.GetRequiredService<ISiteGroupDefinitionRepository>();
|
||||
var siteGroupRepository = provider.GetRequiredService<ISiteGroupRepository>();
|
||||
var siteGroupMemberRepository = provider.GetRequiredService<ISiteGroupMemberRepository>();
|
||||
var siteRepository = provider.GetRequiredService<ISiteRepository>();
|
||||
var aliasRepository = provider.GetRequiredService<IAliasRepository>();
|
||||
var tenantManager = provider.GetRequiredService<ITenantManager>();
|
||||
var settingRepository = provider.GetRequiredService<ISettingRepository>();
|
||||
|
||||
List<SiteGroup> siteGroups = null;
|
||||
List<SiteGroupMember> siteGroupMembers = null;
|
||||
List<Site> sites = null;
|
||||
List<Alias> aliases = null;
|
||||
|
||||
// get site groups
|
||||
var siteGroupDefinitions = siteGroupDefinitionRepository.GetSiteGroupDefinitions();
|
||||
var siteGroups = siteGroupRepository.GetSiteGroups();
|
||||
|
||||
// iterate through site groups which need to be synchronized
|
||||
foreach (var siteGroupDefinition in siteGroupDefinitions.Where(item => item.Synchronization && item.Synchronize))
|
||||
foreach (var siteGroup in siteGroups.Where(item => item.Type == SiteGroupTypes.Synchronization && item.Synchronize))
|
||||
{
|
||||
// get data
|
||||
if (siteGroups == null)
|
||||
if (siteGroupMembers == null)
|
||||
{
|
||||
siteGroups = siteGroupRepository.GetSiteGroups().ToList();
|
||||
siteGroupMembers = siteGroupMemberRepository.GetSiteGroupMembers().ToList();
|
||||
sites = siteRepository.GetSites().ToList();
|
||||
aliases = aliasRepository.GetAliases().ToList();
|
||||
}
|
||||
|
||||
var aliasName = "https://" + aliases.First(item => item.TenantId == tenantManager.GetTenant().TenantId && item.SiteId == siteGroupDefinition.PrimarySiteId && item.IsDefault).Name;
|
||||
log += $"Processing Primary Site: {sites.First(item => item.SiteId == siteGroupDefinition.PrimarySiteId).Name} - {CreateLink(aliasName)}<br />";
|
||||
var aliasName = "https://" + aliases.First(item => item.TenantId == tenantManager.GetTenant().TenantId && item.SiteId == siteGroup.PrimarySiteId && item.IsDefault).Name;
|
||||
log += $"Processing Primary Site: {sites.First(item => item.SiteId == siteGroup.PrimarySiteId).Name} - {CreateLink(aliasName)}<br />";
|
||||
|
||||
// get primary site
|
||||
var primarySite = sites.FirstOrDefault(item => item.SiteId == siteGroupDefinition.PrimarySiteId);
|
||||
var primarySite = sites.FirstOrDefault(item => item.SiteId == siteGroup.PrimarySiteId);
|
||||
if (primarySite != null)
|
||||
{
|
||||
// update flag to prevent job from processing group again
|
||||
siteGroupDefinition.Synchronize = false;
|
||||
siteGroupDefinitionRepository.UpdateSiteGroupDefinition(siteGroupDefinition);
|
||||
siteGroup.Synchronize = false;
|
||||
siteGroupRepository.UpdateSiteGroup(siteGroup);
|
||||
|
||||
// iterate through sites in site group
|
||||
foreach (var siteGroup in siteGroups.Where(item => item.SiteGroupDefinitionId == siteGroupDefinition.SiteGroupDefinitionId && item.SiteId != siteGroupDefinition.PrimarySiteId))
|
||||
foreach (var siteGroupMember in siteGroupMembers.Where(item => item.SiteGroupId == siteGroup.SiteGroupId && item.SiteId != siteGroup.PrimarySiteId))
|
||||
{
|
||||
// get secondary site
|
||||
var secondarySite = sites.FirstOrDefault(item => item.SiteId == siteGroup.SiteId);
|
||||
var secondarySite = sites.FirstOrDefault(item => item.SiteId == siteGroupMember.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;
|
||||
siteGroupMember.AliasName = "https://" + aliases.First(item => item.TenantId == tenantManager.GetTenant().TenantId && item.SiteId == siteGroupMember.SiteId && item.IsDefault).Name;
|
||||
|
||||
// initialize SynchronizedOn
|
||||
if (siteGroup.SynchronizedOn == null)
|
||||
if (siteGroupMember.SynchronizedOn == null)
|
||||
{
|
||||
siteGroup.SynchronizedOn = DateTime.MinValue;
|
||||
}
|
||||
if (siteGroup.SiteGroupDefinition.Localization)
|
||||
{
|
||||
siteGroup.Synchronize = false; // when using localization, do not overwrite content
|
||||
siteGroupMember.SynchronizedOn = DateTime.MinValue;
|
||||
}
|
||||
|
||||
// replicate site
|
||||
var siteLog = ReplicateSite(provider, tenantManager, settingRepository, siteGroup, primarySite, secondarySite);
|
||||
var siteLog = ReplicateSite(provider, tenantManager, settingRepository, siteGroupMember, primarySite, secondarySite);
|
||||
|
||||
// set synchronized on date/time
|
||||
siteGroup.SynchronizedOn = DateTime.UtcNow;
|
||||
siteGroupRepository.UpdateSiteGroup(siteGroup);
|
||||
siteGroupMember.SynchronizedOn = DateTime.UtcNow;
|
||||
siteGroupMemberRepository.UpdateSiteGroupMember(siteGroupMember);
|
||||
|
||||
log += $"Processed Secondary Site: {secondarySite.Name} - {CreateLink(siteGroup.AliasName)}<br />" + siteLog;
|
||||
log += $"Processed Secondary Site: {secondarySite.Name} - {CreateLink(siteGroupMember.AliasName)}<br />" + siteLog;
|
||||
}
|
||||
else
|
||||
{
|
||||
log += $"Site Group {siteGroupDefinition.Name} Has A SiteId {siteGroup.SiteId} Which Does Not Exist<br />";
|
||||
log += $"Site Group {siteGroup.Name} Has A SiteId {siteGroupMember.SiteId} Which Does Not Exist<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log += $"Site Group {siteGroupDefinition.Name} Has A PrimarySiteId {siteGroupDefinition.PrimarySiteId} Which Does Not Exist<br />";
|
||||
log += $"Site Group {siteGroup.Name} Has A PrimarySiteId {siteGroup.PrimarySiteId} Which Does Not Exist<br />";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,21 +119,21 @@ namespace Oqtane.Infrastructure
|
||||
return log;
|
||||
}
|
||||
|
||||
private string ReplicateSite(IServiceProvider provider, ITenantManager tenantManager, ISettingRepository settingRepository, SiteGroup siteGroup, Site primarySite, Site secondarySite)
|
||||
private string ReplicateSite(IServiceProvider provider, ITenantManager tenantManager, ISettingRepository settingRepository, SiteGroupMember siteGroupMember, Site primarySite, Site secondarySite)
|
||||
{
|
||||
var log = "";
|
||||
|
||||
// replicate roles/users
|
||||
log += ReplicateRoles(provider, settingRepository, siteGroup, primarySite.SiteId, secondarySite.SiteId);
|
||||
log += ReplicateRoles(provider, settingRepository, siteGroupMember, primarySite.SiteId, secondarySite.SiteId);
|
||||
|
||||
// replicate folders/files
|
||||
log += ReplicateFolders(provider, settingRepository, siteGroup, primarySite.SiteId, secondarySite.SiteId);
|
||||
log += ReplicateFolders(provider, settingRepository, siteGroupMember, primarySite.SiteId, secondarySite.SiteId);
|
||||
|
||||
// replicate pages/modules
|
||||
log += ReplicatePages(provider, settingRepository, tenantManager, siteGroup, primarySite.SiteId, secondarySite.SiteId);
|
||||
log += ReplicatePages(provider, settingRepository, tenantManager, siteGroupMember, primarySite.SiteId, secondarySite.SiteId);
|
||||
|
||||
// replicate site
|
||||
if (primarySite.ModifiedOn > siteGroup.SynchronizedOn)
|
||||
if (primarySite.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
{
|
||||
secondarySite.TimeZoneId = primarySite.TimeZoneId;
|
||||
secondarySite.CultureCode = primarySite.CultureCode;
|
||||
@@ -182,17 +178,14 @@ namespace Oqtane.Infrastructure
|
||||
secondarySite.DeletedOn = primarySite.DeletedOn;
|
||||
|
||||
var siteRepository = provider.GetRequiredService<ISiteRepository>();
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
siteRepository.UpdateSite(secondarySite);
|
||||
}
|
||||
log += Log(siteGroup, $"Site Updated: {secondarySite.Name}");
|
||||
siteRepository.UpdateSite(secondarySite);
|
||||
log += Log(siteGroupMember, $"Site Updated: {secondarySite.Name}");
|
||||
}
|
||||
|
||||
// site settings
|
||||
log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Site, primarySite.SiteId, secondarySite.SiteId);
|
||||
log += ReplicateSettings(settingRepository, siteGroupMember, EntityNames.Site, primarySite.SiteId, secondarySite.SiteId);
|
||||
|
||||
if (siteGroup.SynchronizedOn == DateTime.MinValue || !string.IsNullOrEmpty(log))
|
||||
if (siteGroupMember.SynchronizedOn == DateTime.MinValue || !string.IsNullOrEmpty(log))
|
||||
{
|
||||
// clear cache for secondary site if any content was replicated
|
||||
var syncManager = provider.GetRequiredService<ISyncManager>();
|
||||
@@ -200,7 +193,7 @@ namespace Oqtane.Infrastructure
|
||||
syncManager.AddSyncEvent(alias, EntityNames.Site, secondarySite.SiteId, SyncEventActions.Refresh);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(log) && siteGroup.Notify)
|
||||
if (!string.IsNullOrEmpty(log) && siteGroupMember.Notify)
|
||||
{
|
||||
// send change log to administrators
|
||||
SendNotifications(provider, secondarySite.SiteId, secondarySite.Name, log);
|
||||
@@ -220,7 +213,7 @@ namespace Oqtane.Infrastructure
|
||||
return fileId;
|
||||
}
|
||||
|
||||
private string ReplicateRoles(IServiceProvider provider, ISettingRepository settingRepository, SiteGroup siteGroup, int primarySiteId, int secondarySiteId)
|
||||
private string ReplicateRoles(IServiceProvider provider, ISettingRepository settingRepository, SiteGroupMember siteGroupMember, int primarySiteId, int secondarySiteId)
|
||||
{
|
||||
// get roles
|
||||
var roleRepository = provider.GetRequiredService<IRoleRepository>();
|
||||
@@ -239,7 +232,7 @@ namespace Oqtane.Infrastructure
|
||||
secondaryRole.SiteId = secondarySiteId;
|
||||
}
|
||||
|
||||
if (role == null || primaryRole.ModifiedOn > siteGroup.SynchronizedOn)
|
||||
if (role == null || primaryRole.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
{
|
||||
// set all properties
|
||||
secondaryRole.Name = primaryRole.Name;
|
||||
@@ -249,19 +242,13 @@ namespace Oqtane.Infrastructure
|
||||
|
||||
if (role == null)
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
roleRepository.AddRole(secondaryRole);
|
||||
}
|
||||
log += Log(siteGroup, $"Role Added: {secondaryRole.Name}");
|
||||
roleRepository.AddRole(secondaryRole);
|
||||
log += Log(siteGroupMember, $"Role Added: {secondaryRole.Name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
roleRepository.UpdateRole(secondaryRole);
|
||||
}
|
||||
log += Log(siteGroup, $"Role Updated: {secondaryRole.Name}");
|
||||
roleRepository.UpdateRole(secondaryRole);
|
||||
log += Log(siteGroupMember, $"Role Updated: {secondaryRole.Name}");
|
||||
secondaryRoles.Remove(role);
|
||||
}
|
||||
}
|
||||
@@ -270,20 +257,17 @@ namespace Oqtane.Infrastructure
|
||||
// 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}");
|
||||
roleRepository.DeleteRole(secondaryRole.RoleId);
|
||||
log += Log(siteGroupMember, $"Role Deleted: {secondaryRole.Name}");
|
||||
}
|
||||
|
||||
// settings
|
||||
log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Role, primarySiteId, secondarySiteId);
|
||||
log += ReplicateSettings(settingRepository, siteGroupMember, EntityNames.Role, primarySiteId, secondarySiteId);
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
private string ReplicateFolders(IServiceProvider provider, ISettingRepository settingRepository, SiteGroup siteGroup, int primarySiteId, int secondarySiteId)
|
||||
private string ReplicateFolders(IServiceProvider provider, ISettingRepository settingRepository, SiteGroupMember siteGroupMember, int primarySiteId, int secondarySiteId)
|
||||
{
|
||||
var folderRepository = provider.GetRequiredService<IFolderRepository>();
|
||||
var fileRepository = provider.GetRequiredService<IFileRepository>();
|
||||
@@ -305,7 +289,7 @@ namespace Oqtane.Infrastructure
|
||||
secondaryFolder.SiteId = secondarySiteId;
|
||||
}
|
||||
|
||||
if (folder == null || primaryFolder.ModifiedOn > siteGroup.SynchronizedOn)
|
||||
if (folder == null || primaryFolder.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
{
|
||||
// set all properties
|
||||
secondaryFolder.ParentId = null;
|
||||
@@ -328,25 +312,19 @@ namespace Oqtane.Infrastructure
|
||||
|
||||
if (folder == null)
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
folderRepository.AddFolder(secondaryFolder);
|
||||
}
|
||||
log += Log(siteGroup, $"Folder Added: {secondaryFolder.Path}");
|
||||
folderRepository.AddFolder(secondaryFolder);
|
||||
log += Log(siteGroupMember, $"Folder Added: {secondaryFolder.Path}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
folderRepository.UpdateFolder(secondaryFolder);
|
||||
}
|
||||
log += Log(siteGroup, $"Folder Updated: {secondaryFolder.Path}");
|
||||
folderRepository.UpdateFolder(secondaryFolder);
|
||||
log += Log(siteGroupMember, $"Folder Updated: {secondaryFolder.Path}");
|
||||
secondaryFolders.Remove(folder);
|
||||
}
|
||||
}
|
||||
|
||||
// folder settings
|
||||
log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Folder, primaryFolder.FolderId, secondaryFolder.FolderId);
|
||||
log += ReplicateSettings(settingRepository, siteGroupMember, EntityNames.Folder, primaryFolder.FolderId, secondaryFolder.FolderId);
|
||||
|
||||
// get files for folder
|
||||
var primaryFiles = fileRepository.GetFiles(primaryFolder.FolderId);
|
||||
@@ -364,7 +342,7 @@ namespace Oqtane.Infrastructure
|
||||
secondaryFile.Name = primaryFile.Name;
|
||||
}
|
||||
|
||||
if (file == null || primaryFile.ModifiedOn > siteGroup.SynchronizedOn)
|
||||
if (file == null || primaryFile.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
{
|
||||
// set all properties
|
||||
secondaryFile.Extension = primaryFile.Extension;
|
||||
@@ -375,21 +353,15 @@ namespace Oqtane.Infrastructure
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
fileRepository.AddFile(secondaryFile);
|
||||
ReplicateFile(folderRepository, primaryFolder, primaryFile, secondaryFolder, secondaryFile);
|
||||
}
|
||||
log += Log(siteGroup, $"File Added: {CreateLink(siteGroup.AliasName + secondaryFolder.Path + secondaryFile.Name)}");
|
||||
fileRepository.AddFile(secondaryFile);
|
||||
ReplicateFile(folderRepository, primaryFolder, primaryFile, secondaryFolder, secondaryFile);
|
||||
log += Log(siteGroupMember, $"File Added: {CreateLink(siteGroupMember.AliasName + secondaryFolder.Path + secondaryFile.Name)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
fileRepository.UpdateFile(secondaryFile);
|
||||
ReplicateFile(folderRepository, primaryFolder, primaryFile, secondaryFolder, secondaryFile);
|
||||
}
|
||||
log += Log(siteGroup, $"File Updated: {CreateLink(siteGroup.AliasName + secondaryFolder.Path + secondaryFile.Name)}");
|
||||
fileRepository.UpdateFile(secondaryFile);
|
||||
ReplicateFile(folderRepository, primaryFolder, primaryFile, secondaryFolder, secondaryFile);
|
||||
log += Log(siteGroupMember, $"File Updated: {CreateLink(siteGroupMember.AliasName + secondaryFolder.Path + secondaryFile.Name)}");
|
||||
secondaryFiles.Remove(file);
|
||||
}
|
||||
}
|
||||
@@ -398,24 +370,18 @@ namespace Oqtane.Infrastructure
|
||||
// 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: {CreateLink(siteGroup.AliasName + secondaryFolder.Path + secondaryFile.Name)}");
|
||||
fileRepository.DeleteFile(secondaryFile.FileId);
|
||||
var secondaryPath = Path.Combine(folderRepository.GetFolderPath(secondaryFolder), secondaryFile.Name);
|
||||
System.IO.File.Delete(secondaryPath);
|
||||
log += Log(siteGroupMember, $"File Deleted: {CreateLink(siteGroupMember.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}");
|
||||
folderRepository.DeleteFolder(secondaryFolder.FolderId);
|
||||
log += Log(siteGroupMember, $"Folder Deleted: {secondaryFolder.Path}");
|
||||
}
|
||||
|
||||
return log;
|
||||
@@ -435,7 +401,7 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
}
|
||||
|
||||
private string ReplicatePages(IServiceProvider provider, ISettingRepository settingRepository, ITenantManager tenantManager, SiteGroup siteGroup, int primarySiteId, int secondarySiteId)
|
||||
private string ReplicatePages(IServiceProvider provider, ISettingRepository settingRepository, ITenantManager tenantManager, SiteGroupMember siteGroupMember, int primarySiteId, int secondarySiteId)
|
||||
{
|
||||
var pageRepository = provider.GetRequiredService<IPageRepository>();
|
||||
var pageModuleRepository = provider.GetRequiredService<IPageModuleRepository>();
|
||||
@@ -463,7 +429,7 @@ namespace Oqtane.Infrastructure
|
||||
secondaryPage.SiteId = secondarySiteId;
|
||||
}
|
||||
|
||||
if (page == null || primaryPage.ModifiedOn > siteGroup.SynchronizedOn)
|
||||
if (page == null || primaryPage.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
{
|
||||
// set all properties
|
||||
secondaryPage.Path = primaryPage.Path;
|
||||
@@ -502,25 +468,19 @@ namespace Oqtane.Infrastructure
|
||||
|
||||
if (page == null)
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
secondaryPage = pageRepository.AddPage(secondaryPage);
|
||||
}
|
||||
log += Log(siteGroup, $"Page Added: {CreateLink(siteGroup.AliasName + secondaryPage.Path)}");
|
||||
secondaryPage = pageRepository.AddPage(secondaryPage);
|
||||
log += Log(siteGroupMember, $"Page Added: {CreateLink(siteGroupMember.AliasName + secondaryPage.Path)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
secondaryPage = pageRepository.UpdatePage(secondaryPage);
|
||||
}
|
||||
log += Log(siteGroup, $"Page Updated: {CreateLink(siteGroup.AliasName + secondaryPage.Path)}");
|
||||
secondaryPage = pageRepository.UpdatePage(secondaryPage);
|
||||
log += Log(siteGroupMember, $"Page Updated: {CreateLink(siteGroupMember.AliasName + secondaryPage.Path)}");
|
||||
secondaryPages.Remove(page);
|
||||
}
|
||||
}
|
||||
|
||||
// page settings
|
||||
log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Page, primaryPage.PageId, secondaryPage.PageId);
|
||||
log += ReplicateSettings(settingRepository, siteGroupMember, EntityNames.Page, primaryPage.PageId, secondaryPage.PageId);
|
||||
|
||||
// modules
|
||||
if (primaryPageModules == null)
|
||||
@@ -547,7 +507,7 @@ namespace Oqtane.Infrastructure
|
||||
secondaryPageModule.Module.ModuleDefinitionName = primaryPageModule.Module.ModuleDefinitionName;
|
||||
}
|
||||
|
||||
if (pageModule == null || primaryPageModule.ModifiedOn > siteGroup.SynchronizedOn || primaryPageModule.Module.ModifiedOn > siteGroup.SynchronizedOn)
|
||||
if (pageModule == null || primaryPageModule.ModifiedOn > siteGroupMember.SynchronizedOn || primaryPageModule.Module.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
{
|
||||
// set all properties
|
||||
secondaryPageModule.Title = primaryPageModule.Title;
|
||||
@@ -570,44 +530,32 @@ namespace Oqtane.Infrastructure
|
||||
if (module == null)
|
||||
{
|
||||
// add new module
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
module = moduleRepository.AddModule(secondaryPageModule.Module);
|
||||
updateContent = true;
|
||||
}
|
||||
log += Log(siteGroup, $"Module Added: {module.Title} - {CreateLink(siteGroup.AliasName + secondaryPage.Path)}");
|
||||
module = moduleRepository.AddModule(secondaryPageModule.Module);
|
||||
updateContent = true;
|
||||
log += Log(siteGroupMember, $"Module Added: {module.Title} - {CreateLink(siteGroupMember.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, $"Module Instance Added: {module.Title} - {CreateLink(siteGroup.AliasName + secondaryPage.Path)}");
|
||||
secondaryPageModule = pageModuleRepository.AddPageModule(secondaryPageModule);
|
||||
log += Log(siteGroupMember, $"Module Instance Added: {module.Title} - {CreateLink(siteGroupMember.AliasName + secondaryPage.Path)}");
|
||||
secondaryPageModule.Module = module;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// update existing module
|
||||
if (primaryPageModule.Module.ModifiedOn > siteGroup.SynchronizedOn)
|
||||
if (primaryPageModule.Module.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
moduleRepository.UpdateModule(secondaryPageModule.Module);
|
||||
updateContent = true;
|
||||
}
|
||||
log += Log(siteGroup, $"Module Updated: {secondaryPageModule.Title} - {CreateLink(siteGroup.AliasName + secondaryPage.Path)}");
|
||||
moduleRepository.UpdateModule(secondaryPageModule.Module);
|
||||
updateContent = true;
|
||||
log += Log(siteGroupMember, $"Module Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + secondaryPage.Path)}");
|
||||
}
|
||||
if (primaryPageModule.ModifiedOn > siteGroup.SynchronizedOn)
|
||||
if (primaryPageModule.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
{
|
||||
if (siteGroup.Synchronize)
|
||||
{
|
||||
secondaryPageModule = pageModuleRepository.UpdatePageModule(secondaryPageModule);
|
||||
}
|
||||
log += Log(siteGroup, $"Module Instance Updated: {secondaryPageModule.Title} - {CreateLink(siteGroup.AliasName + secondaryPage.Path)}");
|
||||
secondaryPageModule = pageModuleRepository.UpdatePageModule(secondaryPageModule);
|
||||
log += Log(siteGroupMember, $"Module Instance Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + secondaryPage.Path)}");
|
||||
secondaryPageModules.Remove(pageModule);
|
||||
}
|
||||
}
|
||||
@@ -625,11 +573,8 @@ namespace Oqtane.Infrastructure
|
||||
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} - {CreateLink(siteGroup.AliasName + secondaryPage.Path)}");
|
||||
((ISynchronizable)moduleObject).LoadModule(secondaryPageModule.Module, primaryModuleContent, primaryPageModule.Module.ModuleDefinition.Version);
|
||||
log += Log(siteGroupMember, $"Module Content Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + secondaryPage.Path)}");
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -641,7 +586,7 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
|
||||
// module settings
|
||||
log += ReplicateSettings(settingRepository, siteGroup, EntityNames.Module, primaryPageModule.ModuleId, secondaryPageModule.ModuleId);
|
||||
log += ReplicateSettings(settingRepository, siteGroupMember, EntityNames.Module, primaryPageModule.ModuleId, secondaryPageModule.ModuleId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,25 +605,19 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
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, $"Module Instance Deleted: {secondaryPageModule.Title} - {CreateLink(siteGroup.AliasName + secondaryPageModule.Page.Path)}");
|
||||
pageModuleRepository.DeletePageModule(secondaryPageModule.PageModuleId);
|
||||
log += Log(siteGroupMember, $"Module Instance Deleted: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.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: {CreateLink(siteGroup.AliasName + secondaryPage.Path)}");
|
||||
pageRepository.DeletePage(secondaryPage.PageId);
|
||||
log += Log(siteGroupMember, $"Page Deleted: {CreateLink(siteGroupMember.AliasName + secondaryPage.Path)}");
|
||||
}
|
||||
|
||||
if (siteGroup.SynchronizedOn == DateTime.MinValue || !string.IsNullOrEmpty(log))
|
||||
if (siteGroupMember.SynchronizedOn == DateTime.MinValue || !string.IsNullOrEmpty(log))
|
||||
{
|
||||
// clear cache for secondary site if any content was replicated
|
||||
var syncManager = provider.GetRequiredService<ISyncManager>();
|
||||
@@ -705,7 +644,7 @@ namespace Oqtane.Infrastructure
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private string ReplicateSettings(ISettingRepository settingRepository, SiteGroup siteGroup, string entityName, int primaryEntityId, int secondaryEntityId)
|
||||
private string ReplicateSettings(ISettingRepository settingRepository, SiteGroupMember siteGroupMember, string entityName, int primaryEntityId, int secondaryEntityId)
|
||||
{
|
||||
var log = "";
|
||||
var updated = false;
|
||||
@@ -722,7 +661,7 @@ namespace Oqtane.Infrastructure
|
||||
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))
|
||||
if (!excludedSettings.Any(item => item.EntityName == secondarySetting.EntityName && item.SettingName == secondarySetting.SettingName))
|
||||
{
|
||||
settingRepository.AddSetting(secondarySetting);
|
||||
updated = true;
|
||||
@@ -734,7 +673,7 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
secondarySetting.SettingValue = primarySetting.SettingValue;
|
||||
secondarySetting.IsPrivate = primarySetting.IsPrivate;
|
||||
if (siteGroup.Synchronize && !excludedSettings.Any(item => item.EntityName == secondarySetting.EntityName && item.SettingName == secondarySetting.SettingName))
|
||||
if (!excludedSettings.Any(item => item.EntityName == secondarySetting.EntityName && item.SettingName == secondarySetting.SettingName))
|
||||
{
|
||||
settingRepository.UpdateSetting(secondarySetting);
|
||||
updated = true;
|
||||
@@ -747,7 +686,7 @@ namespace Oqtane.Infrastructure
|
||||
// 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))
|
||||
if (!excludedSettings.Any(item => item.EntityName == secondarySetting.EntityName && item.SettingName == secondarySetting.SettingName))
|
||||
{
|
||||
settingRepository.DeleteSetting(secondarySetting.EntityName, secondarySetting.SettingId);
|
||||
updated = true;
|
||||
@@ -756,7 +695,7 @@ namespace Oqtane.Infrastructure
|
||||
|
||||
if (updated)
|
||||
{
|
||||
log += Log(siteGroup, $"{entityName} Settings Updated");
|
||||
log += Log(siteGroupMember, $"{entityName} Settings Updated");
|
||||
}
|
||||
|
||||
return log;
|
||||
@@ -774,10 +713,10 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
}
|
||||
|
||||
private string Log(SiteGroup siteGroup, string content)
|
||||
private string Log(SiteGroupMember siteGroupMember, string content)
|
||||
{
|
||||
// not necessary to log initial replication
|
||||
if (siteGroup.SynchronizedOn != DateTime.MinValue)
|
||||
if (siteGroupMember.SynchronizedOn != DateTime.MinValue)
|
||||
{
|
||||
return content + "<br />";
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
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<SiteGroupDefinitionEntityBuilder>
|
||||
{
|
||||
private const string _entityTableName = "SiteGroupDefinition";
|
||||
private readonly PrimaryKey<SiteGroupDefinitionEntityBuilder> _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<AddColumnOperation> SiteGroupDefinitionId { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> Name { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> PrimarySiteId { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> Synchronization { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> Synchronize { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> Localization { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -12,25 +12,20 @@ namespace Oqtane.Migrations.EntityBuilders
|
||||
{
|
||||
private const string _entityTableName = "SiteGroup";
|
||||
private readonly PrimaryKey<SiteGroupEntityBuilder> _primaryKey = new("PK_SiteGroup", x => x.SiteGroupId);
|
||||
private readonly ForeignKey<SiteGroupEntityBuilder> _groupForeignKey = new("FK_SiteGroup_SiteGroupDefinition", x => x.SiteGroupDefinitionId, "SiteGroupDefinition", "SiteGroupDefinitionId", ReferentialAction.Cascade);
|
||||
private readonly ForeignKey<SiteGroupEntityBuilder> _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");
|
||||
Name = AddStringColumn(table, "Name", 200);
|
||||
Type = AddStringColumn(table, "Type", 50);
|
||||
PrimarySiteId = AddIntegerColumn(table, "PrimarySiteId");
|
||||
Synchronize = AddBooleanColumn(table, "Synchronize");
|
||||
Notify = AddBooleanColumn(table, "Notify");
|
||||
SynchronizedOn = AddDateTimeColumn(table, "SynchronizedOn", true);
|
||||
|
||||
AddAuditableColumns(table);
|
||||
|
||||
@@ -39,14 +34,12 @@ namespace Oqtane.Migrations.EntityBuilders
|
||||
|
||||
public OperationBuilder<AddColumnOperation> SiteGroupId { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> SiteGroupDefinitionId { get; set; }
|
||||
public OperationBuilder<AddColumnOperation> Name { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> SiteId { get; set; }
|
||||
public OperationBuilder<AddColumnOperation> Type { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> PrimarySiteId { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> Synchronize { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> Notify { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> SynchronizedOn { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
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 SiteGroupMemberEntityBuilder : AuditableBaseEntityBuilder<SiteGroupMemberEntityBuilder>
|
||||
{
|
||||
private const string _entityTableName = "SiteGroupMember";
|
||||
private readonly PrimaryKey<SiteGroupMemberEntityBuilder> _primaryKey = new("PK_SiteGroupMember", x => x.SiteGroupMemberId);
|
||||
private readonly ForeignKey<SiteGroupMemberEntityBuilder> _groupForeignKey = new("FK_SiteGroupMember_SiteGroup", x => x.SiteGroupId, "SiteGroup", "SiteGroupId", ReferentialAction.Cascade);
|
||||
private readonly ForeignKey<SiteGroupMemberEntityBuilder> _siteForeignKey = new("FK_SiteGroupMember_Site", x => x.SiteId, "Site", "SiteId", ReferentialAction.Cascade);
|
||||
|
||||
public SiteGroupMemberEntityBuilder(MigrationBuilder migrationBuilder, IDatabase database) : base(migrationBuilder, database)
|
||||
{
|
||||
EntityTableName = _entityTableName;
|
||||
PrimaryKey = _primaryKey;
|
||||
ForeignKeys.Add(_groupForeignKey);
|
||||
ForeignKeys.Add(_siteForeignKey);
|
||||
}
|
||||
|
||||
protected override SiteGroupMemberEntityBuilder BuildTable(ColumnsBuilder table)
|
||||
{
|
||||
SiteGroupMemberId = AddAutoIncrementColumn(table, "SiteGroupMemberId");
|
||||
SiteGroupId = AddIntegerColumn(table, "SiteGroupId");
|
||||
SiteId = AddIntegerColumn(table, "SiteId");
|
||||
Notify = AddBooleanColumn(table, "Notify");
|
||||
SynchronizedOn = AddDateTimeColumn(table, "SynchronizedOn", true);
|
||||
|
||||
AddAuditableColumns(table);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public OperationBuilder<AddColumnOperation> SiteGroupMemberId { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> SiteGroupId { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> SiteId { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> Notify { get; set; }
|
||||
|
||||
public OperationBuilder<AddColumnOperation> SynchronizedOn { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,12 @@ namespace Oqtane.Migrations.Tenant
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var siteGroupDefinitionEntityBuilder = new SiteGroupDefinitionEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
siteGroupDefinitionEntityBuilder.Create();
|
||||
|
||||
var siteGroupEntityBuilder = new SiteGroupEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
siteGroupEntityBuilder.Create();
|
||||
siteGroupEntityBuilder.AddIndex("IX_SiteGroup", new[] { "SiteId", "SiteGroupDefinitionId" }, true);
|
||||
|
||||
var siteGroupMemberEntityBuilder = new SiteGroupMemberEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
siteGroupMemberEntityBuilder.Create();
|
||||
siteGroupMemberEntityBuilder.AddIndex("IX_SiteGroupMember", new[] { "SiteId", "SiteGroupId" }, true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace Oqtane.Repository
|
||||
public virtual DbSet<SearchContentWord> SearchContentWord { get; set; }
|
||||
public virtual DbSet<SearchWord> SearchWord { get; set; }
|
||||
public virtual DbSet<MigrationHistory> MigrationHistory { get; set; }
|
||||
public virtual DbSet<SiteGroupDefinition> SiteGroupDefinition { get; set; }
|
||||
public virtual DbSet<SiteGroup> SiteGroup { get; set; }
|
||||
public virtual DbSet<SiteGroupMember> SiteGroupMember { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
public interface ISiteGroupDefinitionRepository
|
||||
{
|
||||
IEnumerable<SiteGroupDefinition> 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<TenantDBContext> _dbContextFactory;
|
||||
|
||||
public SiteGroupDefinitionRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
}
|
||||
|
||||
public IEnumerable<SiteGroupDefinition> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
88
Oqtane.Server/Repository/SiteGroupMemberRepository.cs
Normal file
88
Oqtane.Server/Repository/SiteGroupMemberRepository.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
public interface ISiteGroupMemberRepository
|
||||
{
|
||||
IEnumerable<SiteGroupMember> GetSiteGroupMembers();
|
||||
IEnumerable<SiteGroupMember> GetSiteGroupMembers(int siteId, int siteGroupId);
|
||||
SiteGroupMember AddSiteGroupMember(SiteGroupMember siteGroupMember);
|
||||
SiteGroupMember UpdateSiteGroupMember(SiteGroupMember siteGroupMember);
|
||||
SiteGroupMember GetSiteGroupMember(int siteGroupMemberId);
|
||||
SiteGroupMember GetSiteGroupMember(int siteGroupMemberId, bool tracking);
|
||||
void DeleteSiteGroupMember(int siteGroupMemberId);
|
||||
}
|
||||
|
||||
public class SiteGroupMemberRepository : ISiteGroupMemberRepository
|
||||
{
|
||||
private readonly IDbContextFactory<TenantDBContext> _dbContextFactory;
|
||||
|
||||
public SiteGroupMemberRepository(IDbContextFactory<TenantDBContext> dbContextFactory)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
}
|
||||
|
||||
public IEnumerable<SiteGroupMember> GetSiteGroupMembers()
|
||||
{
|
||||
return GetSiteGroupMembers(-1, -1);
|
||||
}
|
||||
|
||||
public IEnumerable<SiteGroupMember> GetSiteGroupMembers(int siteId, int siteGroupId)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
return db.SiteGroupMember
|
||||
.Where(item => (siteId == -1 || item.SiteId == siteId) && (siteGroupId == -1 || item.SiteGroupId == siteGroupId))
|
||||
.Include(item => item.SiteGroup) // eager load
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public SiteGroupMember AddSiteGroupMember(SiteGroupMember siteGroupMember)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
db.SiteGroupMember.Add(siteGroupMember);
|
||||
db.SaveChanges();
|
||||
return siteGroupMember;
|
||||
}
|
||||
|
||||
public SiteGroupMember UpdateSiteGroupMember(SiteGroupMember siteGroupMember)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
db.Entry(siteGroupMember).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return siteGroupMember;
|
||||
}
|
||||
|
||||
public SiteGroupMember GetSiteGroupMember(int siteGroupMemberId)
|
||||
{
|
||||
return GetSiteGroupMember(siteGroupMemberId, true);
|
||||
}
|
||||
|
||||
public SiteGroupMember GetSiteGroupMember(int siteGroupMemberId, bool tracking)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
if (tracking)
|
||||
{
|
||||
return db.SiteGroupMember
|
||||
.Include(item => item.SiteGroup) // eager load
|
||||
.FirstOrDefault(item => item.SiteGroupMemberId == siteGroupMemberId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return db.SiteGroupMember.AsNoTracking()
|
||||
.Include(item => item.SiteGroup) // eager load
|
||||
.FirstOrDefault(item => item.SiteGroupMemberId == siteGroupMemberId);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteSiteGroupMember(int siteGroupMemberId)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
SiteGroupMember SiteGroupMember = db.SiteGroupMember.Find(siteGroupMemberId);
|
||||
db.SiteGroupMember.Remove(SiteGroupMember);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,11 @@ namespace Oqtane.Repository
|
||||
public interface ISiteGroupRepository
|
||||
{
|
||||
IEnumerable<SiteGroup> GetSiteGroups();
|
||||
IEnumerable<SiteGroup> GetSiteGroups(int siteId, int siteGroupDefinitionId);
|
||||
SiteGroup AddSiteGroup(SiteGroup siteGroup);
|
||||
SiteGroup UpdateSiteGroup(SiteGroup siteGroup);
|
||||
SiteGroup GetSiteGroup(int siteSiteGroupId);
|
||||
SiteGroup GetSiteGroup(int siteSiteGroupId, bool tracking);
|
||||
void DeleteSiteGroup(int siteSiteGroupId);
|
||||
SiteGroup GetSiteGroup(int siteGroupId);
|
||||
SiteGroup GetSiteGroup(int siteGroupId, bool tracking);
|
||||
void DeleteSiteGroup(int siteGroupId);
|
||||
}
|
||||
|
||||
public class SiteGroupRepository : ISiteGroupRepository
|
||||
@@ -24,64 +23,52 @@ namespace Oqtane.Repository
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<SiteGroup> GetSiteGroups()
|
||||
{
|
||||
return GetSiteGroups(-1, -1);
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
return db.SiteGroup.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<SiteGroup> GetSiteGroups(int siteId, int siteGroupDefinitionId)
|
||||
public SiteGroup AddSiteGroup(SiteGroup siteGroup)
|
||||
{
|
||||
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.SiteGroup.Add(siteGroup);
|
||||
db.SaveChanges();
|
||||
return SiteGroup;
|
||||
return siteGroup;
|
||||
}
|
||||
|
||||
public SiteGroup UpdateSiteGroup(SiteGroup SiteGroup)
|
||||
public SiteGroup UpdateSiteGroup(SiteGroup siteGroup)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
db.Entry(SiteGroup).State = EntityState.Modified;
|
||||
db.Entry(siteGroup).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return SiteGroup;
|
||||
return siteGroup;
|
||||
}
|
||||
|
||||
public SiteGroup GetSiteGroup(int SiteGroupId)
|
||||
public SiteGroup GetSiteGroup(int siteGroupId)
|
||||
{
|
||||
return GetSiteGroup(SiteGroupId, true);
|
||||
return GetSiteGroup(siteGroupId, true);
|
||||
}
|
||||
|
||||
public SiteGroup GetSiteGroup(int SiteGroupId, bool tracking)
|
||||
public SiteGroup GetSiteGroup(int siteGroupId, bool tracking)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
if (tracking)
|
||||
{
|
||||
return db.SiteGroup
|
||||
.Include(item => item.SiteGroupDefinition) // eager load
|
||||
.FirstOrDefault(item => item.SiteGroupId == SiteGroupId);
|
||||
return db.SiteGroup.FirstOrDefault(item => item.SiteGroupId == siteGroupId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return db.SiteGroup.AsNoTracking()
|
||||
.Include(item => item.SiteGroupDefinition) // eager load
|
||||
.FirstOrDefault(item => item.SiteGroupId == SiteGroupId);
|
||||
return db.SiteGroup.AsNoTracking().FirstOrDefault(item => item.SiteGroupId == siteGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteSiteGroup(int SiteGroupId)
|
||||
public void DeleteSiteGroup(int siteGroupId)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
SiteGroup SiteGroup = db.SiteGroup.Find(SiteGroupId);
|
||||
db.SiteGroup.Remove(SiteGroup);
|
||||
SiteGroup group = db.SiteGroup.Find(siteGroupId);
|
||||
db.SiteGroup.Remove(group);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Oqtane.Services
|
||||
public class ServerSiteService : ISiteService
|
||||
{
|
||||
private readonly ISiteRepository _sites;
|
||||
private readonly ISiteGroupRepository _siteGroups;
|
||||
private readonly ISiteGroupMemberRepository _siteGroupMembers;
|
||||
private readonly IAliasRepository _aliases;
|
||||
private readonly IPageRepository _pages;
|
||||
private readonly IThemeRepository _themes;
|
||||
@@ -39,10 +39,10 @@ namespace Oqtane.Services
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly string _private = "[PRIVATE]";
|
||||
|
||||
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)
|
||||
public ServerSiteService(ISiteRepository sites, ISiteGroupMemberRepository siteGroupMembers, 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;
|
||||
_siteGroupMembers = siteGroupMembers;
|
||||
_aliases = aliases;
|
||||
_pages = pages;
|
||||
_themes = themes;
|
||||
@@ -315,23 +315,23 @@ namespace Oqtane.Services
|
||||
{
|
||||
var languages = new List<Language>();
|
||||
|
||||
var siteGroups = _siteGroups.GetSiteGroups();
|
||||
if (siteGroups.Any(item => item.SiteId == siteId && item.SiteGroupDefinition.Localization))
|
||||
var siteGroupMembers = _siteGroupMembers.GetSiteGroupMembers();
|
||||
if (siteGroupMembers.Any(item => item.SiteId == siteId && item.SiteGroup.Type == SiteGroupTypes.Localization))
|
||||
{
|
||||
// site is part of a localized site group - get all languages from the site group
|
||||
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 siteGroupId in siteGroupMembers.Where(item => item.SiteId == siteId && item.SiteGroup.Type == SiteGroupTypes.Localization).Select(item => item.SiteGroupId).Distinct().ToList())
|
||||
{
|
||||
foreach (var siteGroup in siteGroups.Where(item => item.SiteGroupDefinitionId == siteGroupDefinitionId))
|
||||
foreach (var siteGroupMember in siteGroupMembers.Where(item => item.SiteGroupId == siteGroupId))
|
||||
{
|
||||
var site = sites.FirstOrDefault(item => item.SiteId == siteGroup.SiteId);
|
||||
var site = sites.FirstOrDefault(item => item.SiteId == siteGroupMember.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);
|
||||
var alias = aliases.FirstOrDefault(item => item.SiteId == siteGroupMember.SiteId && item.TenantId == tenantId && item.IsDefault);
|
||||
if (alias != null)
|
||||
{
|
||||
languages.Add(new Language { Code = site.CultureCode, Name = "", AliasName = alias.Name, IsDefault = false });
|
||||
|
||||
Reference in New Issue
Block a user