From 8ac78415b751aabcb9798e46a275bca1e9fa298e Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Thu, 20 Jul 2023 21:22:17 +0200 Subject: [PATCH 01/10] Renaming MaximumSpace to MaximumSpaceBytes, MaximumStorageQuota to MaximumStorageQuotaBytes --- .../Extensions/MediaStorageManagementExtensions.cs | 6 +++--- .../Constants/MediaStorageManagementOptionsConstants.cs | 6 +++--- .../Filters/UploadFileSizeShapeFilter.cs | 4 ++-- Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md | 4 ++-- .../Service/MediaStorageQuotaService.cs | 4 ++-- .../Settings/MediaStorageManagementOptions.cs | 4 ++-- Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs | 6 ++++-- .../ViewModels/UploadFileSizeViewModel.cs | 4 ++-- .../Views/UploadFileSize.cshtml | 2 +- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs index 88ee7d8c..51a998d6 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs @@ -9,15 +9,15 @@ public static class MediaStorageManagementExtensions { public static void SetMediaStorageManagementOptionsForUITest( this OrchardCoreUITestExecutorConfiguration configuration, - long maximumSpace) + long maximumSpaceBytes) { configuration.OrchardCoreConfiguration.BeforeAppStart += (_, argumentsBuilder) => { argumentsBuilder .AddWithValue( - "OrchardCore:Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpace", - maximumSpace); + "OrchardCore:Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpaceBytes", + maximumSpaceBytes); return Task.CompletedTask; }; diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Constants/MediaStorageManagementOptionsConstants.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Constants/MediaStorageManagementOptionsConstants.cs index f649fd6f..0331dc71 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Constants/MediaStorageManagementOptionsConstants.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Constants/MediaStorageManagementOptionsConstants.cs @@ -1,9 +1,9 @@ -namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Constants; +namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Constants; public static class MediaStorageManagementOptionsConstants { /// - /// Default MaximumStorageQuota in bytes representing 1GB. + /// Default maximum storage quota in bytes representing 1GB. /// - public const long MaximumStorageQuota = 1_073_741_824; + public const long MaximumStorageQuotaBytes = 1_073_741_824; } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs index e4571ab9..0fa0e48b 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs @@ -45,10 +45,10 @@ actionRouteValue is nameof(AdminController.Index) && { var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Footer"]; - var maximumSpace = _mediaStorageQuotaService.MaxSpaceForTenantInMegabytes(); + var maximumSpaceBytes = _mediaStorageQuotaService.MaxSpaceForTenantInMegabytes(); await contentZone.AddAsync(await _shapeFactory.CreateAsync( "UploadFileSize", - viewModel => viewModel.MaximumSpace = maximumSpace)); + viewModel => viewModel.MaximumSpaceBytes = maximumSpaceBytes)); } await next(); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md b/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md index d10e1b0f..6ca47b9d 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md @@ -22,7 +22,7 @@ With this module, you can specify how much space would you like to limit each te "OrchardCore": { "Lombiq_Hosting_Tenants_MediaStorageManagement": { "Media_Storage_Management_Options": { - "MaximumSpace": 2147483648 + "MaximumSpaceBytes": 2147483648 } } } @@ -35,7 +35,7 @@ Tenant based configuration can be defined as the following, for more details rea "TenantName": { "Lombiq_Hosting_Tenants_MediaStorageManagement": { "Media_Storage_Management_Options": { - "MaximumSpace": 2147483648 + "MaximumSpaceBytes": 2147483648 } } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index 53127025..8ec07b20 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.MediaStorageManagement.Settings; +using Lombiq.Hosting.Tenants.MediaStorageManagement.Settings; using Microsoft.Extensions.Options; using OrchardCore.Media; using System.Linq; @@ -30,7 +30,7 @@ public async Task GetRemainingMediaSpaceQuotaLeftAsync() return remainingSpace < 0 ? 0 : remainingSpace; } - public long MaxSpaceForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuota; + public long MaxSpaceForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes; public float MaxSpaceForTenantInMegabytes() => MaxSpaceForTenantInBytes() / 1024f / 1024f; } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Settings/MediaStorageManagementOptions.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Settings/MediaStorageManagementOptions.cs index fbe068fe..435903d5 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Settings/MediaStorageManagementOptions.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Settings/MediaStorageManagementOptions.cs @@ -1,9 +1,9 @@ -namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Settings; +namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Settings; public class MediaStorageManagementOptions { /// /// Gets or sets the maximum storage quota for a tenant in bytes. Default is 1GB. /// - public long MaximumStorageQuota { get; set; } + public long MaximumStorageQuotaBytes { get; set; } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs index 830224cb..edd7c417 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs @@ -18,11 +18,13 @@ public class Startup : StartupBase public override void ConfigureServices(IServiceCollection services) { - var maximumStorageQuota = + var maximumStorageQuotaBytes = + _shellConfiguration.GetValue( + "Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpaceBytes") ?? _shellConfiguration.GetValue( "Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpace"); services.Configure(options => - options.MaximumStorageQuota = maximumStorageQuota ?? MaximumStorageQuota); + options.MaximumStorageQuotaBytes = maximumStorageQuotaBytes ?? MaximumStorageQuotaBytes); services.AddScoped(); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs index faa0af3b..54e7ee83 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs @@ -1,6 +1,6 @@ -namespace Lombiq.Hosting.Tenants.MediaStorageManagement.ViewModels; +namespace Lombiq.Hosting.Tenants.MediaStorageManagement.ViewModels; public class UploadFileSizeViewModel { - public float MaximumSpace { get; set; } + public float MaximumSpaceBytes { get; set; } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml index 21a159ea..f8156e9e 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml @@ -21,7 +21,7 @@ $(function () { return; } model.errorMessage = - @T["You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", Model.MaximumSpace].Json(); + @T["You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", Model.MaximumSpaceBytes].Json(); }); }); From 14f82b296fed3543fa41485363858228282fdf76 Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Fri, 21 Jul 2023 00:30:13 +0200 Subject: [PATCH 02/10] Renaming MaximumSpaceBytes to MaximumStorageQuotaBytes --- .../Filters/UploadFileSizeShapeFilter.cs | 4 ++-- .../Readme.md | 4 ++-- .../Service/IMediaStorageQuotaService.cs | 13 +++++++------ .../Service/MediaStorageQuotaService.cs | 6 +++--- .../Startup.cs | 2 +- .../ViewModels/UploadFileSizeViewModel.cs | 2 +- .../Views/UploadFileSize.cshtml | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs index 0fa0e48b..a6e3c409 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs @@ -45,10 +45,10 @@ actionRouteValue is nameof(AdminController.Index) && { var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Footer"]; - var maximumSpaceBytes = _mediaStorageQuotaService.MaxSpaceForTenantInMegabytes(); + var maximumStorageQuotaMegaBytes = _mediaStorageQuotaService.MaxStorageQuotaForTenantInMegabytes(); await contentZone.AddAsync(await _shapeFactory.CreateAsync( "UploadFileSize", - viewModel => viewModel.MaximumSpaceBytes = maximumSpaceBytes)); + viewModel => viewModel.MaximumStorageQuotaMegaBytes = maximumStorageQuotaMegaBytes)); } await next(); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md b/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md index 6ca47b9d..e1115552 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md @@ -22,7 +22,7 @@ With this module, you can specify how much space would you like to limit each te "OrchardCore": { "Lombiq_Hosting_Tenants_MediaStorageManagement": { "Media_Storage_Management_Options": { - "MaximumSpaceBytes": 2147483648 + "MaximumStorageQuotaBytes": 2147483648 } } } @@ -35,7 +35,7 @@ Tenant based configuration can be defined as the following, for more details rea "TenantName": { "Lombiq_Hosting_Tenants_MediaStorageManagement": { "Media_Storage_Management_Options": { - "MaximumSpaceBytes": 2147483648 + "MaximumStorageQuotaBytes": 2147483648 } } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs index 2579af71..8fddf6b3 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs @@ -1,4 +1,4 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service; @@ -8,17 +8,18 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service; public interface IMediaStorageQuotaService { /// - /// Returns remaining quota space left in bytes. It is always a non-negative number, meaning the minimum value is 0. + /// Returns remaining storage quota space left in bytes. It is always a non-negative number, meaning the minimum + /// value is 0. /// Task GetRemainingMediaSpaceQuotaLeftAsync(); /// - /// Returns the maximum quota space in bytes. + /// Returns the maximum storage quota space in bytes. /// - long MaxSpaceForTenantInBytes(); + long MaxStorageQuotaForTenantInBytes(); /// - /// Returns the maximum quota space in Megabytes. + /// Returns the maximum storage quota space in Megabytes. /// - float MaxSpaceForTenantInMegabytes(); + float MaxStorageQuotaForTenantInMegabytes(); } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index 8ec07b20..0762c52e 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -25,12 +25,12 @@ public async Task GetRemainingMediaSpaceQuotaLeftAsync() var listed = await directoryContent.ToListAsync(); var sumSize = listed.Where(item => item.Length > 0).Sum(item => item.Length); - var remainingSpace = MaxSpaceForTenantInBytes() - sumSize; + var remainingSpace = MaxStorageQuotaForTenantInBytes() - sumSize; return remainingSpace < 0 ? 0 : remainingSpace; } - public long MaxSpaceForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes; + public long MaxStorageQuotaForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes; - public float MaxSpaceForTenantInMegabytes() => MaxSpaceForTenantInBytes() / 1024f / 1024f; + public float MaxStorageQuotaForTenantInMegabytes() => MaxStorageQuotaForTenantInBytes() / 1024f / 1024f; } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs index edd7c417..300b24d8 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs @@ -20,7 +20,7 @@ public override void ConfigureServices(IServiceCollection services) { var maximumStorageQuotaBytes = _shellConfiguration.GetValue( - "Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpaceBytes") ?? + "Lombiq_Hosting_Tenants_MediaStorageManagement:MaximumStorageQuotaBytes") ?? _shellConfiguration.GetValue( "Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpace"); services.Configure(options => diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs index 54e7ee83..603b4763 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs @@ -2,5 +2,5 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.ViewModels; public class UploadFileSizeViewModel { - public float MaximumSpaceBytes { get; set; } + public float MaximumStorageQuotaMegaBytes { get; set; } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml index f8156e9e..30d81f1c 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml @@ -21,7 +21,7 @@ $(function () { return; } model.errorMessage = - @T["You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", Model.MaximumSpaceBytes].Json(); + @T["You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", Model.MaximumStorageQuotaMegaBytes].Json(); }); }); From 82389b9ef199bee973a1bb283f6cc4024b87b45a Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Fri, 21 Jul 2023 01:06:51 +0200 Subject: [PATCH 03/10] Adjusting readme --- Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md b/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md index e1115552..5cdc7ab0 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md @@ -21,9 +21,7 @@ With this module, you can specify how much space would you like to limit each te ```json "OrchardCore": { "Lombiq_Hosting_Tenants_MediaStorageManagement": { - "Media_Storage_Management_Options": { - "MaximumStorageQuotaBytes": 2147483648 - } + "MaximumStorageQuotaBytes": 2147483648 } } ``` @@ -34,9 +32,7 @@ Tenant based configuration can be defined as the following, for more details rea "OrchardCore": { "TenantName": { "Lombiq_Hosting_Tenants_MediaStorageManagement": { - "Media_Storage_Management_Options": { - "MaximumStorageQuotaBytes": 2147483648 - } + "MaximumStorageQuotaBytes": 2147483648 } } } From bb35bf779d8fa76c26dff48845523466258c5e42 Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Fri, 21 Jul 2023 01:10:40 +0200 Subject: [PATCH 04/10] Renaming space to storage --- .../Filters/MediaStorageQuotaActionFilter.cs | 4 ++-- .../Service/IMediaStorageQuotaService.cs | 2 +- .../Service/MediaStorageQuotaService.cs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs index 2c79e219..4eb52531 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.MediaStorageManagement.Service; +using Lombiq.Hosting.Tenants.MediaStorageManagement.Service; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; @@ -16,7 +16,7 @@ public async Task OnAuthorizationAsync(AuthorizationFilterContext context) .HttpContext .RequestServices .GetRequiredService() - .GetRemainingMediaSpaceQuotaLeftAsync(); + .GetRemainingMediaStorageQuotaLeftAsync(); var formOptions = new FormOptions { diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs index 8fddf6b3..6dc5af45 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs @@ -11,7 +11,7 @@ public interface IMediaStorageQuotaService /// Returns remaining storage quota space left in bytes. It is always a non-negative number, meaning the minimum /// value is 0. /// - Task GetRemainingMediaSpaceQuotaLeftAsync(); + Task GetRemainingMediaStorageQuotaLeftAsync(); /// /// Returns the maximum storage quota space in bytes. diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index 0762c52e..09733b10 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -19,15 +19,15 @@ public MediaStorageQuotaService( _mediaFileStore = mediaFileStore; } - public async Task GetRemainingMediaSpaceQuotaLeftAsync() + public async Task GetRemainingMediaStorageQuotaLeftAsync() { var directoryContent = _mediaFileStore.GetDirectoryContentAsync(includeSubDirectories: true); var listed = await directoryContent.ToListAsync(); var sumSize = listed.Where(item => item.Length > 0).Sum(item => item.Length); - var remainingSpace = MaxStorageQuotaForTenantInBytes() - sumSize; + var remainingStorageQuota = MaxStorageQuotaForTenantInBytes() - sumSize; - return remainingSpace < 0 ? 0 : remainingSpace; + return remainingStorageQuota < 0 ? 0 : remainingStorageQuota; } public long MaxStorageQuotaForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes; From 1b50940faaa14e47cf89c480244858c1404b10c7 Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Fri, 21 Jul 2023 01:11:45 +0200 Subject: [PATCH 05/10] MegaBytes -> Megabytes --- .../Filters/UploadFileSizeShapeFilter.cs | 4 ++-- .../ViewModels/UploadFileSizeViewModel.cs | 2 +- .../Views/UploadFileSize.cshtml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs index a6e3c409..573652bc 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs @@ -45,10 +45,10 @@ actionRouteValue is nameof(AdminController.Index) && { var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Footer"]; - var maximumStorageQuotaMegaBytes = _mediaStorageQuotaService.MaxStorageQuotaForTenantInMegabytes(); + var maximumStorageQuotaMegabytes = _mediaStorageQuotaService.MaxStorageQuotaForTenantInMegabytes(); await contentZone.AddAsync(await _shapeFactory.CreateAsync( "UploadFileSize", - viewModel => viewModel.MaximumStorageQuotaMegaBytes = maximumStorageQuotaMegaBytes)); + viewModel => viewModel.MaximumStorageQuotaMegabytes = maximumStorageQuotaMegabytes)); } await next(); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs index 603b4763..9d3fd7a2 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs @@ -2,5 +2,5 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.ViewModels; public class UploadFileSizeViewModel { - public float MaximumStorageQuotaMegaBytes { get; set; } + public float MaximumStorageQuotaMegabytes { get; set; } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml index 30d81f1c..3040f409 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml @@ -21,7 +21,7 @@ $(function () { return; } model.errorMessage = - @T["You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", Model.MaximumStorageQuotaMegaBytes].Json(); + @T["You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", Model.MaximumStorageQuotaMegabytes].Json(); }); }); From d2259efb4caa71f48398662071493ba3a488cc70 Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Fri, 21 Jul 2023 01:35:06 +0200 Subject: [PATCH 06/10] Fixing UI test --- .../Extensions/MediaStorageManagementExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs index 51a998d6..2779952d 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs @@ -9,15 +9,15 @@ public static class MediaStorageManagementExtensions { public static void SetMediaStorageManagementOptionsForUITest( this OrchardCoreUITestExecutorConfiguration configuration, - long maximumSpaceBytes) + long maximumStorageQuotaBytes) { configuration.OrchardCoreConfiguration.BeforeAppStart += (_, argumentsBuilder) => { argumentsBuilder .AddWithValue( - "OrchardCore:Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpaceBytes", - maximumSpaceBytes); + "OrchardCore:Lombiq_Hosting_Tenants_MediaStorageManagement:MaximumStorageQuotaBytes", + maximumStorageQuotaBytes); return Task.CompletedTask; }; From 08865dff0f882ac12df42cb0a5696bd1556391c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 21 Jul 2023 17:24:31 +0200 Subject: [PATCH 07/10] Code styling --- .../Views/UploadFileSize.cshtml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml index 3040f409..6d43e9fa 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml @@ -21,7 +21,10 @@ $(function () { return; } model.errorMessage = - @T["You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", Model.MaximumStorageQuotaMegabytes].Json(); + @T[ + "You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", + Model.MaximumStorageQuotaMegabytes] + .Json(); }); }); From fca05188e1e068e84602b5ba31c0dc3479df87b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 21 Jul 2023 17:25:26 +0200 Subject: [PATCH 08/10] Moving trivial method to extension --- .../Service/IMediaStorageQuotaService.cs | 6 +++++- .../Service/MediaStorageQuotaService.cs | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs index 6dc5af45..7f089848 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs @@ -17,9 +17,13 @@ public interface IMediaStorageQuotaService /// Returns the maximum storage quota space in bytes. /// long MaxStorageQuotaForTenantInBytes(); +} +public static class MediaStorageQuotaServiceExtensions +{ /// /// Returns the maximum storage quota space in Megabytes. /// - float MaxStorageQuotaForTenantInMegabytes(); + public static float MaxStorageQuotaForTenantInMegabytes(this IMediaStorageQuotaService mediaStorageQuotaService) => + mediaStorageQuotaService.MaxStorageQuotaForTenantInBytes() / 1024f / 1024f; } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index 09733b10..30d81013 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -31,6 +31,4 @@ public async Task GetRemainingMediaStorageQuotaLeftAsync() } public long MaxStorageQuotaForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes; - - public float MaxStorageQuotaForTenantInMegabytes() => MaxStorageQuotaForTenantInBytes() / 1024f / 1024f; } From 632e47613012c8f3b6c45452d3af301d20c9226a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 21 Jul 2023 17:29:51 +0200 Subject: [PATCH 09/10] More renames --- .../Filters/MediaStorageQuotaActionFilter.cs | 2 +- .../Filters/UploadFileSizeShapeFilter.cs | 2 +- .../Service/IMediaStorageQuotaService.cs | 14 +++++++------- .../Service/MediaStorageQuotaService.cs | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs index 4eb52531..42cf1781 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs @@ -16,7 +16,7 @@ public async Task OnAuthorizationAsync(AuthorizationFilterContext context) .HttpContext .RequestServices .GetRequiredService() - .GetRemainingMediaStorageQuotaLeftAsync(); + .GetRemainingMediaStorageQuotaBytesAsync(); var formOptions = new FormOptions { diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs index 573652bc..dd200e84 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs @@ -45,7 +45,7 @@ actionRouteValue is nameof(AdminController.Index) && { var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Footer"]; - var maximumStorageQuotaMegabytes = _mediaStorageQuotaService.MaxStorageQuotaForTenantInMegabytes(); + var maximumStorageQuotaMegabytes = _mediaStorageQuotaService.GetMaxStorageQuotaMegabytes(); await contentZone.AddAsync(await _shapeFactory.CreateAsync( "UploadFileSize", viewModel => viewModel.MaximumStorageQuotaMegabytes = maximumStorageQuotaMegabytes)); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs index 7f089848..a092c35e 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs @@ -8,15 +8,15 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service; public interface IMediaStorageQuotaService { /// - /// Returns remaining storage quota space left in bytes. It is always a non-negative number, meaning the minimum - /// value is 0. + /// Returns the remaining storage space left from the quota in bytes. It is always a non-negative number, meaning + /// the minimum value is 0. /// - Task GetRemainingMediaStorageQuotaLeftAsync(); + Task GetRemainingMediaStorageQuotaBytesAsync(); /// - /// Returns the maximum storage quota space in bytes. + /// Returns the maximum storage space form the quota in bytes. /// - long MaxStorageQuotaForTenantInBytes(); + long GetMaxStorageQuotaBytes(); } public static class MediaStorageQuotaServiceExtensions @@ -24,6 +24,6 @@ public static class MediaStorageQuotaServiceExtensions /// /// Returns the maximum storage quota space in Megabytes. /// - public static float MaxStorageQuotaForTenantInMegabytes(this IMediaStorageQuotaService mediaStorageQuotaService) => - mediaStorageQuotaService.MaxStorageQuotaForTenantInBytes() / 1024f / 1024f; + public static float GetMaxStorageQuotaMegabytes(this IMediaStorageQuotaService mediaStorageQuotaService) => + mediaStorageQuotaService.GetMaxStorageQuotaBytes() / 1024f / 1024f; } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index 30d81013..06cbd9c7 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -19,16 +19,16 @@ public MediaStorageQuotaService( _mediaFileStore = mediaFileStore; } - public async Task GetRemainingMediaStorageQuotaLeftAsync() + public async Task GetRemainingMediaStorageQuotaBytesAsync() { var directoryContent = _mediaFileStore.GetDirectoryContentAsync(includeSubDirectories: true); var listed = await directoryContent.ToListAsync(); - var sumSize = listed.Where(item => item.Length > 0).Sum(item => item.Length); - var remainingStorageQuota = MaxStorageQuotaForTenantInBytes() - sumSize; + var sumBytes = listed.Where(item => item.Length > 0).Sum(item => item.Length); + var remainingStorageQuotaBytes = GetMaxStorageQuotaBytes() - sumBytes; - return remainingStorageQuota < 0 ? 0 : remainingStorageQuota; + return remainingStorageQuotaBytes < 0 ? 0 : remainingStorageQuotaBytes; } - public long MaxStorageQuotaForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes; + public long GetMaxStorageQuotaBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes; } From df49b1fa421e80a4f7e4e733d71b71f8e0525e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 21 Jul 2023 17:34:28 +0200 Subject: [PATCH 10/10] Syntax fix --- .../Views/UploadFileSize.cshtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml index 6d43e9fa..2d05c7bf 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml @@ -23,8 +23,7 @@ $(function () { model.errorMessage = @T[ "You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", - Model.MaximumStorageQuotaMegabytes] - .Json(); + Model.MaximumStorageQuotaMegabytes].Json(); }); });