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

Merge release/2.1 to main #17090

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Nightly (`main`):
[![Build status](https://github.com/OrchardCMS/OrchardCore/actions/workflows/preview_ci.yml/badge.svg)](https://github.com/OrchardCMS/OrchardCore/actions?query=workflow%3A%22Preview+-+CI%22)
[![Cloudsmith](https://api-prd.cloudsmith.io/badges/version/orchardcore/preview/nuget/OrchardCore.Application.Cms.Targets/latest/x/?render=true&badge_token=gAAAAABey9hKFD_C-ZIpLvayS3HDsIjIorQluDs53KjIdlxoDz6Ntt1TzvMNJp7a_UWvQbsfN5nS7_0IbxCyqHZsjhmZP6cBkKforo-NqwrH5-E6QCrJ3D8%3D)](https://cloudsmith.io/~orchardcore/repos/preview/packages/detail/nuget/OrchardCore.Application.Cms.Targets/latest/)

## Project Status: v2.1.1
## Project Status: v2.1.2

The software is production-ready, and capable of serving large mission-critical applications as well, and we're not aware of any fundamental bugs or missing features we deem crucial. Orchard Core continues to evolve, with each version bringing new improvements, and keeping up with the cutting-edge of .NET.

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ nav:
- Owners: resources/owners/README.md
- Workshops: resources/workshops/README.md
- Releases:
- 2.1.2: releases/2.1.2.md
- 2.1.1: releases/2.1.1.md
- 2.1.0: releases/2.1.0.md
- 2.0.2: releases/2.0.2.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ public async Task GenerateAsync(IUser user, ClaimsIdentity claims)
return;
}

var roleNames = await _userManager.GetRolesAsync(user);

var isAdministrator = false;

if (await _userManager.IsInRoleAsync(user, await _systemRoleNameProvider.GetAdminRoleAsync()))
foreach (var roleName in roleNames)
{
claims.AddClaim(StandardClaims.SiteOwner);

isAdministrator = true;
if (await _systemRoleNameProvider.IsAdminRoleAsync(roleName))
{
isAdministrator = true;
break;
}
}

var roleNames = await _userManager.GetRolesAsync(user);

foreach (var roleName in roleNames)
{
claims.AddClaim(new Claim(_identityOptions.ClaimsIdentity.RoleClaimType, roleName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Liquid.Abstractions\OrchardCore.Liquid.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Roles.Core\OrchardCore.Roles.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Settings.Core\OrchardCore.Settings.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Setup.Abstractions\OrchardCore.Setup.Abstractions.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using OrchardCore.Roles;
using OrchardCore.Security;

namespace OrchardCore.Settings.Services;
Expand All @@ -10,10 +11,14 @@ namespace OrchardCore.Settings.Services;
public class SuperUserHandler : IAuthorizationHandler
{
private readonly ISiteService _siteService;
private readonly ISystemRoleNameProvider _systemRoleNameProvider;

public SuperUserHandler(ISiteService siteService)
public SuperUserHandler(
ISiteService siteService,
ISystemRoleNameProvider systemRoleNameProvider)
{
_siteService = siteService;
_systemRoleNameProvider = systemRoleNameProvider;
}

public async Task HandleAsync(AuthorizationHandlerContext context)
Expand All @@ -25,7 +30,7 @@ public async Task HandleAsync(AuthorizationHandlerContext context)
return;
}

if (user.HasClaim(StandardClaims.SiteOwner.Type, StandardClaims.SiteOwner.Value))
if (user.IsInRole(await _systemRoleNameProvider.GetAdminRoleAsync()))
{
SucceedAllRequirements(context);

Expand Down
5 changes: 4 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Settings/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using OrchardCore.Recipes;
using OrchardCore.Recipes.Services;
using OrchardCore.ResourceManagement;
using OrchardCore.Roles;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings.Deployment;
using OrchardCore.Settings.Drivers;
Expand Down Expand Up @@ -65,7 +66,9 @@ public override void ConfigureServices(IServiceCollection services)

services.AddScoped<ISetupEventHandler, SetupEventHandler>();
services.AddPermissionProvider<Permissions>();
services.AddScoped<IAuthorizationHandler, SuperUserHandler>();

services.AddRolesCoreServices()
.AddScoped<IAuthorizationHandler, SuperUserHandler>();

services.AddRecipeExecutionStep<SettingsStep>();
services.AddSingleton<ISiteService, SiteService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<IActionResult> Index(string sitemapId, CancellationToken cance

document.Declaration = new XDeclaration("1.0", "utf-8", null);

using var stream = MemoryStreamFactory.GetStream();
var stream = MemoryStreamFactory.GetStream();
await document.SaveAsync(stream, SaveOptions.None, cancellationToken);

if (stream.Length >= ErrorLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public override async Task<IDisplayResult> UpdateAsync(User user, UpdateEditorCo
var userContext = new UserContext(user);
// TODO This handler should be invoked through the create or update methods.
// otherwise it will not be invoked when a workflow, or other operation, changes this value.
await _userEventHandlers.InvokeAsync((handler, context) => handler.DisabledAsync(userContext), userContext, _logger);
await _userEventHandlers.InvokeAsync((handler, context) => handler.DisabledAsync(context), userContext, _logger);
}
}
else if (!isEditingDisabled && model.IsEnabled && !user.IsEnabled)
Expand All @@ -135,7 +135,7 @@ public override async Task<IDisplayResult> UpdateAsync(User user, UpdateEditorCo
var userContext = new UserContext(user);
// TODO This handler should be invoked through the create or update methods.
// otherwise it will not be invoked when a workflow, or other operation, changes this value.
await _userEventHandlers.InvokeAsync((handler, context) => handler.EnabledAsync(userContext), userContext, _logger);
await _userEventHandlers.InvokeAsync((handler, context) => handler.EnabledAsync(context), userContext, _logger);
}

if (context.Updater.ModelState.IsValid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OrchardCore.Liquid;
using OrchardCore.Security;
using OrchardCore.Roles;
using OrchardCore.Security.Permissions;

namespace OrchardCore.Users.Liquid;

public static class UserFilters
{
public static ValueTask<FluidValue> HasClaim(FluidValue input, FilterArguments arguments, TemplateContext ctx)
public static async ValueTask<FluidValue> HasClaim(FluidValue input, FilterArguments arguments, TemplateContext ctx)
{
if (input.ToObjectValue() is LiquidUserAccessor)
{
var context = (LiquidTemplateContext)ctx;
var httpContextAccessor = context.Services.GetRequiredService<IHttpContextAccessor>();
var systemRoleNameProvider = context.Services.GetRequiredService<ISystemRoleNameProvider>();

var user = httpContextAccessor.HttpContext?.User;
if (user != null)
Expand Down Expand Up @@ -45,7 +46,7 @@ public static ValueTask<FluidValue> HasClaim(FluidValue input, FilterArguments a
// {% assign isAuthorized = User | has_permission: "AccessAdminPanel" %}
// ```
if (string.Equals(claimType, Permission.ClaimType, StringComparison.OrdinalIgnoreCase) &&
user.HasClaim(StandardClaims.SiteOwner.Type, StandardClaims.SiteOwner.Value))
user.IsInRole(await systemRoleNameProvider.GetAdminRoleAsync()))
{
var logger = context.Services.GetRequiredService<ILogger<Startup>>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.Extensions.Caching.Distributed;
using OrchardCore.Users.Handlers;

namespace OrchardCore.Users.TimeZone.Handlers;

public class UserEventHandler : UserEventHandlerBase
{
private const string CacheKey = "UserTimeZone/";

private readonly IDistributedCache _distributedCache;

public UserEventHandler(IDistributedCache distributedCache)
{
_distributedCache = distributedCache;
}

public override Task DeletedAsync(UserDeleteContext context)
=> ForgetCacheAsync(context.User.UserName);

public override Task UpdatedAsync(UserUpdateContext context)
=> ForgetCacheAsync(context.User.UserName);

public override Task DisabledAsync(UserContext context)
=> ForgetCacheAsync(context.User.UserName);

private Task ForgetCacheAsync(string userName)
{
var key = GetCacheKey(userName);

return _distributedCache.RemoveAsync(key);
}

internal static string GetCacheKey(string userName)
=> CacheKey + userName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
using Microsoft.Extensions.Caching.Distributed;
using OrchardCore.Entities;
using OrchardCore.Modules;
using OrchardCore.Users.Handlers;
using OrchardCore.Users.Models;
using OrchardCore.Users.TimeZone.Handlers;
using OrchardCore.Users.TimeZone.Models;

namespace OrchardCore.Users.TimeZone.Services;

public class UserTimeZoneService : UserEventHandlerBase, IUserTimeZoneService
public class UserTimeZoneService : IUserTimeZoneService
{
private const string CacheKey = "UserTimeZone/";
private const string EmptyTimeZone = "NoTimeZoneFound";

private static readonly DistributedCacheEntryOptions _slidingExpiration = new()
Expand Down Expand Up @@ -47,7 +46,6 @@ public async ValueTask<ITimeZone> GetAsync(string userName)
return _clock.GetTimeZone(currentTimeZoneId);
}


/// <inheritdoc/>
public ValueTask<ITimeZone> GetAsync(IUser user)
=> GetAsync(user?.UserName);
Expand All @@ -59,7 +57,7 @@ public async ValueTask UpdateAsync(IUser user)
/// <inheritdoc/>
private async ValueTask<string> GetTimeZoneIdAsync(string userName)
{
var key = GetCacheKey(userName);
var key = UserEventHandler.GetCacheKey(userName);

var timeZoneId = await _distributedCache.GetStringAsync(key);

Expand Down Expand Up @@ -95,22 +93,10 @@ private async ValueTask<string> GetTimeZoneIdAsync(string userName)
return timeZoneId;
}

public override Task DeletedAsync(UserDeleteContext context)
=> ForgetCacheAsync(context.User.UserName);

public override Task UpdatedAsync(UserUpdateContext context)
=> ForgetCacheAsync(context.User.UserName);

public override Task DisabledAsync(UserContext context)
=> ForgetCacheAsync(context.User.UserName);

private Task ForgetCacheAsync(string userName)
{
var key = GetCacheKey(userName);
var key = UserEventHandler.GetCacheKey(userName);

return _distributedCache.RemoveAsync(key);
}

private static string GetCacheKey(string userName)
=> CacheKey + userName;
}
6 changes: 3 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OrchardCore.Users.Handlers;
using OrchardCore.Users.Models;
using OrchardCore.Users.TimeZone.Drivers;
using OrchardCore.Users.TimeZone.Handlers;
using OrchardCore.Users.TimeZone.Services;

namespace OrchardCore.Users.TimeZone;
Expand All @@ -13,10 +14,9 @@ public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IUserTimeZoneService, UserTimeZoneService>();
services.AddScoped<IUserEventHandler, UserEventHandler>();
services.AddScoped<ITimeZoneSelector, UserTimeZoneSelector>();
services.AddScoped<UserTimeZoneService>();
services.AddScoped<IUserTimeZoneService>(sp => sp.GetRequiredService<UserTimeZoneService>());
services.AddScoped<IUserEventHandler>(sp => sp.GetRequiredService<UserTimeZoneService>());
services.AddDisplayDriver<User, UserTimeZoneDisplayDriver>();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Security.Claims;
using System.Security.Claims;

namespace OrchardCore.Security;

Expand All @@ -7,5 +7,6 @@ public static class StandardClaims
/// <summary>
/// This claim is assigned by the system during the login process if the user belongs to the Administrator role.
/// </summary>
[Obsolete("This claim is obsolete and will be removed in the next major version.")]
public static readonly Claim SiteOwner = new("SiteOwner", "true");
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace OrchardCore.Roles;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddRolesCoreServices(this IServiceCollection services)
{
return services.AddSingleton<ISystemRoleNameProvider, DefaultSystemRoleNameProvider>();
services.TryAddSingleton<ISystemRoleNameProvider, DefaultSystemRoleNameProvider>();

return services;
}
}
2 changes: 1 addition & 1 deletion src/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Orchard Core CMS supports all major site building strategies:

## Status

The latest released version of Orchard Core is `2.1.1`. The release notes can be found under [Releases](releases/2.1.1.md).
The latest released version of Orchard Core is `2.1.2`. The release notes can be found under [Releases](releases/2.1.2.md).

## Getting Started

Expand Down
8 changes: 4 additions & 4 deletions src/docs/getting-started/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ More information about `dotnet new` can be found at <https://docs.microsoft.com/
Once the .NET Core SDK has been installed, type the following command to install the templates for creating Orchard Core web applications:

```CMD
dotnet new install OrchardCore.ProjectTemplates::2.1.1
dotnet new install OrchardCore.ProjectTemplates::2.1.2
```

This will use the most stable release of Orchard Core. In order to use the latest `main` branch of Orchard Core, the following command can be used:

```CMD
dotnet new install OrchardCore.ProjectTemplates::2.1.1-* --nuget-source https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json
dotnet new install OrchardCore.ProjectTemplates::2.1.2-* --nuget-source https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json
```

## Create a new website
Expand Down Expand Up @@ -44,7 +44,7 @@ Options:

-ov|--orchard-version Specifies which version of Orchard Core packages to use.
string - Optional
Default: 2.1.1
Default: 2.1.2
```

Logging can be ignored with this command:
Expand Down Expand Up @@ -133,7 +133,7 @@ Options:

-ov|--orchard-version Specifies which version of Orchard Core packages to use.
string - Optional
Default: 2.1.1
Default: 2.1.2
```

```CMD
Expand Down
6 changes: 3 additions & 3 deletions src/docs/guides/add-admin-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ There are different ways to create sites and modules for Orchard Core. You can l

You can install the latest released templates using this command:

```dotnet new install OrchardCore.ProjectTemplates::2.1.1-*```
```dotnet new install OrchardCore.ProjectTemplates::2.1.2-*```

!!! note
To use the development branch of the template add `--nuget-source https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json`
Expand All @@ -40,10 +40,10 @@ The next step is to reference the module from the application, by adding a proje

We also need a reference to the `OrchardCore.Admin` package in order to be able to implement the required interfaces:

```dotnet add .\MyModule\MyModule.csproj package OrchardCore.Admin --version 2.1.1-*```
```dotnet add .\MyModule\MyModule.csproj package OrchardCore.Admin --version 2.1.2-*```

!!! note
To use the development branch of the template add ` --source https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json --version 2.1.1-*`
To use the development branch of the template add ` --source https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json --version 2.1.2-*`

## Adding our controller and views

Expand Down
2 changes: 1 addition & 1 deletion src/docs/guides/create-blazor-cms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ In our `OCBlazorLib` blazor Library project, Let's enrich our `/content` page to
- In `OCBlazorLib.csproj` Add a NuGet package reference to `OrchardCore.ContentManagement`

```dotnetcli
dotnet add ./OCBlazorLib/OCBlazorLib.csproj package OrchardCore.ContentManagement --version 2.1.1
dotnet add ./OCBlazorLib/OCBlazorLib.csproj package OrchardCore.ContentManagement --version 2.1.2
```

- Add the following `using` statements in `_Imports.razor`
Expand Down
2 changes: 1 addition & 1 deletion src/docs/guides/create-cms-application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There are different ways to create sites and modules for Orchard Core. You can l

In this guide we will use our "Code Generation Templates". You can install the latest stable release of the templates using this command:

```dotnet new install OrchardCore.ProjectTemplates::2.1.1-*```
```dotnet new install OrchardCore.ProjectTemplates::2.1.2-*```

!!! note
To use the development branch of the template add `--nuget-source https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json`.
Expand Down
2 changes: 1 addition & 1 deletion src/docs/guides/create-modular-application-mvc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ There are different ways to create sites and modules for Orchard Core. You can l

In this guide we will use our [Code Generation Templates](../../getting-started/templates/README.md). You can install the latest stable release of the templates using this command:

```dotnet new install OrchardCore.ProjectTemplates::2.1.1-*```
```dotnet new install OrchardCore.ProjectTemplates::2.1.2-*```

!!! note
To use the development branch of the template add `--nuget-source https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json`
Expand Down
Loading
Loading