2

Ich arbeite an einem Projekt, das mit ASP.NET Boilerplate erstellt wird. Die Vorlage, die ich verwende, ist .NET Core mit Angular, einschließlich Module Zero. Mandantenfähigkeit ist aktiviert.Wie können Mieterbenutzer mit einer bestimmten Rolle vom Host aufgelistet werden?

Die Aufgabe, an der ich gerade arbeite, besteht darin, Administratoren des Hosts das Anzeigen von Benutzern mit der Rolle Admin von jedem Mandanten zu ermöglichen. Ich habe einen neuen Menüeintrag im Popup-Menü (Spalte Actions) in der Liste Mieter hinzugefügt. Es ruft eine API-Methode auf und übergibt die tenantId.

Der API-Code sieht wie folgt aus (in Anlehnung an Standardcode-Muster):

if (tenantId != null) 
{ 
    UnitOfWorkManager.Current.SetTenantId(tenantId.Value); 

    adminRole = await _roleManager.GetRoleByNameAsync("admin"); 
} 

if (tenantId != null && adminRole != null) 
{ 
    users = users.Where(u => u.Roles.Any(r => r.RoleId == adminRole.Id)); 
} 

var totalCount = await AsyncQueryableExecuter.CountAsync(users); 

users = ApplySorting(users, input); 

users = ApplyPaging(users, input); 

In der Anwendung ich eine Mietermix haben. Einige haben ihre eigene Datenbank und andere nicht. Der obige Code funktioniert wie erwartet, wenn der Mandant über eine eigene separate Datenbank verfügt, während bei Mandanten, die dies nicht tun, eine Fehlermeldung angezeigt wird:

Erforderliche Berechtigungen werden nicht gewährt. Mindestens eines dieser Rechte muss gewährt werden: Benutzer

In der Log-Datei, ich habe die folgende Ausnahme:

 
WARN 2017-11-23 10:37:23,101 [45] Mvc.ExceptionHandling.AbpExceptionFilter - Required permissions are not granted. At least one of these permissions must be granted: Users 
Abp.Authorization.AbpAuthorizationException: Required permissions are not granted. At least one of these permissions must be granted: Users 
at Abp.Authorization.PermissionCheckerExtensions.d__9.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Authorization\PermissionCheckerExtensions.cs:line 195 
--- End of stack trace from previous location where exception was thrown ---at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Abp.Authorization.AuthorizationHelper.d__19.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationHelper.cs:line 48 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Abp.Authorization.AuthorizationHelper.d__22.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationHelper.cs:line 98 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Abp.Authorization.AuthorizationHelper.d__20.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationHelper.cs:line 57 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) 
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) 
at Nito.AsyncEx.AsyncContext.Run(Func'1 action) at Abp.Authorization.AuthorizationInterceptor.Intercept(IInvocation invocation) 
in D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationInterceptor.cs:line 20 
at Castle.DynamicProxy.AbstractInvocation.Proceed() 
at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 68 
at Castle.DynamicProxy.AbstractInvocation.Proceed() 
at Castle.DynamicProxy.AbstractInvocation.Proceed() 
at Castle.DynamicProxy.AbstractInvocation.Proceed() 
at Castle.Proxies.UserAppServiceProxy.ApplySorting(IQueryable'1 query, PagedResultRequestDto input) 
at CK.Users.UserAppService.d__16.MoveNext() in D:\Projects\CK\Development\aspnet-core\src\CK.Application\Users\UserAppService.cs:line 179 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at lambda_method(Closure , Object) 
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() 
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__10.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) 
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) 
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__23.MoveNext() 

Frage ist, warum hat die gleiche Code Arbeit mit Mietern, die ihre eigene Datenbank, aber mit anderen bekomme ich eine Ausnahme? Und was muss ich tun, damit ich diesen Code unabhängig von der Einrichtung des Mandanten verwenden kann?

Alle Vorschläge sind willkommen.

Grüße, Alex

+0

Es funktioniert. Danke. Kannst du das als Antwort posten, damit ich es annehmen kann? Einziger Unterschied ist, dass ich [AbpAllowAnonymous] zuordnen musste. – Alex

Antwort

2

Es scheint, dass AuthorizationInterceptor unnötig ApplySorting Verfahren ab.

können Sie sicher, dass die Methode mit dem Attribut [AbpAllowAnonymous] außer Kraft setzen:

[AbpAllowAnonymous] 
protected override IQueryable<User> ApplySorting(IQueryable<User> query, UserGetAllInput input) 
{ 
    return base.ApplySorting(query, input); 
} 
Verwandte Themen