Skip to content

Commit

Permalink
Corrects the mapping of types to features in ITypeFeatureProvider (#1…
Browse files Browse the repository at this point in the history
…5793)

---------

Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
Co-authored-by: Mike Alhayek <mike@crestapps.com>
Co-authored-by: Sébastien Ros <sebastienros@gmail.com>
  • Loading branch information
4 people authored May 24, 2024
1 parent 98bca75 commit 95bbd6d
Show file tree
Hide file tree
Showing 44 changed files with 279 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
using Microsoft.Extensions.Logging;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Data.Migration;
using OrchardCore.Modules;
using YesSql.Sql;

namespace OrchardCore.ContentFields.Indexing.SQL
{
[Feature("OrchardCore.ContentFields.Indexing.SQL")]
public class Migrations : DataMigration
{
private readonly ILogger _logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Threading.Tasks;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Data.Migration;
using OrchardCore.Modules;
using YesSql.Sql;

namespace OrchardCore.ContentFields.Indexing.SQL
{
[Feature("OrchardCore.ContentFields.Indexing.SQL.UserPicker")]
public class UserPickerMigrations : DataMigration
{
public async Task<int> CreateAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.ContentLocalization.Drivers;
using OrchardCore.Modules;
using OrchardCore.Navigation;

namespace OrchardCore.ContentLocalization
{
[Feature("OrchardCore.ContentLocalization.ContentCulturePicker")]
public class AdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _providersRouteValues = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
using OrchardCore.Data.Migration;
using OrchardCore.Deployment;
using OrchardCore.Entities;
using OrchardCore.Modules;
using OrchardCore.Recipes;
using OrchardCore.Recipes.Services;
using OrchardCore.Settings;

namespace OrchardCore.Contents.Deployment.ExportContentToDeploymentTarget
{
[Feature("OrchardCore.Contents.Deployment.ExportContentToDeploymentTarget")]
public class ExportContentToDeploymentTargetMigrations : DataMigration
{
private readonly IRecipeMigrator _recipeMigrator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
using OrchardCore.Facebook.Login.Services;
using OrchardCore.Facebook.Login.Settings;
using OrchardCore.Facebook.Settings;
using OrchardCore.Modules;

namespace OrchardCore.Facebook.Login.Configuration
{
[Feature(FacebookConstants.Features.Login)]
public class FacebookLoginConfiguration :
IConfigureOptions<AuthenticationOptions>,
IConfigureNamedOptions<FacebookOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
using OrchardCore.DisplayManagement.Implementation;
using OrchardCore.Facebook.Widgets.ViewModels;
using OrchardCore.Liquid;
using OrchardCore.Modules;

namespace OrchardCore.Facebook.Widgets.Services;

[Feature(FacebookConstants.Features.Widgets)]
public class LiquidShapes(HtmlEncoder htmlEncoder) : ShapeTableProvider
{
private readonly HtmlEncoder _htmlEncoder = htmlEncoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Data.Migration;
using OrchardCore.Facebook.Widgets.Models;
using OrchardCore.Modules;
using OrchardCore.Recipes;
using OrchardCore.Recipes.Services;

namespace OrchardCore.Facebook.Widgets
{
[Feature(FacebookConstants.Features.Widgets)]
public class WidgetMigrations : DataMigration
{
private readonly IRecipeMigrator _recipeMigrator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.Modules;
using OrchardCore.Navigation;

namespace OrchardCore.GitHub
{
[Feature(GitHubConstants.Features.GitHubAuthentication)]
public class AdminMenuGitHubLogin : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.Modules;
using OrchardCore.Navigation;

namespace OrchardCore.Google
{
[Feature(GoogleConstants.Features.GoogleAuthentication)]
public class GoogleAuthenticationAdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down Expand Up @@ -46,7 +44,6 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
}
}

[Feature(GoogleConstants.Features.GoogleAnalytics)]
public class GoogleAnalyticsAdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down Expand Up @@ -85,7 +82,6 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
}
}

[Feature(GoogleConstants.Features.GoogleTagManager)]
public class GoogleTagManagerAdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
using Microsoft.Extensions.Options;
using OrchardCore.Environment.Cache;
using OrchardCore.Media.Services;
using OrchardCore.Modules;
using OrchardCore.Security.Permissions;

namespace OrchardCore.Media
{
[Feature("OrchardCore.Media.Security")]
public class SecureMediaPermissions : IPermissionProvider
{
// Note: The ManageMediaFolder permission grants all access, so viewing must be implied by it too.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.Modules;
using OrchardCore.Navigation;

namespace OrchardCore.Microsoft.Authentication
{
[Feature(MicrosoftAuthenticationConstants.Features.MicrosoftAccount)]
public class AdminMenuMicrosoftAccount : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down Expand Up @@ -46,7 +44,6 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
}
}

[Feature(MicrosoftAuthenticationConstants.Features.AAD)]
public class AdminMenuAAD : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OrchardCore.Environment.Shell;
using OrchardCore.Modules;
using OrchardCore.OpenId.Services;
using OrchardCore.OpenId.Settings;

namespace OrchardCore.OpenId.Configuration
{
[Feature(OpenIdConstants.Features.Client)]
public class OpenIdClientConfiguration :
IConfigureOptions<AuthenticationOptions>,
IConfigureNamedOptions<OpenIdConnectOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
using OpenIddict.Server.AspNetCore;
using OpenIddict.Server.DataProtection;
using OrchardCore.Environment.Shell;
using OrchardCore.Modules;
using OrchardCore.OpenId.Services;
using OrchardCore.OpenId.Settings;
using static OpenIddict.Abstractions.OpenIddictConstants;

namespace OrchardCore.OpenId.Configuration
{
[Feature(OpenIdConstants.Features.Server)]
public class OpenIdServerConfiguration : IConfigureOptions<AuthenticationOptions>,
IConfigureOptions<OpenIddictServerOptions>,
IConfigureOptions<OpenIddictServerDataProtectionOptions>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
using OpenIddict.Validation.DataProtection;
using OrchardCore.Environment.Shell;
using OrchardCore.Environment.Shell.Scope;
using OrchardCore.Modules;
using OrchardCore.OpenId.Services;
using OrchardCore.OpenId.Settings;
using OrchardCore.Security;
using SystemEnvironment = System.Environment;
using static OpenIddict.Abstractions.OpenIddictConstants;
using SystemEnvironment = System.Environment;

namespace OrchardCore.OpenId.Configuration
{
[Feature(OpenIdConstants.Features.Validation)]
public class OpenIdValidationConfiguration : IConfigureOptions<AuthenticationOptions>,
IConfigureOptions<OpenIddictValidationOptions>,
IConfigureOptions<OpenIddictValidationDataProtectionOptions>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Environment.Extensions;
using OrchardCore.Environment.Extensions.Features;
using OrchardCore.Environment.Shell;
using OrchardCore.Roles.ViewModels;
using OrchardCore.Security;
using OrchardCore.Security.Permissions;
Expand All @@ -28,8 +29,10 @@ public class AdminController : Controller
private readonly IAuthorizationService _authorizationService;
private readonly IEnumerable<IPermissionProvider> _permissionProviders;
private readonly ITypeFeatureProvider _typeFeatureProvider;
private readonly IShellFeaturesManager _shellFeaturesManager;
private readonly IRoleService _roleService;
private readonly INotifier _notifier;

protected readonly IStringLocalizer S;
protected readonly IHtmlLocalizer H;

Expand All @@ -39,6 +42,7 @@ public AdminController(
IAuthorizationService authorizationService,
IEnumerable<IPermissionProvider> permissionProviders,
ITypeFeatureProvider typeFeatureProvider,
IShellFeaturesManager shellFeaturesManager,
IRoleService roleService,
INotifier notifier,
IStringLocalizer<AdminController> stringLocalizer,
Expand All @@ -49,6 +53,7 @@ public AdminController(
_authorizationService = authorizationService;
_permissionProviders = permissionProviders;
_typeFeatureProvider = typeFeatureProvider;
_shellFeaturesManager = shellFeaturesManager;
_roleService = roleService;
_notifier = notifier;
S = stringLocalizer;
Expand Down Expand Up @@ -241,9 +246,15 @@ private RoleEntry BuildRoleEntry(IRole role)
private async Task<IDictionary<PermissionGroupKey, IEnumerable<Permission>>> GetInstalledPermissionsAsync()
{
var installedPermissions = new Dictionary<PermissionGroupKey, IEnumerable<Permission>>();
var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

foreach (var permissionProvider in _permissionProviders)
{
var feature = _typeFeatureProvider.GetFeatureForDependency(permissionProvider.GetType());
// Two features could use the same permission.
var feature = _typeFeatureProvider
.GetFeaturesForDependency(permissionProvider.GetType())
.LastOrDefault(feature => enabledFeatures.Any(enabledFeature => feature.Id == enabledFeature.Id));

var permissions = await permissionProvider.GetPermissionsAsync();

foreach (var permission in permissions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private async Task UpdateRolesForInstalledFeatureAsync(IFeatureInfo feature)
_installedFeatures.Add(feature.Id);

var providers = _permissionProviders
.Where(provider => _typeFeatureProvider.GetFeatureForDependency(provider.GetType()).Id == feature.Id);
.Where(provider => _typeFeatureProvider.GetFeaturesForDependency(provider.GetType()).Any(p => p.Id == feature.Id));

if (!providers.Any())
{
Expand Down Expand Up @@ -98,7 +98,7 @@ private async Task UpdateRolesForEnabledFeatureAsync(IFeatureInfo feature)
}

var providers = _permissionProviders
.Where(provider => _typeFeatureProvider.GetFeatureForDependency(provider.GetType()).Id == feature.Id);
.Where(provider => _typeFeatureProvider.GetFeaturesForDependency(provider.GetType()).Any(p => p.Id == feature.Id));

if (!providers.Any())
{
Expand Down Expand Up @@ -144,8 +144,8 @@ private async Task UpdateRoleForInstalledFeaturesAsync(string roleName)

// And defining at least one 'IPermissionProvider'.
rolesDocument.MissingFeaturesByRole[roleName] = (await _extensionManager.LoadFeaturesAsync(missingFeatures))
.Where(entry => entry.ExportedTypes.Any(type => type.IsAssignableTo(typeof(IPermissionProvider))))
.Select(entry => entry.FeatureInfo.Id)
.Where(entry => _typeFeatureProvider.GetTypesForFeature(entry).Any(type => type.IsAssignableTo(typeof(IPermissionProvider))))
.Select(entry => entry.Id)
.ToList();

await _documentManager.UpdateAsync(rolesDocument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Descriptors;
using OrchardCore.DisplayManagement.Shapes;
using OrchardCore.Modules;

namespace OrchardCore.Search.Lucene
{
[Feature("OrchardCore.Search.Lucene.ContentPicker")]
public class LuceneContentPickerShapeProvider : IShapeAttributeProvider
{
protected readonly IStringLocalizer S;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Descriptors;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Modules;
using OrchardCore.Tenants.ViewModels;

namespace OrchardCore.Tenants.Services;

[Feature("OrchardCore.Tenants.FeatureProfiles")]
public class TenantFeatureProfileShapeTableProvider : ShapeTableProvider
{
public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.Modules;
using OrchardCore.Navigation;

namespace OrchardCore.Twitter
{
[Feature(TwitterConstants.Features.Signin)]
public class AdminMenuSignin : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down Expand Up @@ -45,7 +43,6 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
}
}

[Feature(TwitterConstants.Features.Twitter)]
public class AdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down
4 changes: 0 additions & 4 deletions src/OrchardCore.Modules/OrchardCore.Users/AdminMenu.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.Modules;
using OrchardCore.Navigation;
using OrchardCore.Users.Drivers;
using OrchardCore.Users.Models;
Expand Down Expand Up @@ -55,7 +54,6 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
}
}

[Feature("OrchardCore.Users.ChangeEmail")]
public class ChangeEmailAdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down Expand Up @@ -93,7 +91,6 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
}
}

[Feature(UserConstants.Features.UserRegistration)]
public class RegistrationAdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down Expand Up @@ -131,7 +128,6 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
}
}

[Feature(UserConstants.Features.ResetPassword)]
public class ResetPasswordAdminMenu : INavigationProvider
{
private static readonly RouteValueDictionary _routeValues = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
using OrchardCore.DisplayManagement.Entities;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Modules;
using OrchardCore.Settings;
using OrchardCore.Users.Models;

namespace OrchardCore.Users.Drivers
{
[Feature("OrchardCore.Users.ChangeEmail")]
public class ChangeEmailSettingsDisplayDriver : SectionDisplayDriver<ISite, ChangeEmailSettings>
{
public const string GroupId = "userChangeEmail";
Expand Down
Loading

0 comments on commit 95bbd6d

Please sign in to comment.