diff --git a/Oqtane.Client/Modules/Controls/FileManager.razor b/Oqtane.Client/Modules/Controls/FileManager.razor index 6a1f4aa0..c37cef54 100644 --- a/Oqtane.Client/Modules/Controls/FileManager.razor +++ b/Oqtane.Client/Modules/Controls/FileManager.razor @@ -61,10 +61,20 @@ } -
-
-
-
+ @if (ShowProgress) + { +
+
+
+
+ } + else + { + if (_uploading) + { +
+ } + } } @@ -100,6 +110,7 @@ private string _guid; private string _message = string.Empty; private MessageType _messagetype; + private bool _uploading = false; [Parameter] public string Id { get; set; } // optional - for setting the id of the FileManager component for accessibility @@ -128,6 +139,9 @@ [Parameter] public bool ShowImage { get; set; } = true; // optional - for indicating whether an image thumbnail should be displayed - default is true + [Parameter] + public bool ShowProgress { get; set; } = true; // optional - for indicating whether progress info should be displayed during upload - default is true + [Parameter] public bool ShowSuccess { get; set; } = false; // optional - for indicating whether a success message should be displayed upon successful upload - default is false @@ -271,13 +285,10 @@ { _message = string.Empty; FileId = int.Parse((string)e.Value); - if (FileId != -1) - { - await OnSelect.InvokeAsync(FileId); - } - await SetImage(); + await OnSelect.InvokeAsync(FileId); StateHasChanged(); + } private async Task SetImage() @@ -321,6 +332,12 @@ } if (restricted == "") { + if (!ShowProgress) + { + _uploading = true; + StateHasChanged(); + } + try { // upload the files @@ -354,8 +371,16 @@ } // reset progress indicators - await interop.SetElementAttribute(_guid + "ProgressInfo", "style", "display: none;"); - await interop.SetElementAttribute(_guid + "ProgressBar", "style", "display: none;"); + if (ShowProgress) + { + await interop.SetElementAttribute(_guid + "ProgressInfo", "style", "display: none;"); + await interop.SetElementAttribute(_guid + "ProgressBar", "style", "display: none;"); + } + else + { + _uploading = false; + StateHasChanged(); + } if (success) { @@ -396,7 +421,9 @@ await logger.LogError(ex, "File Upload Failed {Error}", ex.Message); _message = Localizer["Error.File.Upload"]; _messagetype = MessageType.Error; + _uploading = false; } + } else { diff --git a/Oqtane.Client/Services/ServiceBase.cs b/Oqtane.Client/Services/ServiceBase.cs index 110ea49b..54c66d7e 100644 --- a/Oqtane.Client/Services/ServiceBase.cs +++ b/Oqtane.Client/Services/ServiceBase.cs @@ -202,15 +202,15 @@ namespace Oqtane.Services private async Task CheckResponse(HttpResponseMessage response, string uri) { - if (uri.Contains("/api/") && !response.RequestMessage.RequestUri.AbsolutePath.Contains("/api/")) + if (response.IsSuccessStatusCode && uri.Contains("/api/") && !response.RequestMessage.RequestUri.AbsolutePath.Contains("/api/")) { - await Log(uri, response.RequestMessage.Method.ToString(), "Request {Uri} Not Mapped To A Controller Method", uri); + await Log(uri, response.RequestMessage.Method.ToString(), response.StatusCode.ToString(), "Request {Uri} Not Mapped To An API Controller Method", uri); return false; } if (response.IsSuccessStatusCode) return true; if (response.StatusCode != HttpStatusCode.NoContent && response.StatusCode != HttpStatusCode.NotFound) { - await Log(uri, response.RequestMessage.Method.ToString(), "Request {Uri} Failed With Status {StatusCode} - {ReasonPhrase}", uri, response.StatusCode, response.ReasonPhrase); + await Log(uri, response.RequestMessage.Method.ToString(), response.StatusCode.ToString(), "Request {Uri} Failed With Status {StatusCode} - {ReasonPhrase}", uri, response.StatusCode, response.ReasonPhrase); } return false; } @@ -221,7 +221,7 @@ namespace Oqtane.Services return mediaType != null && mediaType.Equals("application/json", StringComparison.OrdinalIgnoreCase); } - private async Task Log(string uri, string method, string message, params object[] args) + private async Task Log(string uri, string method, string status, string message, params object[] args) { if (_siteState.Alias != null) { @@ -251,7 +251,14 @@ namespace Oqtane.Services log.Function = LogFunction.Other.ToString(); break; } - log.Level = LogLevel.Error.ToString(); + if (status == "500") + { + log.Level = LogLevel.Error.ToString(); + } + else + { + log.Level = LogLevel.Warning.ToString(); + } log.Message = message; log.MessageTemplate = ""; log.Properties = JsonSerializer.Serialize(args); diff --git a/Oqtane.Client/Themes/Controls/Container/ModuleActionsBase.cs b/Oqtane.Client/Themes/Controls/Container/ModuleActionsBase.cs index eb452b6b..fb61b714 100644 --- a/Oqtane.Client/Themes/Controls/Container/ModuleActionsBase.cs +++ b/Oqtane.Client/Themes/Controls/Container/ModuleActionsBase.cs @@ -139,11 +139,11 @@ namespace Oqtane.Themes.Controls var permissions = pagemodule.Module.PermissionList; if (!permissions.Any(item => item.PermissionName == PermissionNames.View && item.RoleName == RoleNames.Everyone)) { - permissions.Add(new Permission(ModuleState.SiteId, EntityNames.Page, pagemodule.PageId, PermissionNames.View, RoleNames.Everyone, null, true)); + permissions.Add(new Permission(ModuleState.SiteId, EntityNames.Module, pagemodule.ModuleId, PermissionNames.View, RoleNames.Everyone, null, true)); } if (!permissions.Any(item => item.PermissionName == PermissionNames.View && item.RoleName == RoleNames.Registered)) { - permissions.Add(new Permission(ModuleState.SiteId, EntityNames.Page, pagemodule.PageId, PermissionNames.View, RoleNames.Registered, null, true)); + permissions.Add(new Permission(ModuleState.SiteId, EntityNames.Module, pagemodule.ModuleId, PermissionNames.View, RoleNames.Registered, null, true)); } pagemodule.Module.PermissionList = permissions; await ModuleService.UpdateModuleAsync(pagemodule.Module); diff --git a/Oqtane.Server/Controllers/PageController.cs b/Oqtane.Server/Controllers/PageController.cs index a23828f7..5c7c5e8a 100644 --- a/Oqtane.Server/Controllers/PageController.cs +++ b/Oqtane.Server/Controllers/PageController.cs @@ -89,7 +89,7 @@ namespace Oqtane.Controllers { if (page != null) { - _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Page Get Attempt {PageId}", id); + _logger.Log(LogLevel.Warning, this, LogFunction.Security, "Unauthorized Page Get Attempt {PageId}", id); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; } else @@ -116,7 +116,7 @@ namespace Oqtane.Controllers { if (page != null) { - _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Page Get Attempt {SiteId} {Path}", siteid, path); + _logger.Log(LogLevel.Warning, this, LogFunction.Security, "Unauthorized Page Get Attempt {SiteId} {Path}", siteid, path); HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; } else diff --git a/Oqtane.Server/Infrastructure/InstallationManager.cs b/Oqtane.Server/Infrastructure/InstallationManager.cs index fa856456..835350b6 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -201,7 +201,24 @@ namespace Oqtane.Infrastructure { Directory.CreateDirectory(Path.GetDirectoryName(filename)); } - entry.ExtractToFile(filename, true); + if (Path.Exists(filename) && Path.GetExtension(filename).ToLower() == ".dll") + { + // ensure assembly version is equal to or greater than existing assembly + var assembly = filename.Replace(Path.GetFileName(filename), "temp.dll"); + entry.ExtractToFile(assembly, true); + if (Version.Parse(FileVersionInfo.GetVersionInfo(assembly).FileVersion).CompareTo(Version.Parse(FileVersionInfo.GetVersionInfo(filename).FileVersion)) >= 0) + { + File.Move(assembly, filename, true); + } + else + { + File.Delete(assembly); + } + } + else + { + entry.ExtractToFile(filename, true); + } } catch { diff --git a/Oqtane.Server/wwwroot/js/interop.js b/Oqtane.Server/wwwroot/js/interop.js index 5ee359c8..792eb464 100644 --- a/Oqtane.Server/wwwroot/js/interop.js +++ b/Oqtane.Server/wwwroot/js/interop.js @@ -290,8 +290,10 @@ Oqtane.Interop = { var progressinfo = document.getElementById('ProgressInfo_' + id); var progressbar = document.getElementById('ProgressBar_' + id); - progressinfo.setAttribute("style", "display: inline;"); - progressbar.setAttribute("style", "width: 100%; display: inline;"); + if (progressinfo !== null && progressbar !== null) { + progressinfo.setAttribute("style", "display: inline;"); + progressbar.setAttribute("style", "width: 100%; display: inline;"); + } for (var i = 0; i < files.length; i++) { var FileChunk = []; @@ -322,21 +324,29 @@ Oqtane.Interop = { var request = new XMLHttpRequest(); request.open('POST', posturl, true); request.upload.onloadstart = function (e) { - progressinfo.innerHTML = file.name + ' 0%'; - progressbar.value = 0; + if (progressinfo !== null && progressbar !== null) { + progressinfo.innerHTML = file.name + ' 0%'; + progressbar.value = 0; + } }; request.upload.onprogress = function (e) { - var percent = Math.ceil((e.loaded / e.total) * 100); - progressinfo.innerHTML = file.name + '[' + PartCount + '] ' + percent + '%'; - progressbar.value = (percent / 100); + if (progressinfo !== null && progressbar !== null) { + var percent = Math.ceil((e.loaded / e.total) * 100); + progressinfo.innerHTML = file.name + '[' + PartCount + '] ' + percent + '%'; + progressbar.value = (percent / 100); + } }; request.upload.onloadend = function (e) { - progressinfo.innerHTML = file.name + ' 100%'; - progressbar.value = 1; + if (progressinfo !== null && progressbar !== null) { + progressinfo.innerHTML = file.name + ' 100%'; + progressbar.value = 1; + } }; - request.upload.onerror = function () { - progressinfo.innerHTML = file.name + ' Error: ' + xhr.status; - progressbar.value = 0; + request.upload.onerror = function() { + if (progressinfo !== null && progressbar !== null) { + progressinfo.innerHTML = file.name + ' Error: ' + xhr.status; + progressbar.value = 0; + } }; request.send(data); }