Activities of "lalitChougule"

Hi @muhammedaltug,

Thanks to answer my queries. I have few more requirement, and few previously unanswered questions and its related to same topic so posting it here itself.

  1. To hide password and username field from user creation form, Can it be done only by replacing the whole component or there is any other way around ? I don't want to replace whole component just for this small change.
  2. Just like what we do on backend i.e. override only particular method of service , can we do same for user.component ? i.e. in angular component ?
  3. Requirement : Once my user is created I want to redirect the user to my custom page.

Can all the above requirements can be done without replacing user.component ? If yes please guide me.

Thanks in advance !!!

Hi,

Why you can't access IIdentityRoleRepository? Can you explain the structure of your project

I think we are trying to access it in Application.Contracts thatz why its not accessible.

My Project structure

Gateway
	MainProject.HttpApi.Host
Microservices
	ProjectA.HttpApi.Host
	ProjectB.HttpApi.Host
	ProjectC.HttpApi.Host -- IdentityServer
	ProjectD.HttpApi.Host
Module
	ProjectA
		scr
			ProjectA.Application
			ProjectA.Application.Contracts
			ProjectA.Domain
			ProjectA.Domain.Shared
			ProjectA.EntityFrameworkCore
			ProjectA.HttpApi
			ProjectA.HttpApiClient
		test
			ProjectA.Application.Tests
			ProjectA.Domain.Tests
			ProjectA.EntityFrameworkCore.Tests
			ProjectA.HttpApiClient.ConsoleTestApp
			ProjectA.TestBase
	ProjectB
		src
			ProjectB.Application
			ProjectB.Application.Contracts
			ProjectB.Domain
			ProjectB.Domain.Shared
			ProjectB.EntityFrameworkCore
			ProjectB.HttpApi
			ProjectB.HttpApiClient
		test
			ProjectB.Application.Tests
			ProjectB.Domain.Tests
			ProjectB.EntityFrameworkCore.Tests
			ProjectB.HttpApiClient.ConsoleTestApp
			ProjectB.TestBase
	ProjectC
		src
			ProjectC.Application
			ProjectC.Application.Contracts
			ProjectC.Domain
			ProjectC.Domain.Shared
			ProjectC.EntityFrameworkCore
			ProjectC.HttpApi
			ProjectC.HttpApiClient
		test
			ProjectC.Application.Tests
			ProjectC.Domain.Tests
			ProjectC.EntityFrameworkCore.Tests
			ProjectC.HttpApiClient.ConsoleTestApp
			ProjectC.TestBase
	ProjectD
		src
			ProjectD.Application
			ProjectD.Application.Contracts
			ProjectD.Domain
			ProjectD.Domain.Shared
			ProjectD.EntityFrameworkCore
			ProjectD.HttpApi
			ProjectD.HttpApiClient
		test
			ProjectD.Application.Tests
			ProjectD.Domain.Tests
			ProjectD.EntityFrameworkCore.Tests
			ProjectD.HttpApiClient.ConsoleTestApp
			ProjectD.TestBase

The code which I am trying to do is in Module of Gateway project.

HI

It depends on where your dynamic permissions are stored. If your application is a monolithic application, you can consider try to inject the repository.

In short, don't call application services, because this will cause an infinite loop.

Ok I got your point. What are the other ways of access roles ? I dont want to access permissions. I want to access all roles.

I am not able to access IIdentityRoleRepository as well as IdentityRoleManager in the above code block.

hi

The application service will try to get all permissions when you call the its method, it will be an infinite loop.

So do not call application service in the Define method.

You can get dynamic permissions through other ways. Async methods are preferred.

Please provide sample code, What are the other ways and what do u mean by Sync methods are preferred ?

Hi @maliming

Error Log :

2021-05-27 11:18:46.476 +05:30 [ERR] ValueFactory attempted to access the Value property of this instance.
System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance.
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.get_PermissionDefinitions()
   at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.GetOrNull(String name)
   at Volo.Abp.Authorization.AbpAuthorizationPolicyProvider.GetPolicyAsync(String policyName)
   at Microsoft.AspNetCore.Authorization.AuthorizationPolicy.CombineAsync(IAuthorizationPolicyProvider policyProvider, IEnumerable`1 authorizeData)
   at Volo.Abp.Authorization.MethodInvocationAuthorizationService.CheckAsync(MethodInvocationAuthorizationContext context)
   at Volo.Abp.Authorization.AuthorizationInterceptor.AuthorizeAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Authorization.AuthorizationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
   at Nito.AsyncEx.AsyncContext.<>c__DisplayClass16_0`1.&lt;Run&gt;b__0(Task`1 t)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
   at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action)
   at Volo.Abp.Threading.AsyncHelper.RunSync[TResult](Func`1 func)
   at SCV.Litmus.Permissions.LitmusPermissionDefinitionProvider.GetRoles() in D:\Litmus\Projects\core-platform\SCV.Litmus\aspnet-core\modules\litmus-core\src\SCV.Litmus.Application.Contracts\Permissions\LitmusPermissionDefinitionProvider.cs:line 64
   at SCV.Litmus.Permissions.LitmusPermissionDefinitionProvider.Define(IPermissionDefinitionContext context) in D:\Litmus\Projects\core-platform\SCV.Litmus\aspnet-core\modules\litmus-core\src\SCV.Litmus.Application.Contracts\Permissions\LitmusPermissionDefinitionProvider.cs:line 57
   at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.CreatePermissionGroupDefinitions()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.CreatePermissionDefinitions()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.get_PermissionDefinitions()
   at Volo.Abp.Authorization.Permissions.PermissionDefinitionManager.GetPermissions()
   at Volo.Abp.Authorization.AbpAuthorizationPolicyProvider.GetPoliciesNamesAsync()
   at Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationAppService.GetAuthConfigAsync()
   at Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationAppService.GetAsync()
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationController.GetAsync()
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

My Code :

public class LitmusPermissionDefinitionProvider : PermissionDefinitionProvider
    {
        protected IServiceProvider _serviceProvider { get; }
        public LitmusPermissionDefinitionProvider(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        public override void Define(IPermissionDefinitionContext context)
        {
            var myGroup = context.AddGroup(LitmusPermissions.GroupName);

            var TestPermissionTestPermission = myGroup.AddPermission("TestRoles");
            var roles = GetRoles();
            foreach (var item in roles)
                TestPermissionTestPermission.AddChild(item);
        }

        private string[] GetRoles()
        {
            var result = AsyncHelper.RunSync(() => _serviceProvider.GetRequiredService<IIdentityRoleAppService>().GetAllListAsync());
            return result.Items.Select(x => x.Name).ToArray();
        }

        private static LocalizableString L(string name)
        {
            return LocalizableString.Create<LitmusResource>(name);
        }
    }

I tried your way, still stuck with same error. If I am doing it wrong way, please provide sample code.

Thanks

Can we use anything other or you can say customised alert message for UserFriendlyException warning box and on UI Information box based on fields for UI validation on user/role pages.:

Can you give more details or screenshots about this?

  • From server side error/warning/information we are using UserFriendlyException, I mean same for everything.Is there any other option available ? Like for informative message we don't wanna show error icon, For success we wanna show green check etc. and is there any way to customize it's height width or position.

  • I don't wanna show Organization Unit (Please refer to my orignal question where I have shared screenshot as well)

In Edit page, my user should not be able to change Roles, I mean I need to disabled all Assignable roles checkboxes.

Please reply to this query as well.

There should be FakeCurrentPrincipalAccessor.cs file in your TestBase project, we use it to mock user.

Also for data seeding, please check this documentation: https://docs.abp.io/en/abp/latest/Testing#the-seed-data

I got it GetPrincipal() method, but it has main admin. How do I use it in my case. I need to create more than 3-4 Unit test where each method have different login user with different case.

[Fact]
public async CheckForUser_1()
{
    using(user_1 logged in)
    {
        //my code
    }
}

[Fact]
public async CheckForUser_2()
{
    using(user_2 logged in)
    {
        //my code
    }
}

[Fact]
public async CheckForUser_3()
{
    using(user_3 logged in)
    {
        //my code
    }
}

[Fact]
public async CheckForUser_4()
{
    using(user_4 logged in)
    {
        //my code
    }
}

So where I have used using(user_1 logged in ) how can I use the method you mentioned ?

Hi @cotur,

I will try that. Please provide me solution for my second point as well.

User cases :

I have 2 users (user_1 and user_2), when I log with user_1 and create another user I check if my user is created by user_1 then I have some different action/code to be executed, and if my user_2 login I have to perform different action/code.This is just an example, but I hope u got my point.

Basic Requirement in Unit Test

I need to know how to I write test case where my user_1 is logged in and where my user_2 is logged in. And how do I seed IdentityUser i.e. AbpUsers table in test env with user_1 and user_2 details because as what I have learned there are more than one tables are involved as below:

  1. AbpUsers
  2. AbpUserRoles
  3. AbpRoles

etc etc How to I seed the above tables with my data.

Thanks

Hi @alper,

Thanks for the response.

I implemented your second approach, I customized code for the mentioned methods. It was just a POC for now, but in near future I have to develop full functionality. For now it's kinda configured via appsetting.json approach like if RoleA log's in he ill be able to see user's only under RoleA or which ever role the user is associated with. I want to make it more dynamic.

appsetting.json

"UserAccessControl": {
    "FetchUsersByClaims": [
      "SupplierAdmin"
    ],
    "UserCreationWithClaims": [
      "SupplierAdmin"
    ],
    "FetchUsersByRoles": {
      "admin": "AnchorAdmin",
      "AnchorAdmin": "SellerAdmin",
      "SupplierAdmin": "Supplier",
      "SellerAdmin": "Seller"
    },
    "CannotEditUserWithRoles": {
      "AnchorAdmin": "AnchorAdmin"
    },
    "CannotDeleteUserWithRoles": {
      "AnchorAdmin": "AnchorAdmin,SupplierAdmin"
    }
  }

Here as u see my config file in UserAccessControl a section called FetchUsersByRoles, here I have mentioned which If my logged in use if of role admin he can only get users of role AnchorAdmin.Likewise other sections.

This is where my config file have control, I want to give this control to my Admin user. I want to generate a screen and allow Admin himself to have a control over this.And in future we add new roles to our system, we can have control over them as well.

If you can simply proved any better approach to manage this requirement will be very helpfull.

There are few other new requirements including the above requirements as below :

  • The table in which we get user details in Administrator -> Identity -> User screen, currently we can see Action , UserName , EmailAddress and PhoneNumber. I want Action, UserName, RoleName of User, EmailAddress.
  • In the permission tree can we disable any permission check box as per roles, for example I have a role called Supplier and SupplierAdmin, So while my SupplierAdmin is creating any user of role Supplier he should be able to see all permission but few check box should be disabled, so that he cannot check that checkbox even if he wants to.
  • In User/Role table action button can we have any option called view where my user can see same page as edit page but all the fields should be disabled, user cannot edit or save anything.
  • While Creating any user we get password option, Is there any way where we hide that passowrd field and set default password for created user and when the user log's in for first time he should be asked to change the password.
  • Can we use anything other or you can say customised alert message for UserFriendlyException warning box and on UI Information box based on fields for UI validation on user/role pages.
  • In Edit page, my user should not be able to change Roles, I mean I need to disabled all Assignable roles checkboxes.

If these are not in abp features please let me know how to achieve this. Please try to answer all the above points and if possible please provide some details or sample code.

Thanks

Showing 41 to 50 of 80 entries
Made with ❤️ on ABP v9.2.0-preview. Updated on January 14, 2025, 14:54