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-751: Upgrade to Orchard Core 1.8 #106

Merged
merged 27 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5c282ed
Upgrading to .NET 8 and OC 1.8.2
Psichorex Jan 18, 2024
d12a9f2
Addressing warnings.
Psichorex Jan 19, 2024
5addb2e
Addressing warnings.
Psichorex Jan 20, 2024
d514b83
Fixing.
Psichorex Jan 28, 2024
5a47e81
Keeping T.
Psichorex Jan 29, 2024
856c0fb
Keeping T.
Psichorex Jan 29, 2024
16918b8
Removing fields.
Psichorex Jan 29, 2024
1597f4c
Keeping H.
Psichorex Jan 29, 2024
8dea136
Adding comment.
Psichorex Jan 29, 2024
3e9780d
Adding comment.
Psichorex Jan 29, 2024
f8f8e01
Merge remote-tracking branch 'origin/dev' into issue/OSOE-751
Psichorex Jan 30, 2024
71ca884
Revert "Addressing warnings."
Psichorex Jan 30, 2024
6253c59
Fixes.
Psichorex Jan 30, 2024
98f029c
Fixes.
Psichorex Jan 30, 2024
e4c85a7
Removing workaround.
Psichorex Jan 30, 2024
53112a5
Update Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilt…
Psichorex Feb 1, 2024
6c17a34
Minor fixing.
Psichorex Feb 1, 2024
9837aa1
Merge remote-tracking branch 'origin/dev' into issue/OSOE-751
Piedone Feb 5, 2024
1269e6e
Upgrading MS package.
Psichorex Feb 6, 2024
198405f
Merge branch 'issue/OSOE-751' of https://github.com/Lombiq/Hosting-Te…
Psichorex Feb 6, 2024
215068a
Merge remote-tracking branch 'origin/dev' into issue/OSOE-751
Psichorex Feb 13, 2024
72f87fa
Using issue branch reference.
Psichorex Feb 16, 2024
aab34c3
Using alpha.
Psichorex Feb 17, 2024
697fae6
Using alphas.
Psichorex Feb 18, 2024
97cc946
Updating UITT alpha.
Psichorex Feb 20, 2024
ef7c66d
Using new UITT alpha.
Psichorex Feb 21, 2024
37cd30c
Reverting to dev reference.
Psichorex Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -18,45 +17,29 @@
namespace Lombiq.Hosting.Tenants.Admin.Login.Controllers;

[Feature(SubTenant)]
public class TenantLoginController : Controller
public class TenantLoginController(
ISiteService siteService,
SignInManager<IUser> userSignInManager,
IShellHost shellHost,
ShellSettings shellSettings,
ILogger<TenantLoginController> logger,
INotifier notifier,
IHtmlLocalizer<TenantLoginController> htmlLocalizer) : Controller
{
private readonly ISiteService _siteService;
private readonly SignInManager<IUser> _userSignInManager;
private readonly IShellHost _shellHost;
private readonly ShellSettings _shellSettings;
private readonly ILogger _logger;
private readonly INotifier _notifier;
private readonly IHtmlLocalizer H;

public TenantLoginController(
ISiteService siteService,
SignInManager<IUser> userSignInManager,
IShellHost shellHost,
ShellSettings shellSettings,
ILogger<TenantLoginController> logger,
INotifier notifier,
IHtmlLocalizer<TenantLoginController> htmlLocalizer)
{
_siteService = siteService;
_userSignInManager = userSignInManager;
_shellHost = shellHost;
_shellSettings = shellSettings;
_logger = logger;
_notifier = notifier;
H = htmlLocalizer;
}
private readonly ILogger _logger = logger;
private readonly IHtmlLocalizer H = htmlLocalizer;

[HttpPost]
// This is necessary because requests for this action will come from the Default tenant.
[IgnoreAntiforgeryToken]
public async Task<IActionResult> Index(string password)
{
if (_shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName))
if (shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName))
{
return NotFound();
}

var defaultShell = await _shellHost.GetScopeAsync(ShellSettings.DefaultShellName);
var defaultShell = await shellHost.GetScopeAsync(ShellSettings.DefaultShellName);
var tenantLoginPasswordValidator = defaultShell?.ServiceProvider.GetService<ITenantLoginPasswordValidator>();

if (defaultShell == null ||
Expand All @@ -66,17 +49,17 @@ public async Task<IActionResult> Index(string password)
return NotFound();
}

var sitesettings = await _siteService.LoadSiteSettingsAsync();
var adminUser = await _userSignInManager.UserManager.FindByIdAsync(sitesettings.SuperUser);
adminUser ??= (await _userSignInManager.UserManager.GetUsersInRoleAsync(Administrator)).FirstOrDefault();
var sitesettings = await siteService.LoadSiteSettingsAsync();
var adminUser = await userSignInManager.UserManager.FindByIdAsync(sitesettings.SuperUser);
adminUser ??= (await userSignInManager.UserManager.GetUsersInRoleAsync(Administrator)).FirstOrDefault();

if (adminUser == null)
{
await _notifier.ErrorAsync(H["No user with administrator role in this tenant."]);
await notifier.ErrorAsync(H["No user with administrator role in this tenant."]);
return Redirect("~/");
}

await _userSignInManager.SignInAsync(adminUser, isPersistent: false);
await userSignInManager.SignInAsync(adminUser, isPersistent: false);
_logger.LogInformation(1, "An admin user logged in from the Default tenant.");

return RedirectToAction("Index", "Admin", new { area = "OrchardCore.Admin" });
Expand Down
39 changes: 12 additions & 27 deletions Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,20 @@
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;

public class TenantsIndexFilter : IAsyncResultFilter
public class TenantsIndexFilter(
ILayoutAccessor layoutAccessor,
IShapeFactory shapeFactory,
IShellHost shellHost,
IHttpContextAccessor hca,
IAuthorizationService authorizationService) : IAsyncResultFilter
{
private readonly ILayoutAccessor _layoutAccessor;
private readonly IShapeFactory _shapeFactory;
private readonly IShellHost _shellHost;
private readonly IHttpContextAccessor _hca;
private readonly IAuthorizationService _authorizationService;

public TenantsIndexFilter(
ILayoutAccessor layoutAccessor,
IShapeFactory shapeFactory,
IShellHost shellHost,
IHttpContextAccessor hca,
IAuthorizationService authorizationService)
{
_layoutAccessor = layoutAccessor;
_shapeFactory = shapeFactory;
_shellHost = shellHost;
_hca = hca;
_authorizationService = authorizationService;
}

public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
var actionRouteController = context.ActionDescriptor.RouteValues["Controller"];
Expand All @@ -46,20 +31,20 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE
actionRouteArea == $"{nameof(OrchardCore)}.{nameof(OrchardCore.Tenants)}" &&
actionRouteValue is nameof(AdminController.Edit) &&
context.Result is ViewResult &&
await _authorizationService.AuthorizeAsync(
_hca.HttpContext.User,
await authorizationService.AuthorizeAsync(
hca.HttpContext.User,
TenantAdminPermissions.LoginAsAdmin)
)
{
var shellSettings = _shellHost.GetSettings(context.RouteData.Values["Id"].ToString());
var shellSettings = shellHost.GetSettings(context.RouteData.Values["Id"].ToString());
if (shellSettings != null &&
shellSettings.State == TenantState.Running &&
!shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName))
{
var layout = await _layoutAccessor.GetLayoutAsync();
var layout = await layoutAccessor.GetLayoutAsync();
var contentZone = layout.Zones["Content"];
await contentZone.AddAsync(
await _shapeFactory.CreateAsync("TenantAdminShape", new
await shapeFactory.CreateAsync("TenantAdminShape", new
{
shellSettings.RequestUrlHost,
shellSettings.RequestUrlPrefix,
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,10 +34,10 @@
</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'">
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,11 @@

namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters;

public class DashboardQuotaFilter : IAsyncResultFilter
public class DashboardQuotaFilter(
IShapeFactory shapeFactory,
ILayoutAccessor layoutAccessor,
IEmailQuotaService emailQuotaService) : IAsyncResultFilter
{
private readonly IShapeFactory _shapeFactory;
private readonly ILayoutAccessor _layoutAccessor;
private readonly IEmailQuotaService _emailQuotaService;

public DashboardQuotaFilter(
IShapeFactory shapeFactory,
ILayoutAccessor layoutAccessor,
IEmailQuotaService emailQuotaService)
{
_shapeFactory = shapeFactory;
_layoutAccessor = layoutAccessor;
_emailQuotaService = emailQuotaService;
}

public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
if (!context.IsAdmin())
Expand All @@ -32,19 +21,19 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE
}

if (context.Result is ViewResult &&
_emailQuotaService.ShouldLimitEmails())
emailQuotaService.ShouldLimitEmails())
{
var currentEmailQuota = await _emailQuotaService.IsQuotaOverTheLimitAsync();
var currentEmailQuota = await emailQuotaService.IsQuotaOverTheLimitAsync();

var currentUsagePercentage = currentEmailQuota.EmailQuota
.CurrentUsagePercentage(_emailQuotaService.GetEmailQuotaPerMonth());
.CurrentUsagePercentage(emailQuotaService.GetEmailQuotaPerMonth());

if (currentUsagePercentage >= 80)
{
var layout = await _layoutAccessor.GetLayoutAsync();
var layout = await layoutAccessor.GetLayoutAsync();
var contentZone = layout.Zones["Messages"];
await contentZone.AddAsync(
await _shapeFactory.CreateAsync("DashboardQuotaMessage", new
await shapeFactory.CreateAsync("DashboardQuotaMessage", new
{
currentEmailQuota.IsOverQuota,
UsagePercentage = currentUsagePercentage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,11 @@

namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters;

public class EmailSettingsQuotaFilter : IAsyncResultFilter
public class EmailSettingsQuotaFilter(
IShapeFactory shapeFactory,
ILayoutAccessor layoutAccessor,
IEmailQuotaService emailQuotaService) : IAsyncResultFilter
{
private readonly IShapeFactory _shapeFactory;
private readonly ILayoutAccessor _layoutAccessor;
private readonly IEmailQuotaService _emailQuotaService;

public EmailSettingsQuotaFilter(
IShapeFactory shapeFactory,
ILayoutAccessor layoutAccessor,
IEmailQuotaService emailQuotaService)
{
_shapeFactory = shapeFactory;
_layoutAccessor = layoutAccessor;
_emailQuotaService = emailQuotaService;
}

public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
if (!context.IsAdmin())
Expand All @@ -43,17 +32,17 @@ actionRouteValue is nameof(AdminController.Index) &&
context.Result is ViewResult &&
context.RouteData.Values.TryGetValue("GroupId", out var groupId) &&
(string)groupId == "email" &&
_emailQuotaService.ShouldLimitEmails())
emailQuotaService.ShouldLimitEmails())
{
var layout = await _layoutAccessor.GetLayoutAsync();
var layout = await layoutAccessor.GetLayoutAsync();
var contentZone = layout.Zones["Content"];

var quota = await _emailQuotaService.GetOrCreateCurrentQuotaAsync();
var quota = await emailQuotaService.GetOrCreateCurrentQuotaAsync();
await contentZone.AddAsync(
await _shapeFactory.CreateAsync("EmailSettingsQuotaMessage", new
await shapeFactory.CreateAsync("EmailSettingsQuotaMessage", new
{
quota.CurrentEmailUsageCount,
EmailQuotaPerMonth = _emailQuotaService.GetEmailQuotaPerMonth(),
EmailQuotaPerMonth = emailQuotaService.GetEmailQuotaPerMonth(),
}),
"0");
}
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,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 Down
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);
}
}
Loading