Aktivity „tomcic“

v4.0.2, MVC

After logging in, I would like the application to check whether the user has completed the data, if not, I would like to hide some functions for him and force a redirection to the page with the form.

I added code to the test app (new clean app generated by apb suite).

I get an error:

System.InvalidOperationException: Nullable object must have a value. at System.Nullable`1.get_Value() at Volo.Abp.Users.CurrentUserExtensions.GetId(ICurrentUser currentUser) at TestApp.Web.PageFilters.UserInfoCheckPageFilter.OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) in D:\dotnet\testapp\src\TestApp.Web\PageFilters\UserInfoCheckPageFilter.cs:line 37 at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync() at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context) at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)

at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)

at Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<b__1>d.MoveNext()

--- End of stack trace from previous location --- at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IBackChannelLogoutService backChannelLogoutService) at IdentityServer4.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) at Volo.Abp.AspNetCore.MultiTenancy.MultiTenancyMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<b__1>d.MoveNext()

--- End of stack trace from previous location --- at Microsoft.AspNetCore.Builder.ApplicationBuilderAbpJwtTokenMiddlewareExtension.<>c__DisplayClass0_0.<b__0>d.MoveNext()

--- End of stack trace from previous location --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<b__1>d.MoveNext()

--- End of stack trace from previous location --- at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Otázka

v4.2.2 MVC EF Core Tiered: no

I would like to limit the visibility of some users' data to their data only (via appuserID or tenant) - how can I do this?

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v4.2.2.
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

How to set permissions to gain access for the user who has been assigned the permission WorkAppPermissions.WorkLogs.Default or WorkAppPermissions.WorkLogsPowerAdmin.Default ?

Thanks :)

namespace WorkApp.WorkLogs {

[Authorize(WorkAppPermissions.WorkLogs.Default)] OR [Authorize(WorkAppPermissions.WorkLogsPowerAdmin.Default)]                       //&lt;=================== pseudocode P1 OR P2

> public class WorkLogAppService : ApplicationService, IWorkLogAppService

{
    private readonly IWorkLogRepository _workLogRepository;
    private readonly IRepository&lt;AppUser, Guid&gt; _appUserRepository;

    public WorkLogAppService(IWorkLogRepository workLogRepository, IRepository&lt;AppUser, Guid&gt; appUserRepository)
    {
        _workLogRepository = workLogRepository; _appUserRepository = appUserRepository;
    }

    public virtual async Task&lt;PagedResultDto&lt;WorkLogWithNavigationPropertiesDto&gt;> GetListAsync(GetWorkLogsInput input)
    {
        var totalCount = await _workLogRepository.GetCountAsync(input.FilterText, input.Title, input.StartDateMin, input.StartDateMax, input.EndDateMin, input.EndDateMax, input.Description, input.AppUserId);
        var items = await _workLogRepository.GetListWithNavigationPropertiesAsync(input.FilterText, input.Title, input.StartDateMin, input.StartDateMax, input.EndDateMin, input.EndDateMax, input.Description, input.AppUserId, input.Sorting, input.MaxResultCount, input.SkipCount);

        return new PagedResultDto&lt;WorkLogWithNavigationPropertiesDto&gt;
        {
            TotalCount = totalCount,
            Items = ObjectMapper.Map&lt;List&lt;WorkLogWithNavigationProperties&gt;, List&lt;WorkLogWithNavigationPropertiesDto&gt;>(items)
        };
    }

    public virtual async Task&lt;WorkLogWithNavigationPropertiesDto&gt; GetWithNavigationPropertiesAsync(Guid id)
    {
        return ObjectMapper.Map&lt;WorkLogWithNavigationProperties, WorkLogWithNavigationPropertiesDto&gt;
            (await _workLogRepository.GetWithNavigationPropertiesAsync(id));
    }

    public virtual async Task&lt;WorkLogDto&gt; GetAsync(Guid id)
    {
        return ObjectMapper.Map&lt;WorkLog, WorkLogDto&gt;(await _workLogRepository.GetAsync(id));
    }

    public virtual async Task&lt;PagedResultDto&lt;LookupDto&lt;Guid?&gt;>> GetAppUserLookupAsync(LookupRequestDto input)
    {
        var query = _appUserRepository.AsQueryable()
            .WhereIf(!string.IsNullOrWhiteSpace(input.Filter),
                x => x.UserName != null &&
                     x.UserName.Contains(input.Filter));

        var lookupData = await query.PageBy(input.SkipCount, input.MaxResultCount).ToDynamicListAsync&lt;AppUser&gt;();
        var totalCount = query.Count();
        return new PagedResultDto&lt;LookupDto&lt;Guid?&gt;>
        {
            TotalCount = totalCount,
            Items = ObjectMapper.Map&lt;List&lt;AppUser&gt;, List&lt;LookupDto&lt;Guid?&gt;>>(lookupData)
        };
    }

    [Authorize(WorkAppPermissions.WorkLogs.Delete)]
    public virtual async Task DeleteAsync(Guid id)
    {
        await _workLogRepository.DeleteAsync(id);
    }

    [Authorize(WorkAppPermissions.WorkLogs.Create)]
    public virtual async Task&lt;WorkLogDto&gt; CreateAsync(WorkLogCreateDto input)
    {
        var workLog = ObjectMapper.Map&lt;WorkLogCreateDto, WorkLog&gt;(input);

        workLog = await _workLogRepository.InsertAsync(workLog, autoSave: true);
        return ObjectMapper.Map&lt;WorkLog, WorkLogDto&gt;(workLog);
    }

    [Authorize(WorkAppPermissions.WorkLogs.Edit)]
    public virtual async Task&lt;WorkLogDto&gt; UpdateAsync(Guid id, WorkLogUpdateDto input)
    {
        var workLog = await _workLogRepository.GetAsync(id);
        ObjectMapper.Map(input, workLog);
        workLog = await _workLogRepository.UpdateAsync(workLog);
        return ObjectMapper.Map&lt;WorkLog, WorkLogDto&gt;(workLog);
    }
}

}

I would like to give the entry owner permissions and the same permissions for all records to the administrator. In the code I want to include filter if LogPowerAdmin show all, if WorkLogs show only current user resources. Is this the right way?

If requester is an admin, get all the data from db; if a user, get only data that the user has created.

Exacly, this is what I want to do.

I would like to define Permissions:

        public static class WorkAppPermissions
        {
            public const string GroupName = "WorkApp";

            public static class Dashboard
            {
                public const string DashboardGroup = GroupName + ".Dashboard";
                public const string Host = DashboardGroup + ".Host";
                public const string Tenant = DashboardGroup + ".Tenant";
            }

            //Add your own permission names. Example:
            //public const string MyPermission1 = GroupName + ".MyPermission1";

            public class WorkLogs
            {
                public const string Default = GroupName + ".WorkLogs";
                public const string Edit = Default + ".Edit";
                public const string Create = Default + ".Create";
                public const string Delete = Default + ".Delete";
            }

            public class WorkLogsPowerAdmin
            {
                public const string Default = GroupName + ".WorkLogs";
                public const string Edit = Default + ".Edit";
                public const string Create = Default + ".Create";
                public const string Delete = Default + ".Delete";
            }
        }

To be able to use them when configuring the system in Identity Management -> Roles -> Permissions. Your solution severely limits configuration flexibility. In the domain layer, It should refer to Permissions, Roles should be remained flexible. Therefore, I would like to know how to handle this case in endpoint.

Odpoveď

1.I created a new project ( MVC - EF - 4.2.2)

  1. Add Identity module with source code

  2. On build I see error in d:\abptest2\src\Test.Domain.Shared\TestDomainSharedModule.cs(38,23): error CS0246: The type or namespace name "AbpIdentityProDomainSharedModule" could not be found (are you missing a using directive or an assembly reference?)[d:\abptest2\src\Test.Domain.Shared\Test.Domain.Shared.csproj]

Zobrazených 1 až 8 z 8 záznamov
Made with ❤️ on ABP v8.2.0-preview Updated on marca 25, 2024, 15:11