abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
13k stars 3.46k forks source link

Blazor Server App Tenant side /setting-management throw PermissionRequirement: FeatureManagement.ManageHostFeatures error #18759

Open cihangll opened 10 months ago

cihangll commented 10 months ago

Is there an existing issue for this?

Description

[20:15:05 INF] Authorization failed. These requirements were not met: PermissionRequirement: FeatureManagement.ManageHostFeatures [20:15:05 WRN] Unhandled exception rendering component: Sequence contains no elements System.InvalidOperationException: Sequence contains no elements at System.Linq.ThrowHelper.ThrowNoElementsException() at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at Volo.Abp.SettingManagement.Blazor.Pages.SettingManagement.SettingManagement.OnInitializedAsync() at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() [20:15:05 ERR] Unhandled exception in circuit 'i7fd8uxqZ3FbReH_DitNnYIt5f82XkVVB5irrEIahbk'. System.InvalidOperationException: Sequence contains no elements at System.Linq.ThrowHelper.ThrowNoElementsException() at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at Volo.Abp.SettingManagement.Blazor.Pages.SettingManagement.SettingManagement.OnInitializedAsync() at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() [20:15:05 WRN] Unhandled exception rendering component: Cannot access a disposed object. System.ObjectDisposedException: Cannot access a disposed object. at Microsoft.AspNetCore.Components.RenderTree.ArrayBuilder1.GrowBuffer(Int32 desiredCapacity) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange1 oldTree, ArrayRange`1 newTree) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException) at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue() [20:15:05 ERR] Unhandled exception in circuit 'i7fd8uxqZ3FbReH_DitNnYIt5f82XkVVB5irrEIahbk'. System.ObjectDisposedException: Cannot access a disposed object. ...

Reproduction Steps

1) Create blazor server project (abp new Acme.BookStore -u blazor-server) 2) Create tenant 3) Login with tenant user 4) Click setting section (/setting-management)

Expected behavior

Host side successfully goes to /setting-management. But tenant side not.

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

8.0.1

User Interface

Blazor Server

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

cihangll commented 10 months ago

https://github.com/abpframework/abp/blob/c18884a4316dd1e3448610f2acaf98e69e370365/modules/setting-management/src/Volo.Abp.SettingManagement.Blazor/Pages/SettingManagement/SettingManagement.razor.cs#L45C9-L45C23 line causes error. SelectedGroup = GetNormalizedString(SettingComponentCreationContext.Groups.First().Id); First().Id throws an error when the Groups count value is 0.

maliming commented 10 months ago

hi

Can you share the Reproduction Steps?

Thanks.

omer-repo commented 4 months ago

I'm using Blazor WebAssembly 8.0.2

I have same error and it didn't exist in the previous versions but I don't know when it started to cause error.

Normally, only host admin was able to see Setting link under the Management menu. Tenant admins were only able to see User/Identity Management under Management menu. But then, new tenants started to see "Setting" link also. (Old tenants still don't see)

maliming commented 4 months ago

hi @omer-repo

How can I reproduce your problem with a new template project?

omer-repo commented 4 months ago

hi @maliming I think I found the reason. Setting Management

The "Enable Setting Management" checkbox is unchecked for the previous tenants but it is checked for the new ones. But because of nothing of items under the setting management is checked by default, tenant admin gets error when clicked on the Setting Management (because there is no item to manage) If I select also "Allow changing email settings", tenant admin doesn't get an error and successfully see Setting Management page.

So, my question is now that: How can I make unchecked "Enable Setting Management" option for new tenants? Because I'm creating tenants with the code below. (For current tenants maybe I can remove something from PermissionGrants table)

var tenant = await TenantManager.CreateAsync(input.Name);
input.MapExtraPropertiesTo(tenant);

await TenantRepository.InsertAsync(tenant);

await CurrentUnitOfWork.SaveChangesAsync();

await DistributedEventBus.PublishAsync(
    new TenantCreatedEto
    {
        Id = tenant.Id,
        Name = tenant.Name,
        Properties =
        {
            { "AdminEmail", input.AdminEmailAddress },
            { "AdminPassword", input.AdminPassword }
        }
    });

using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
    //TODO: Handle database creation?
    // TODO: Seeder might be triggered via event handler.
    await DataSeeder.SeedAsync(
                    new DataSeedContext(tenant.Id)
                        .WithProperty("AdminEmail", input.AdminEmailAddress)
                        .WithProperty("AdminPassword", input.AdminPassword)
                    );

}
maliming commented 4 months ago

hi @cihangll

The default value has not changed for 3 years.

https://github.com/abpframework/abp/blame/dev/modules/setting-management/src/Volo.Abp.SettingManagement.Domain.Shared/Volo/Abp/SettingManagement/SettingManagementFeatureDefinitionProvider.cs#L17

The "Enable Setting Management" checkbox is unchecked for the previous tenants but it is checked for the new ones

I have no idea for this case.