Skip to content

Commit

Permalink
Merge pull request #106 from Lombiq/issue/OSOE-751
Browse files Browse the repository at this point in the history
OSOE-751: Upgrade to Orchard Core 1.8
  • Loading branch information
Psichorex authored Feb 21, 2024
2 parents aed1116 + 37cd30c commit 3e640bc
Show file tree
Hide file tree
Showing 34 changed files with 133 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using OrchardCore.Modules;
using OrchardCore.Settings;
using OrchardCore.Users;
using System;
using System.Linq;
using System.Threading.Tasks;
using static Lombiq.Hosting.Tenants.Admin.Login.Constants.FeatureNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using OrchardCore.DisplayManagement.Layout;
using OrchardCore.Environment.Shell;
using OrchardCore.Environment.Shell.Models;
using OrchardCore.Modules;
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Tenants.Controllers;
using System;
using System.Threading.Tasks;

namespace Lombiq.Hosting.Tenants.Admin.Login.Filters;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**;Tests\**</DefaultItemExcludes>
</PropertyGroup>
Expand Down Expand Up @@ -34,18 +34,18 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.7.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.7.0" />
<PackageReference Include="OrchardCore.Tenants" Version="1.7.0" />
<PackageReference Include="OrchardCore.Users" Version="1.7.0" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.Tenants" Version="1.8.2" />
<PackageReference Include="OrchardCore.Users" Version="1.8.2" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
<ProjectReference Include="..\..\..\Libraries\Lombiq.HelpfulLibraries\Lombiq.HelpfulLibraries.OrchardCore\Lombiq.HelpfulLibraries.OrchardCore.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="8.0.3-alpha.0.lmbq-249" />
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="8.1.1-alpha.7.osoe-751" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Lombiq.Hosting.Tenants.Admin.Login/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Description = "Ability to log in as a tenant’s admin user.",
Category = "Hosting",
DefaultTenantOnly = true,
Dependencies = new[] { "OrchardCore.Tenants" }
Dependencies = ["OrchardCore.Tenants"]
)]

[assembly: Feature(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>

Expand Down Expand Up @@ -33,7 +33,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="8.1.0-alpha.1.osoe-638" />
<PackageReference Include="Lombiq.Tests.UI" Version="8.2.1-alpha.22.osoe-751" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>
Expand Down Expand Up @@ -34,16 +34,16 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Admin" Version="1.7.0" />
<PackageReference Include="OrchardCore.Email.Core" Version="1.7.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.7.0" />
<PackageReference Include="OrchardCore.AdminDashboard" Version="1.7.0" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.7.0" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.7.0" />
<PackageReference Include="OrchardCore.Email.Abstractions" Version="1.7.0" />
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="1.7.0" />
<PackageReference Include="OrchardCore.Admin" Version="1.8.2" />
<PackageReference Include="OrchardCore.Email.Core" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.AdminDashboard" Version="1.8.2" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Email.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="1.8.2" />
<PackageReference Include="Scrutor" Version="4.2.2" />
<PackageReference Include="YesSql.Abstractions" Version="3.3.0" />
<PackageReference Include="YesSql.Abstractions" Version="4.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand All @@ -52,7 +52,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="8.0.3-alpha.0.lmbq-249" />
<PackageReference Include="Lombiq.HelpfulExtensions" Version="7.0.2" />
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="8.1.1-alpha.7.osoe-751" />
<PackageReference Include="Lombiq.HelpfulExtensions" Version="7.0.3-alpha.4.osoe-751" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions Lombiq.Hosting.Tenants.EmailQuotaManagement/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
Name = "Lombiq Hosting - Tenants Email Quota Management",
Category = "Hosting",
IsAlwaysEnabled = true,
Dependencies = new[]
{
Dependencies =
[
"OrchardCore.Emails",
"Lombiq.HelpfulExtensions.Emails",
}
]
)]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OrchardCore.Data.Migration;
using System.Threading.Tasks;

namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Migrations;

Expand All @@ -14,19 +15,19 @@ public class EmailQuotaMigrations : DataMigration
#pragma warning restore CA1822 // Mark members as static
#pragma warning restore IDE0079 // Remove unnecessary suppression

public int UpdateFrom1()
public async Task<int> UpdateFrom1Async()
{
SchemaBuilder.AlterTable("EmailQuotaIndex", table => table
await SchemaBuilder.AlterTableAsync("EmailQuotaIndex", table => table
.AddColumn<int>("LastReminderPercentage")
);

return 2;
}

public int UpdateFrom2()
public async Task<int> UpdateFrom2Async()
{
// Deleting index because it is not needed.
SchemaBuilder.DropTable("EmailQuotaIndex");
await SchemaBuilder.DropTableAsync("EmailQuotaIndex");

return 3;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.BackgroundTasks;
using System;
using System.Threading;
Expand All @@ -15,6 +15,6 @@ public async Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToke
{
var emailQuotaService = serviceProvider.GetRequiredService<IEmailQuotaService>();
var currentQuota = await emailQuotaService.GetOrCreateCurrentQuotaAsync();
emailQuotaService.ResetQuota(currentQuota);
await emailQuotaService.ResetQuotaAsync(currentQuota);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -91,22 +91,22 @@ public async Task<EmailQuota> GetOrCreateCurrentQuotaAsync()
// Need to set default value otherwise the database might complain about being 01/01/0001 out of range.
LastReminderUtc = _clock.UtcNow.AddMonths(-1),
};
_session.Save(currentQuota);
await _session.SaveAsync(currentQuota);

return currentQuota;
}

public void IncreaseEmailUsage(EmailQuota emailQuota)
public Task IncreaseEmailUsageAsync(EmailQuota emailQuota)
{
emailQuota.CurrentEmailUsageCount++;
_session.Save(emailQuota);
return _session.SaveAsync(emailQuota);
}

public void SetQuotaOnEmailReminder(EmailQuota emailQuota)
public Task SetQuotaOnEmailReminderAsync(EmailQuota emailQuota)
{
emailQuota.LastReminderUtc = _clock.UtcNow;
emailQuota.LastReminderPercentage = emailQuota.CurrentUsagePercentage(GetEmailQuotaPerMonth());
_session.Save(emailQuota);
return _session.SaveAsync(emailQuota);
}

public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePercentage)
Expand All @@ -128,10 +128,10 @@ public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePerce
emailQuota.LastReminderPercentage >= 100);
}

public void ResetQuota(EmailQuota emailQuota)
public Task ResetQuotaAsync(EmailQuota emailQuota)
{
emailQuota.CurrentEmailUsageCount = 0;
_session.Save(emailQuota);
return _session.SaveAsync(emailQuota);
}

public int GetEmailQuotaPerMonth() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand Down Expand Up @@ -34,20 +34,20 @@ public interface IEmailQuotaService
/// <summary>
/// Increases the usage count of the given <paramref name="emailQuota"/> and saves it to the database.
/// </summary>
void IncreaseEmailUsage(EmailQuota emailQuota);
Task IncreaseEmailUsageAsync(EmailQuota emailQuota);

/// <summary>
/// Resets the given <paramref name="emailQuota"/> <see cref="EmailQuota.CurrentEmailUsageCount"/> to 0 and saves it
/// to the database.
/// </summary>
void ResetQuota(EmailQuota emailQuota);
Task ResetQuotaAsync(EmailQuota emailQuota);

/// <summary>
/// Sets the <see cref="EmailQuota.LastReminderUtc"/> to the current date and
/// <see cref="EmailQuota.LastReminderPercentage"/> to the current email quota usage percentage then saves it to the
/// database.
/// </summary>
void SetQuotaOnEmailReminder(EmailQuota emailQuota);
Task SetQuotaOnEmailReminderAsync(EmailQuota emailQuota);

/// <summary>
/// Returns <see langword="true"/>, if the reminder email should be sent.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.HelpfulExtensions.Extensions.Emails.Services;
using Lombiq.HelpfulExtensions.Extensions.Emails.Services;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using Microsoft.Extensions.Localization;
using OrchardCore.Email;
Expand Down Expand Up @@ -54,7 +54,7 @@ public async Task<SmtpResult> SendAsync(MailMessage message)
var emailResult = await _smtpService.SendAsync(message);
if (emailResult == SmtpResult.Success)
{
_emailQuotaService.IncreaseEmailUsage(isQuotaOverResult.EmailQuota);
await _emailQuotaService.IncreaseEmailUsageAsync(isQuotaOverResult.EmailQuota);
}

return emailResult;
Expand All @@ -68,7 +68,7 @@ private async Task SendAlertEmailIfNecessaryAsync(EmailQuota emailQuota)
var siteOwnerEmails = (await _emailQuotaService.GetUserEmailsForEmailReminderAsync()).ToList();
if (currentUsagePercentage >= 100)
{
SendQuotaEmail(
await SendQuotaEmailAsync(
emailQuota,
siteOwnerEmails,
"EmailQuotaExceededError",
Expand All @@ -77,15 +77,15 @@ private async Task SendAlertEmailIfNecessaryAsync(EmailQuota emailQuota)
return;
}

SendQuotaEmail(
await SendQuotaEmailAsync(
emailQuota,
siteOwnerEmails,
$"EmailQuotaWarning",
_emailQuotaSubjectService.GetWarningEmailSubject(currentUsagePercentage),
currentUsagePercentage);
}

private void SendQuotaEmail(
private Task SendQuotaEmailAsync(
EmailQuota emailQuota,
IEnumerable<string> siteOwnerEmails,
string emailTemplateName,
Expand Down Expand Up @@ -113,6 +113,6 @@ private void SendQuotaEmail(
});
}

_emailQuotaService.SetQuotaOnEmailReminder(emailQuota);
return _emailQuotaService.SetQuotaOnEmailReminderAsync(emailQuota);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="8.1.0-alpha.1.osoe-638" />
<PackageReference Include="Lombiq.Tests.UI" Version="8.2.1-alpha.22.osoe-751" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>
Expand Down Expand Up @@ -34,8 +34,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="1.7.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.7.0" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.7.0" />
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>

Expand Down Expand Up @@ -33,7 +33,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="8.1.0-alpha.1.osoe-638" />
<PackageReference Include="Lombiq.Tests.UI" Version="8.2.1-alpha.22.osoe-751" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private Task HandleConditionallyEnabledFeaturesAsync()
throw new InvalidOperationException("'IsAlwaysEnabled' feature can't be disabled by FeaturesGuard.");
}

if (!featuresToEnable.Any() && !featuresToDisable.Any())
if (featuresToEnable.Count == 0 && featuresToDisable.Count == 0)
{
return;
}
Expand All @@ -119,7 +119,7 @@ private Task HandleConditionallyEnabledFeaturesAsync()
/// </returns>
private static bool TryGetFeaturesToBeEnabledAndDisabled(
IDictionary<string, IEnumerable<string>> conditionallyEnabledFeatures,
IReadOnlySet<string> enabledFeatureIds,
HashSet<string> enabledFeatureIds,
out HashSet<string> featuresToEnable,
out HashSet<string> featuresToDisable)
{
Expand Down Expand Up @@ -152,6 +152,6 @@ private static bool TryGetFeaturesToBeEnabledAndDisabled(
featuresToEnable = featuresToEnableIds;
featuresToDisable = featuresToDisableIds;

return featuresToEnableIds.Any() || featuresToDisableIds.Any();
return featuresToEnableIds.Count != 0 || featuresToDisableIds.Count != 0;
}
}
Loading

0 comments on commit 3e640bc

Please sign in to comment.