Merge pull request #228 from sbwalker/master
resolved a number of issues with site creation #224
This commit is contained in:
commit
43e8647671
|
@ -1,13 +1,14 @@
|
||||||
@namespace Oqtane.Modules.Admin.Sites
|
@namespace Oqtane.Modules.Admin.Site
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject ISiteService SiteService
|
@inject ISiteService SiteService
|
||||||
|
@inject ITenantService TenantService
|
||||||
@inject IAliasService AliasService
|
@inject IAliasService AliasService
|
||||||
@inject IThemeService ThemeService
|
@inject IThemeService ThemeService
|
||||||
@inject ISettingService SettingService
|
@inject ISettingService SettingService
|
||||||
|
|
||||||
@if (themes != null)
|
@if (themes != null)
|
||||||
{
|
{
|
||||||
<table class="table table-borderless">
|
<table class="table table-borderless">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
@ -17,6 +18,14 @@
|
||||||
<input class="form-control" @bind="@name" />
|
<input class="form-control" @bind="@name" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="Name" class="control-label">Tenant: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="form-control" @bind="@tenant" readonly />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="Name" class="control-label">Aliases: </label>
|
<label for="Name" class="control-label">Aliases: </label>
|
||||||
|
@ -96,7 +105,7 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<a data-toggle="collapse" class="app-link-unstyled" href="#SMTP" aria-expanded="false" aria-controls="SMTP">
|
<a data-toggle="collapse" class="app-link-unstyled" href="#SMTP" aria-expanded="false" aria-controls="SMTP">
|
||||||
<h5>SMTP Settings</h5><hr class="app-rule" />
|
<h5><i class="oi oi-chevron-bottom"></i> SMTP Settings</h5><hr class="app-rule" />
|
||||||
</a>
|
</a>
|
||||||
<div class="collapse" id="SMTP">
|
<div class="collapse" id="SMTP">
|
||||||
<table class="table table-borderless">
|
<table class="table table-borderless">
|
||||||
|
@ -142,25 +151,29 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<br />
|
||||||
<button type="button" class="btn btn-success" @onclick="SaveSite">Save</button>
|
<button type="button" class="btn btn-success" @onclick="SaveSite">Save</button>
|
||||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||||
|
@if (UserSecurity.IsAuthorized(PageState.User, Constants.HostRole))
|
||||||
|
{
|
||||||
|
<ActionDialog Header="Delete Site" Message="@("Are You Sure You Wish To Delete This Site?")" Action="Delete" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await DeleteSite())" />
|
||||||
|
}
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon" DeletedBy="@deletedby" DeletedOn="@deletedon"></AuditInfo>
|
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon" DeletedBy="@deletedby" DeletedOn="@deletedon"></AuditInfo>
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
|
||||||
|
|
||||||
Dictionary<string, string> themes;
|
Dictionary<string, string> themes;
|
||||||
Dictionary<string, string> panelayouts;
|
Dictionary<string, string> panelayouts;
|
||||||
Dictionary<string, string> containers;
|
Dictionary<string, string> containers;
|
||||||
|
|
||||||
List<Theme> Themes;
|
List<Theme> Themes;
|
||||||
Alias Alias;
|
|
||||||
int siteid;
|
|
||||||
string name = "";
|
string name = "";
|
||||||
|
List<Tenant> tenants;
|
||||||
|
string tenant = "";
|
||||||
List<Alias> aliases;
|
List<Alias> aliases;
|
||||||
string urls = "";
|
string urls = "";
|
||||||
int logofileid = -1;
|
int logofileid = -1;
|
||||||
|
@ -189,12 +202,12 @@
|
||||||
{
|
{
|
||||||
Themes = await ThemeService.GetThemesAsync();
|
Themes = await ThemeService.GetThemesAsync();
|
||||||
aliases = await AliasService.GetAliasesAsync();
|
aliases = await AliasService.GetAliasesAsync();
|
||||||
Alias = aliases.Where(item => item.AliasId == int.Parse(PageState.QueryString["id"])).FirstOrDefault();
|
Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
|
||||||
siteid = Alias.SiteId;
|
|
||||||
Site site = await SiteService.GetSiteAsync(siteid, Alias);
|
|
||||||
if (site != null)
|
if (site != null)
|
||||||
{
|
{
|
||||||
name = site.Name;
|
name = site.Name;
|
||||||
|
tenants = await TenantService.GetTenantsAsync();
|
||||||
|
tenant = tenants.Find(item => item.TenantId == site.TenantId).Name;
|
||||||
foreach (Alias alias in aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
|
foreach (Alias alias in aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
|
||||||
{
|
{
|
||||||
urls += alias.Name + "\n";
|
urls += alias.Name + "\n";
|
||||||
|
@ -229,7 +242,7 @@
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", siteid, ex.Message);
|
await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
|
||||||
AddModuleMessage(ex.Message, MessageType.Error);
|
AddModuleMessage(ex.Message, MessageType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +275,7 @@
|
||||||
{
|
{
|
||||||
if (name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
|
if (name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
|
||||||
{
|
{
|
||||||
Site site = await SiteService.GetSiteAsync(siteid, Alias);
|
Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
|
||||||
if (site != null)
|
if (site != null)
|
||||||
{
|
{
|
||||||
site.Name = name;
|
site.Name = name;
|
||||||
|
@ -277,7 +290,7 @@
|
||||||
site.DefaultContainerType = containertype;
|
site.DefaultContainerType = containertype;
|
||||||
site.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
|
site.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
|
||||||
|
|
||||||
site = await SiteService.UpdateSiteAsync(site, Alias);
|
site = await SiteService.UpdateSiteAsync(site);
|
||||||
|
|
||||||
urls = urls.Replace("\n", ",");
|
urls = urls.Replace("\n", ",");
|
||||||
string[] names = urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
string[] names = urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
@ -320,8 +333,23 @@
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", siteid, ex.Message);
|
await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
|
||||||
AddModuleMessage("Error Saving Site", MessageType.Error);
|
AddModuleMessage("Error Saving Site", MessageType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task DeleteSite()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await SiteService.DeleteSiteAsync(PageState.Site.SiteId);
|
||||||
|
await logger.LogInformation("Sited Deleted {SiteId}", PageState.Site.SiteId);
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await logger.LogError(ex, "Error Deleting Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
|
||||||
|
AddModuleMessage("Error Deleting Site", MessageType.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -44,14 +44,6 @@ else
|
||||||
<textarea class="form-control" @bind="@urls" rows="3" />
|
<textarea class="form-control" @bind="@urls" rows="3" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<label for="Name" class="control-label">Logo: </label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<FileManager @ref="filemanager" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="Name" class="control-label">Default Theme: </label>
|
<label for="Name" class="control-label">Default Theme: </label>
|
||||||
|
@ -130,7 +122,6 @@ else
|
||||||
string tenantid = "-1";
|
string tenantid = "-1";
|
||||||
string name = "";
|
string name = "";
|
||||||
string urls = "";
|
string urls = "";
|
||||||
FileManager filemanager;
|
|
||||||
string themetype = "";
|
string themetype = "";
|
||||||
string layouttype = "";
|
string layouttype = "";
|
||||||
string containertype = "";
|
string containertype = "";
|
||||||
|
@ -210,6 +201,8 @@ else
|
||||||
|
|
||||||
if (isvalid)
|
if (isvalid)
|
||||||
{
|
{
|
||||||
|
ShowProgressIndicator();
|
||||||
|
|
||||||
List<Alias> aliases = new List<Alias>();
|
List<Alias> aliases = new List<Alias>();
|
||||||
urls = urls.Replace("\n", ",");
|
urls = urls.Replace("\n", ",");
|
||||||
foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
@ -226,11 +219,6 @@ else
|
||||||
site.TenantId = int.Parse(tenantid);
|
site.TenantId = int.Parse(tenantid);
|
||||||
site.Name = name;
|
site.Name = name;
|
||||||
site.LogoFileId = null;
|
site.LogoFileId = null;
|
||||||
int logofileid = filemanager.GetFileId();
|
|
||||||
if (logofileid != -1)
|
|
||||||
{
|
|
||||||
site.LogoFileId = logofileid;
|
|
||||||
}
|
|
||||||
site.DefaultThemeType = themetype;
|
site.DefaultThemeType = themetype;
|
||||||
site.DefaultLayoutType = (layouttype == null ? "" : layouttype);
|
site.DefaultLayoutType = (layouttype == null ? "" : layouttype);
|
||||||
site.DefaultContainerType = containertype;
|
site.DefaultContainerType = containertype;
|
||||||
|
|
|
@ -19,8 +19,8 @@ else
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
</Header>
|
</Header>
|
||||||
<Row>
|
<Row>
|
||||||
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.AliasId.ToString())" /></td>
|
<td><NavLink class="btn btn-primary" href="@(scheme + context.Name + "/admin/site")">Edit</NavLink></td>
|
||||||
<td><ActionDialog Header="Delete Site" Message="@("Are You Sure You Wish To Delete The " + context.Name + " Site?")" Action="Delete" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await DeleteSite(context))" Disabled="sites.Count == 1" /></td>
|
<td><NavLink class="btn btn-danger" href="@(scheme + context.Name + "/admin/site")">Delete</NavLink></td>
|
||||||
<td><a href="@(scheme + context.Name)">@context.Name</a></td>
|
<td><a href="@(scheme + context.Name)">@context.Name</a></td>
|
||||||
</Row>
|
</Row>
|
||||||
</Pager>
|
</Pager>
|
||||||
|
@ -47,19 +47,4 @@ else
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DeleteSite(Alias Alias)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await SiteService.DeleteSiteAsync(Alias.SiteId, Alias);
|
|
||||||
await logger.LogInformation("Sited Deleted {Alias}", Alias);
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
await logger.LogError(ex, "Error Deleting Site {Error}", ex.Message);
|
|
||||||
AddModuleMessage("Error Deleting Site", MessageType.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -4,32 +4,78 @@
|
||||||
@inject ITenantService TenantService
|
@inject ITenantService TenantService
|
||||||
@inject IInstallationService InstallationService
|
@inject IInstallationService InstallationService
|
||||||
|
|
||||||
<table class="table table-borderless">
|
<table class="table table-borderless">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="Name" class="control-label">Name: </label>
|
<label for="Name" class="control-label">Name: </label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input class="form-control" @bind="@name" />
|
<input class="form-control" @bind="@name" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="Name" class="control-label">Connection String: </label>
|
<label for="Title" class="control-label">Database Type: </label>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input class="form-control" @bind="@connectionstring" />
|
<select class="custom-select" @bind="@type">
|
||||||
</td>
|
<option value="LocalDB">Local Database</option>
|
||||||
</tr>
|
<option value="SQLServer">SQL Server</option>
|
||||||
<tr>
|
</select>
|
||||||
<td>
|
</td>
|
||||||
<label for="Name" class="control-label">Schema: </label>
|
</tr>
|
||||||
</td>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<input class="form-control" @bind="@schema" />
|
<label for="Title" class="control-label">Server: </label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
<td>
|
||||||
</table>
|
<input type="text" class="form-control" @bind="@server" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="Title" class="control-label">Database: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" class="form-control" @bind="@database" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="Title" class="control-label">Integrated Security: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select class="custom-select" @onchange="SetIntegratedSecurity">
|
||||||
|
<option value="true" selected>True</option>
|
||||||
|
<option value="false">False</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr style="@integratedsecurity">
|
||||||
|
<td>
|
||||||
|
<label for="Title" class="control-label">Username: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" class="form-control" @bind="@username" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr style="@integratedsecurity">
|
||||||
|
<td>
|
||||||
|
<label for="Title" class="control-label">Password: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="password" class="form-control" @bind="@password" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="Name" class="control-label">Schema: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input class="form-control" @bind="@schema" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
<button type="button" class="btn btn-success" @onclick="SaveTenant">Save</button>
|
<button type="button" class="btn btn-success" @onclick="SaveTenant">Save</button>
|
||||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||||
|
|
||||||
|
@ -37,46 +83,72 @@
|
||||||
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
||||||
|
|
||||||
string name = "";
|
string name = "";
|
||||||
string connectionstring = "";
|
string type = "LocalDB";
|
||||||
|
string server = "(LocalDb)\\MSSQLLocalDB";
|
||||||
|
string database = "Oqtane-" + DateTime.Now.ToString("yyyyMMddHHmm");
|
||||||
|
string username = "";
|
||||||
|
string password = "";
|
||||||
string schema = "";
|
string schema = "";
|
||||||
|
string integratedsecurity = "display: none;";
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
private void SetIntegratedSecurity(ChangeEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
if (Convert.ToBoolean((string)e.Value))
|
||||||
{
|
{
|
||||||
List<Tenant> tenants = await TenantService.GetTenantsAsync();
|
integratedsecurity = "display: none;";
|
||||||
connectionstring = tenants.FirstOrDefault().DBConnectionString;
|
|
||||||
schema = tenants.FirstOrDefault().DBSchema;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
await logger.LogError(ex, "Error Loading Tenants {Error}", ex.Message);
|
integratedsecurity = "";
|
||||||
AddModuleMessage("Error Loading Tenants", MessageType.Error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SaveTenant()
|
private async Task SaveTenant()
|
||||||
{
|
{
|
||||||
ShowProgressIndicator();
|
if (!string.IsNullOrEmpty(name))
|
||||||
|
|
||||||
connectionstring = connectionstring.Replace("\\\\", "\\");
|
|
||||||
GenericResponse response = await InstallationService.Install(connectionstring);
|
|
||||||
if (response.Success)
|
|
||||||
{
|
{
|
||||||
Tenant tenant = new Tenant();
|
ShowProgressIndicator();
|
||||||
tenant.Name = name;
|
|
||||||
tenant.DBConnectionString = connectionstring;
|
|
||||||
tenant.DBSchema = schema;
|
|
||||||
tenant.IsInitialized = false;
|
|
||||||
await TenantService.AddTenantAsync(tenant);
|
|
||||||
await logger.LogInformation("Tenant Created {Tenant}", tenant);
|
|
||||||
|
|
||||||
NavigationManager.NavigateTo(NavigateUrl());
|
string connectionstring = "";
|
||||||
|
if (type == "LocalDB")
|
||||||
|
{
|
||||||
|
connectionstring = "Data Source=" + server + ";AttachDbFilename=|DataDirectory|\\" + database + ".mdf;Initial Catalog=" + database + ";Integrated Security=SSPI;";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
connectionstring = "Data Source=" + server + ";Initial Catalog=" + database + ";";
|
||||||
|
if (integratedsecurity == "display: none;")
|
||||||
|
{
|
||||||
|
connectionstring += "Integrated Security=SSPI;";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
connectionstring += "User ID=" + username + ";Password=" + password;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GenericResponse response = await InstallationService.Install(connectionstring);
|
||||||
|
if (response.Success)
|
||||||
|
{
|
||||||
|
Tenant tenant = new Tenant();
|
||||||
|
tenant.Name = name;
|
||||||
|
tenant.DBConnectionString = connectionstring;
|
||||||
|
tenant.DBSchema = schema;
|
||||||
|
tenant.IsInitialized = false;
|
||||||
|
await TenantService.AddTenantAsync(tenant);
|
||||||
|
await logger.LogInformation("Tenant Created {Tenant}", tenant);
|
||||||
|
|
||||||
|
NavigationManager.NavigateTo(NavigateUrl());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await logger.LogError("Error Creating Tenant {Error}", response.Message);
|
||||||
|
AddModuleMessage(response.Message, MessageType.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await logger.LogError("Error Creating Tenant {Error}", response.Message);
|
AddModuleMessage("You Must Provide A Name For The Tenant", MessageType.Warning);
|
||||||
AddModuleMessage(response.Message, MessageType.Error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,6 @@
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string UploadMultiple { get; set; } // optional - enable multiple file uploads - default false
|
public string UploadMultiple { get; set; } // optional - enable multiple file uploads - default false
|
||||||
|
|
||||||
|
|
||||||
string id;
|
string id;
|
||||||
List<Folder> folders;
|
List<Folder> folders;
|
||||||
int folderid = -1;
|
int folderid = -1;
|
||||||
|
|
|
@ -9,15 +9,11 @@ namespace Oqtane.Services
|
||||||
Task<List<Site>> GetSitesAsync();
|
Task<List<Site>> GetSitesAsync();
|
||||||
|
|
||||||
Task<Site> GetSiteAsync(int SiteId);
|
Task<Site> GetSiteAsync(int SiteId);
|
||||||
Task<Site> GetSiteAsync(int SiteId, Alias Alias);
|
|
||||||
|
|
||||||
Task<Site> AddSiteAsync(Site Site);
|
|
||||||
Task<Site> AddSiteAsync(Site Site, Alias Alias);
|
Task<Site> AddSiteAsync(Site Site, Alias Alias);
|
||||||
|
|
||||||
Task<Site> UpdateSiteAsync(Site Site);
|
Task<Site> UpdateSiteAsync(Site Site);
|
||||||
Task<Site> UpdateSiteAsync(Site Site, Alias Alias);
|
|
||||||
|
|
||||||
Task DeleteSiteAsync(int SiteId);
|
Task DeleteSiteAsync(int SiteId);
|
||||||
Task DeleteSiteAsync(int SiteId, Alias Alias);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Oqtane.Services
|
||||||
|
|
||||||
Task<User> AddUserAsync(User User);
|
Task<User> AddUserAsync(User User);
|
||||||
|
|
||||||
Task<User> AddUserAsync(User User, Alias alias);
|
Task<User> AddUserAsync(User User, Alias Alias);
|
||||||
|
|
||||||
Task<User> UpdateUserAsync(User User);
|
Task<User> UpdateUserAsync(User User);
|
||||||
|
|
||||||
|
|
|
@ -36,37 +36,27 @@ namespace Oqtane.Services
|
||||||
{
|
{
|
||||||
return await http.GetJsonAsync<Site>(apiurl + "/" + SiteId.ToString());
|
return await http.GetJsonAsync<Site>(apiurl + "/" + SiteId.ToString());
|
||||||
}
|
}
|
||||||
public async Task<Site> GetSiteAsync(int SiteId, Alias Alias)
|
|
||||||
{
|
|
||||||
return await http.GetJsonAsync<Site>(CreateApiUrl(Alias, NavigationManager.Uri, "Site") + "/" + SiteId.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Site> AddSiteAsync(Site Site)
|
|
||||||
{
|
|
||||||
return await http.PostJsonAsync<Site>(apiurl, Site);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Site> AddSiteAsync(Site Site, Alias Alias)
|
public async Task<Site> AddSiteAsync(Site Site, Alias Alias)
|
||||||
{
|
{
|
||||||
return await http.PostJsonAsync<Site>(CreateApiUrl(Alias, NavigationManager.Uri, "Site"), Site);
|
if (Alias == null)
|
||||||
|
{
|
||||||
|
return await http.PostJsonAsync<Site>(apiurl, Site);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return await http.PostJsonAsync<Site>(CreateApiUrl(Alias, NavigationManager.Uri, "Site"), Site);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Site> UpdateSiteAsync(Site Site)
|
public async Task<Site> UpdateSiteAsync(Site Site)
|
||||||
{
|
{
|
||||||
return await http.PutJsonAsync<Site>(apiurl + "/" + Site.SiteId.ToString(), Site);
|
return await http.PutJsonAsync<Site>(apiurl + "/" + Site.SiteId.ToString(), Site);
|
||||||
}
|
}
|
||||||
public async Task<Site> UpdateSiteAsync(Site Site, Alias Alias)
|
|
||||||
{
|
|
||||||
return await http.PutJsonAsync<Site>(CreateApiUrl(Alias, NavigationManager.Uri, "Site") + "/" + Site.SiteId.ToString(), Site);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task DeleteSiteAsync(int SiteId)
|
public async Task DeleteSiteAsync(int SiteId)
|
||||||
{
|
{
|
||||||
await http.DeleteAsync(apiurl + "/" + SiteId.ToString());
|
await http.DeleteAsync(apiurl + "/" + SiteId.ToString());
|
||||||
}
|
}
|
||||||
public async Task DeleteSiteAsync(int SiteId, Alias Alias)
|
|
||||||
{
|
|
||||||
await http.DeleteAsync(CreateApiUrl(Alias, NavigationManager.Uri, "Site") + "/" + SiteId.ToString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@
|
||||||
site.DefaultThemeType = Constants.DefaultTheme;
|
site.DefaultThemeType = Constants.DefaultTheme;
|
||||||
site.DefaultLayoutType = Constants.DefaultLayout;
|
site.DefaultLayoutType = Constants.DefaultLayout;
|
||||||
site.DefaultContainerType = Constants.DefaultContainer;
|
site.DefaultContainerType = Constants.DefaultContainer;
|
||||||
site = await SiteService.AddSiteAsync(site);
|
site = await SiteService.AddSiteAsync(site, null);
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.SiteId = site.SiteId;
|
user.SiteId = site.SiteId;
|
||||||
|
|
|
@ -7,6 +7,7 @@ using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
|
@ -42,6 +43,7 @@ namespace Oqtane.Controllers
|
||||||
[HttpGet("name/{name}")]
|
[HttpGet("name/{name}")]
|
||||||
public Alias Get(string name)
|
public Alias Get(string name)
|
||||||
{
|
{
|
||||||
|
name = WebUtility.UrlDecode(name);
|
||||||
List<Alias> aliases = Aliases.GetAliases().ToList();
|
List<Alias> aliases = Aliases.GetAliases().ToList();
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
alias = aliases.Where(item => item.Name == name).FirstOrDefault();
|
alias = aliases.Where(item => item.Name == name).FirstOrDefault();
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace Oqtane.Controllers
|
||||||
if (authorized)
|
if (authorized)
|
||||||
{
|
{
|
||||||
Site = Sites.AddSite(Site);
|
Site = Sites.AddSite(Site);
|
||||||
logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Added {Site}", Site);
|
logger.Log(Site.SiteId, LogLevel.Information, this, LogFunction.Create, "Site Added {Site}", Site);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Site;
|
return Site;
|
||||||
|
@ -77,7 +77,7 @@ namespace Oqtane.Controllers
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Site = Sites.UpdateSite(Site);
|
Site = Sites.UpdateSite(Site);
|
||||||
logger.Log(LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", Site);
|
logger.Log(Site.SiteId, LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", Site);
|
||||||
}
|
}
|
||||||
return Site;
|
return Site;
|
||||||
}
|
}
|
||||||
|
@ -87,14 +87,15 @@ namespace Oqtane.Controllers
|
||||||
[Authorize(Roles = Constants.HostRole)]
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public void Delete(int id)
|
public void Delete(int id)
|
||||||
{
|
{
|
||||||
|
Site Site = Sites.GetSite(id);
|
||||||
if (Sites.GetSites().Count() > 1)
|
if (Sites.GetSites().Count() > 1)
|
||||||
{
|
{
|
||||||
Sites.DeleteSite(id);
|
Sites.DeleteSite(id);
|
||||||
logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Deleted {SiteId}", id);
|
logger.Log(Site.SiteId, LogLevel.Information, this, LogFunction.Delete, "Site Deleted {SiteId}", id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.Log(LogLevel.Warning, this, LogFunction.Delete, "Unable to delete the root site.");
|
logger.Log(Site.SiteId, LogLevel.Warning, this, LogFunction.Delete, "Unable to delete the root site.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ namespace Oqtane.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user.Password = ""; // remove sensitive information
|
user.Password = ""; // remove sensitive information
|
||||||
logger.Log(LogLevel.Information, this, LogFunction.Create, "User Added {User}", user);
|
logger.Log(User.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
|
|
@ -8,6 +8,8 @@ namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
void Log(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args);
|
void Log(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args);
|
||||||
void Log(LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args);
|
void Log(LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args);
|
||||||
|
void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args);
|
||||||
|
void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args);
|
||||||
void Log(Log Log);
|
void Log(Log Log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,14 +29,35 @@ namespace Oqtane.Infrastructure
|
||||||
|
|
||||||
public void Log(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args)
|
public void Log(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args)
|
||||||
{
|
{
|
||||||
Log(Level, Class.GetType().AssemblyQualifiedName, Function, null, Message, Args);
|
Log(-1, Level, Class.GetType().AssemblyQualifiedName, Function, null, Message, Args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Log(LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args)
|
public void Log(LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args)
|
||||||
{
|
{
|
||||||
Alias alias = TenantResolver.GetAlias();
|
Log(-1, Level, Class.GetType().AssemblyQualifiedName, Function, Exception, Message, Args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args)
|
||||||
|
{
|
||||||
|
Log(SiteId, Level, Class.GetType().AssemblyQualifiedName, Function, null, Message, Args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args)
|
||||||
|
{
|
||||||
Log log = new Log();
|
Log log = new Log();
|
||||||
log.SiteId = alias.SiteId;
|
if (SiteId == -1)
|
||||||
|
{
|
||||||
|
log.SiteId = null;
|
||||||
|
Alias alias = TenantResolver.GetAlias();
|
||||||
|
if (alias != null)
|
||||||
|
{
|
||||||
|
log.SiteId = alias.SiteId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log.SiteId = SiteId;
|
||||||
|
}
|
||||||
log.PageId = null;
|
log.PageId = null;
|
||||||
log.ModuleId = null;
|
log.ModuleId = null;
|
||||||
log.UserId = null;
|
log.UserId = null;
|
||||||
|
@ -96,56 +117,70 @@ namespace Oqtane.Infrastructure
|
||||||
Log.Server = Environment.MachineName;
|
Log.Server = Environment.MachineName;
|
||||||
Log.MessageTemplate = Log.Message;
|
Log.MessageTemplate = Log.Message;
|
||||||
Log = ProcessStructuredLog(Log);
|
Log = ProcessStructuredLog(Log);
|
||||||
Logs.AddLog(Log);
|
try
|
||||||
|
{
|
||||||
|
Logs.AddLog(Log);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// an error occurred writing to the database
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Log ProcessStructuredLog(Log Log)
|
private Log ProcessStructuredLog(Log Log)
|
||||||
{
|
{
|
||||||
string message = Log.Message;
|
try
|
||||||
string properties = "";
|
|
||||||
if (!string.IsNullOrEmpty(message) && message.Contains("{") && message.Contains("}") && !string.IsNullOrEmpty(Log.Properties))
|
|
||||||
{
|
{
|
||||||
// get the named holes in the message and replace values
|
string message = Log.Message;
|
||||||
object[] values = JsonSerializer.Deserialize<object[]>(Log.Properties);
|
string properties = "";
|
||||||
List<string> names = new List<string>();
|
if (!string.IsNullOrEmpty(message) && message.Contains("{") && message.Contains("}") && !string.IsNullOrEmpty(Log.Properties))
|
||||||
int index = message.IndexOf("{");
|
|
||||||
while (index != -1)
|
|
||||||
{
|
{
|
||||||
if (message.IndexOf("}", index) != -1)
|
// get the named holes in the message and replace values
|
||||||
|
object[] values = JsonSerializer.Deserialize<object[]>(Log.Properties);
|
||||||
|
List<string> names = new List<string>();
|
||||||
|
int index = message.IndexOf("{");
|
||||||
|
while (index != -1)
|
||||||
{
|
{
|
||||||
names.Add(message.Substring(index + 1, message.IndexOf("}", index) - index - 1));
|
if (message.IndexOf("}", index) != -1)
|
||||||
if (values.Length > (names.Count - 1))
|
|
||||||
{
|
{
|
||||||
if (values[names.Count - 1] == null)
|
names.Add(message.Substring(index + 1, message.IndexOf("}", index) - index - 1));
|
||||||
|
if (values.Length > (names.Count - 1))
|
||||||
{
|
{
|
||||||
message = message.Replace("{" + names[names.Count - 1] + "}", "null");
|
if (values[names.Count - 1] == null)
|
||||||
}
|
{
|
||||||
else
|
message = message.Replace("{" + names[names.Count - 1] + "}", "null");
|
||||||
{
|
}
|
||||||
message = message.Replace("{" + names[names.Count - 1] + "}", values[names.Count - 1].ToString());
|
else
|
||||||
|
{
|
||||||
|
message = message.Replace("{" + names[names.Count - 1] + "}", values[names.Count - 1].ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
index = message.IndexOf("{", index + 1);
|
||||||
}
|
}
|
||||||
index = message.IndexOf("{", index + 1);
|
// rebuild properties into dictionary
|
||||||
}
|
Dictionary<string, object> propertydictionary = new Dictionary<string, object>();
|
||||||
// rebuild properties into dictionary
|
for (int i = 0; i < values.Length; i++)
|
||||||
Dictionary<string, object> propertydictionary = new Dictionary<string, object>();
|
|
||||||
for (int i = 0; i < values.Length; i++)
|
|
||||||
{
|
|
||||||
if (i < names.Count)
|
|
||||||
{
|
{
|
||||||
propertydictionary.Add(names[i], values[i]);
|
if (i < names.Count)
|
||||||
}
|
{
|
||||||
else
|
propertydictionary.Add(names[i], values[i]);
|
||||||
{
|
}
|
||||||
propertydictionary.Add("Property" + i.ToString(), values[i]);
|
else
|
||||||
|
{
|
||||||
|
propertydictionary.Add("Property" + i.ToString(), values[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
properties = JsonSerializer.Serialize(propertydictionary);
|
||||||
}
|
}
|
||||||
properties = JsonSerializer.Serialize(propertydictionary);
|
Log.Message = message;
|
||||||
|
Log.Properties = properties;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Log.Properties = "";
|
||||||
}
|
}
|
||||||
Log.Message = message;
|
|
||||||
Log.Properties = properties;
|
|
||||||
return Log;
|
return Log;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,9 @@ namespace Oqtane.Repository
|
||||||
SiteTemplate.Add(new PageTemplate { Name = "Site Management", Parent = "Admin", Path = "admin/sites", Icon = "globe", IsNavigation = false, IsPersonalizable = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
|
SiteTemplate.Add(new PageTemplate { Name = "Site Management", Parent = "Admin", Path = "admin/sites", Icon = "globe", IsNavigation = false, IsPersonalizable = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
|
||||||
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Sites, Oqtane.Client", Title = "Site Management", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
|
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Sites, Oqtane.Client", Title = "Site Management", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
|
||||||
}});
|
}});
|
||||||
|
SiteTemplate.Add(new PageTemplate { Name = "Site Settings", Parent = "Admin", Path = "admin/site", Icon = "home", IsNavigation = false, IsPersonalizable = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
|
||||||
|
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Site, Oqtane.Client", Title = "Site Settings", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
|
||||||
|
}});
|
||||||
SiteTemplate.Add(new PageTemplate { Name = "Page Management", Parent = "Admin", Path = "admin/pages", Icon = "layers", IsNavigation = false, IsPersonalizable = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
|
SiteTemplate.Add(new PageTemplate { Name = "Page Management", Parent = "Admin", Path = "admin/pages", Icon = "layers", IsNavigation = false, IsPersonalizable = false, EditMode = true, PagePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", PageTemplateModules = new List<PageTemplateModule> {
|
||||||
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Pages, Oqtane.Client", Title = "Page Management", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
|
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.Pages, Oqtane.Client", Title = "Page Management", Pane = "Content", ModulePermissions = "[{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]", Content = "" }
|
||||||
}});
|
}});
|
||||||
|
|
|
@ -212,7 +212,7 @@ GO
|
||||||
CREATE TABLE [dbo].[Log] (
|
CREATE TABLE [dbo].[Log] (
|
||||||
|
|
||||||
[LogId] [int] IDENTITY(1,1) NOT NULL,
|
[LogId] [int] IDENTITY(1,1) NOT NULL,
|
||||||
[SiteId] [int] NOT NULL,
|
[SiteId] [int] NULL,
|
||||||
[LogDate] [datetime] NOT NULL,
|
[LogDate] [datetime] NOT NULL,
|
||||||
[PageId] [int] NULL,
|
[PageId] [int] NULL,
|
||||||
[ModuleId] [int] NULL,
|
[ModuleId] [int] NULL,
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace Oqtane.Models
|
||||||
public class Log
|
public class Log
|
||||||
{
|
{
|
||||||
public int LogId { get; set; }
|
public int LogId { get; set; }
|
||||||
public int SiteId { get; set; }
|
public int? SiteId { get; set; }
|
||||||
public DateTime LogDate { get; set; }
|
public DateTime LogDate { get; set; }
|
||||||
public int? PageId { get; set; }
|
public int? PageId { get; set; }
|
||||||
public int? ModuleId { get; set; }
|
public int? ModuleId { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user