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

Corrects the mapping of types to features in ITypeFeatureProvider #15793

Merged
merged 31 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0ca7aae
Update type mappings in TypeFeatureProvider when the service collecti…
gvkries Apr 19, 2024
f0834d1
Remove unnecessary FeatureEntry type.
gvkries Apr 19, 2024
7f5352d
Moves populating the `ITypeFeatureProvider` completely into the `Shel…
gvkries Apr 20, 2024
3202617
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries Apr 22, 2024
3350463
Merge branch 'gvkries/di-dependencies-15782' of https://github.com/gv…
gvkries Apr 22, 2024
b65b1e0
Fixes unit tests.
gvkries Apr 22, 2024
6e509a6
Changes the `ITypeFeatureProvider` to allow types that are used by mu…
gvkries Apr 23, 2024
4ed7ab8
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries Apr 23, 2024
1a74496
Added a basic unit test.
gvkries Apr 23, 2024
2a71dfe
Merge branch 'main' into gvkries/di-dependencies-15782
Piedone May 2, 2024
4b20596
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries May 6, 2024
8d78e67
Update src/OrchardCore/OrchardCore/Extensions/ExtensionManager.cs
gvkries May 6, 2024
18812a7
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries May 15, 2024
b93df1c
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries May 16, 2024
a4a3c85
Adds GetFeatureForDependency() back and also introduces GetExtensionF…
gvkries May 16, 2024
471c62a
Formatting.
gvkries May 16, 2024
b6ec58e
Apply suggestions from code review
gvkries May 17, 2024
ca4e21b
React to code review.
gvkries May 17, 2024
85b9421
Suggestions from code review applied.
gvkries May 17, 2024
2335466
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries May 17, 2024
58fe1e6
Removes the FeatureAttribute from classes that are now automatically …
gvkries May 17, 2024
1c0d8a3
Typo
gvkries May 17, 2024
c4e8a3e
Check if feature is enabled when displaying permissions registered fo…
gvkries May 17, 2024
b6a988a
Added FeatureAttribute back for some classes that should belong to th…
gvkries May 17, 2024
ed7f37e
Use the last enabled feature instead of the first one in the permissi…
gvkries May 19, 2024
3cb2504
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries May 19, 2024
4439345
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries May 23, 2024
e73cb94
Update AdminController.cs
sebastienros May 23, 2024
a6bd9cd
Update src/OrchardCore/OrchardCore.Abstractions/Extensions/Features/I…
sebastienros May 23, 2024
c8d9db7
Merge branch 'main' into gvkries/di-dependencies-15782
gvkries May 24, 2024
5037727
minor cleanup and add documentation
MikeAlhayek May 24, 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 @@ -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
Piedone marked this conversation as resolved.
Show resolved Hide resolved
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));
sebastienros marked this conversation as resolved.
Show resolved Hide resolved

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
Loading