Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-658: Rename MaximumSpace to MaximumSpaceBytes #79

Merged
merged 10 commits into from
Jul 21, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Constants;
namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Constants;

public static class MediaStorageManagementOptionsConstants
{
/// <summary>
/// Default MaximumStorageQuota in bytes representing 1GB.
/// Default maximum storage quota in bytes representing 1GB.
/// </summary>
public const long MaximumStorageQuota = 1_073_741_824;
public const long MaximumStorageQuotaBytes = 1_073_741_824;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<UploadFileSizeViewModel>(
"UploadFileSize",
viewModel => viewModel.MaximumSpace = maximumSpace));
viewModel => viewModel.MaximumSpaceBytes = maximumSpaceBytes));
}

await next();
Expand Down
4 changes: 2 additions & 2 deletions Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,7 +30,7 @@ public async Task<long> GetRemainingMediaSpaceQuotaLeftAsync()
return remainingSpace < 0 ? 0 : remainingSpace;
}

public long MaxSpaceForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuota;
public long MaxSpaceForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes;

public float MaxSpaceForTenantInMegabytes() => MaxSpaceForTenantInBytes() / 1024f / 1024f;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Settings;
namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Settings;

public class MediaStorageManagementOptions
{
/// <summary>
/// Gets or sets the maximum storage quota for a tenant in bytes. Default is 1GB.
/// </summary>
public long MaximumStorageQuota { get; set; }
public long MaximumStorageQuotaBytes { get; set; }
}
6 changes: 4 additions & 2 deletions Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public class Startup : StartupBase

public override void ConfigureServices(IServiceCollection services)
{
var maximumStorageQuota =
var maximumStorageQuotaBytes =
_shellConfiguration.GetValue<long?>(
"Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpaceBytes") ??
_shellConfiguration.GetValue<long?>(
"Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpace");
services.Configure<MediaStorageManagementOptions>(options =>
options.MaximumStorageQuota = maximumStorageQuota ?? MaximumStorageQuota);
options.MaximumStorageQuotaBytes = maximumStorageQuotaBytes ?? MaximumStorageQuotaBytes);
Piedone marked this conversation as resolved.
Show resolved Hide resolved

services.AddScoped<IMediaStorageQuotaService, MediaStorageQuotaService>();

Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Piedone marked this conversation as resolved.
Show resolved Hide resolved
});
});
</script>
Expand Down