1.I created a new project ( MVC - EF - 4.2.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]
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.
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 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?
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.
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)] //<=================== pseudocode P1 OR P2
> public class WorkLogAppService : ApplicationService, IWorkLogAppService
{ private readonly IWorkLogRepository _workLogRepository; private readonly IRepository<AppUser, Guid> _appUserRepository; public WorkLogAppService(IWorkLogRepository workLogRepository, IRepository<AppUser, Guid> appUserRepository) { _workLogRepository = workLogRepository; _appUserRepository = appUserRepository; } public virtual async Task<PagedResultDto<WorkLogWithNavigationPropertiesDto>> 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<WorkLogWithNavigationPropertiesDto> { TotalCount = totalCount, Items = ObjectMapper.Map<List<WorkLogWithNavigationProperties>, List<WorkLogWithNavigationPropertiesDto>>(items) }; } public virtual async Task<WorkLogWithNavigationPropertiesDto> GetWithNavigationPropertiesAsync(Guid id) { return ObjectMapper.Map<WorkLogWithNavigationProperties, WorkLogWithNavigationPropertiesDto> (await _workLogRepository.GetWithNavigationPropertiesAsync(id)); } public virtual async Task<WorkLogDto> GetAsync(Guid id) { return ObjectMapper.Map<WorkLog, WorkLogDto>(await _workLogRepository.GetAsync(id)); } public virtual async Task<PagedResultDto<LookupDto<Guid?>>> 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<AppUser>(); var totalCount = query.Count(); return new PagedResultDto<LookupDto<Guid?>> { TotalCount = totalCount, Items = ObjectMapper.Map<List<AppUser>, List<LookupDto<Guid?>>>(lookupData) }; } [Authorize(WorkAppPermissions.WorkLogs.Delete)] public virtual async Task DeleteAsync(Guid id) { await _workLogRepository.DeleteAsync(id); } [Authorize(WorkAppPermissions.WorkLogs.Create)] public virtual async Task<WorkLogDto> CreateAsync(WorkLogCreateDto input) { var workLog = ObjectMapper.Map<WorkLogCreateDto, WorkLog>(input); workLog = await _workLogRepository.InsertAsync(workLog, autoSave: true); return ObjectMapper.Map<WorkLog, WorkLogDto>(workLog); } [Authorize(WorkAppPermissions.WorkLogs.Edit)] public virtual async Task<WorkLogDto> UpdateAsync(Guid id, WorkLogUpdateDto input) { var workLog = await _workLogRepository.GetAsync(id); ObjectMapper.Map(input, workLog); workLog = await _workLogRepository.UpdateAsync(workLog); return ObjectMapper.Map<WorkLog, WorkLogDto>(workLog); } }
}
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?
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)
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.