@aaron - The example document cited by @maliming in his first reply shows that code. I was NOT using that in version 6.3.1. That's what gave me that impression. Plus at this point I am just looking for help/direction to solve my issue. Is that too much to ask?
I did some more testing/debugging.
I applied the code to the UserClaimsPrincipalFactory with two claims.
public override async Task<ClaimsPrincipal> CreateAsync(User user)
{
var claim = await base.CreateAsync(user);
claim.Identities.First().AddClaim(new Claim("CompanyFilter", user.CompanyId.HasValue ? user.CompanyId.Value.ToString() : ""));
claim.Identities.First().AddClaim(new Claim("NurseHomeFilter", user.NurseHomeId.HasValue ? user.NurseHomeId.Value.ToString() : ""));
return claim;
}
In my DB Context, I have added these two methods. In debug, I dont see these methods execute.
protected virtual int? GetCurrentUsersCompanyIdOrNull()
{
var userOuClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == "CompanyFilter");
if (string.IsNullOrEmpty(userOuClaim?.Value))
{
return null;
}
return Convert.ToInt32(userOuClaim.Value);
}
protected virtual int? GetCurrentUsersNurseHomeIdOrNull()
{
var userOuClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == "NurseHomeFilter");
if (string.IsNullOrEmpty(userOuClaim?.Value))
{
return null;
}
return Convert.ToInt32(userOuClaim.Value);
}
In debug, i then checked the values of the filters when the "GetAll" repository method is called. They both have nothing?
> ? CurrentUnitOfWork.Filters
Count = 5
[0]: {Abp.Domain.Uow.DataFilterConfiguration}
[1]: {Abp.Domain.Uow.DataFilterConfiguration}
[2]: {Abp.Domain.Uow.DataFilterConfiguration}
[3]: {Abp.Domain.Uow.DataFilterConfiguration}
[4]: {Abp.Domain.Uow.DataFilterConfiguration}
> ? CurrentUnitOfWork.Filters[3]
{Abp.Domain.Uow.DataFilterConfiguration}
FilterName: "CompanyFilter"
FilterParameters: Count = 0
IsEnabled: true
> ? CurrentUnitOfWork.Filters[4]
{Abp.Domain.Uow.DataFilterConfiguration}
FilterName: "NurseHomeFilter"
FilterParameters: Count = 0
IsEnabled: true
It's going to take some time and effort for me to recreate in the demo project. I dont have time to do that right now.
Today, I went back to my V631 solution and retested my data filters there and it seems to be broken there too. Its working on one app service and MVC view but not on another. I dont know how this broke, I had tested all of my pages and services after I applied the changes. Now I'm more confused as to what the issue could be!
DB Context code:
protected override bool ShouldFilterEntity<TEntity>(IMutableEntityType entityType)
{
if (typeof(IHasCompany).IsAssignableFrom(typeof(TEntity)))
{
return true;
}
return false;
}
protected override Expression<Func<TEntity, bool>> CreateFilterExpression<TEntity>()
{
Expression<Func<TEntity, bool>> expression = null;
if (typeof(IHasCompany).IsAssignableFrom(typeof(TEntity)))
{
Expression<Func<TEntity, bool>> companyFilter = e => ((IHasCompany)e).CompanyId == CurrentCompanyId || (((IHasCompany)e).CompanyId == CurrentCompanyId) == IsCompanyFilterEnabled;
expression = expression == null ? companyFilter : CombineExpressions(expression, companyFilter);
}
return base.CreateFilterExpression<TEntity>();
}
App service method, where filter is enabled.
public async Task<PagedResultDto<GetHomeForView>> GetAll(GetAllHomesInput input)
{
using (CurrentUnitOfWork.EnableFilter(AppConsts.CompanyFilter))
{
using (CurrentUnitOfWork.SetFilterParameter(AppConsts.CompanyFilter, AppConsts.CompanyFilterParameter_CompanyId, GetCurrentUserCompany()))
{
//code removed
}
}
}
When I run my code in debug (see image below), I can see the filter being applied in the using statement and there is a value as well. Yet once it goes inside the method code block and query executes, its not filtering the data. All rows in the table are being returned. All this code works perfectly in V6.3.1 solution.
I had posted this question on Stackoverflow few months ago.. The accepted answer on that question was working for me and my app in ANZ Version 6.3.1. Yesterday I updated my entire ANZ solution to V6.6.1. That code is not working now.
On the documentation for data filters it shows the code example below.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Filter("PersonFilter", (IHasPerson entity, int personId) => entity.PersonId == personId, 0);
}
Do I need to use the code shown in the documentation? And does it apply to EF Core?
@clintoncherry - I tried your suggestion today, when I was deploying an update to my hosted app. It did not make any difference. After publishing both errors that I reported in my original post still happened.
I'm not asking you about a specific tool or plugins. I provided Google maps as an example. My question is a generic one. Where should I place scripts that are to be used in Modals before "show" event and after "show" event. As currently I'm getting different results from placing them in the model cshtml.
@ismcagdas - I have opened new issue # 2104
@ismcagdas - Can you respond to each of my questions and clarify the correct placement?
I am running into some errors/issues with my implementation of Google maps APIs in my app. Specifically with modals. On index pages, the google maps functions all work just fine. But once I move it into a modal, I run into issues.
My questions on scripts used for modals are as follows:
Q1. What is the best place to use/insert a JS script or JS code that needs to execute before the user sees the modal? Q2. Where should JS event functions, like the one shown below, be placed? These need to fire after the modal is open and the user takes action on a select1.
$("#Select1").change(function () {
Fill_Select2();
});
I typically place these types of functions/events directly in the modal.cshtml file at the very end, after all the HTML. These events dont always work when I place them in the createModal.js script files.
Q3. For google maps I need to place the below script entry, before I add my JS code, to make the maps work. I have added these into my modal.cshtml.
<script src="https://maps.googleapis.com/maps/api/js?key=XX" async defer></script>
However this leads to warnings/errors that I have loaded google maps API too many times. This happens as the user will enter/exit the modal multiple times from my index pages. So where would be the best place to add this script?