Closed
Description
Description
I'm wondering if there is a seam / extensibility point where I can enforce filtering of returned data regardless if it's a primary call for that entity or if it's included with another entity.
For instance, I have an Identifiable of type "Org" and tried filtering the returned entities based upon the user's permissions. Works great, but if I make a primary request of say, UserProfile and include=org, this code doesn't get hit. (AuthorizedRepository<> inherits from EntityFrameworkCoreRepository<>)
public class OrgRepository : AuthorizedRepository<Org>
{
public OrgRepository(ITargetedFields targetedFields,
IDbContextResolver contextResolver,
IResourceGraph resourceGraph,
IGenericServiceFactory genericServiceFactory,
IResourceFactory resourceFactory,
IEnumerable<IQueryConstraintProvider> constraintProviders,
ILoggerFactory loggerFactory,
ICurrentUserAuthorizationService authService
)
: base(targetedFields, contextResolver, resourceGraph, genericServiceFactory, resourceFactory, constraintProviders, loggerFactory, authService)
{
}
protected override IQueryable<Org> GetAll()
{
var query = base.GetAll();
var authRestricted = base.HasAccess(Policies.CanGetAllRestricted<Org>())
|| base.HasAccess(Policies.CanGetByIdRestricted<Org>());
var authUnrestricted = base.HasAccess(Policies.CanGetAllUnrestricted<Org>())
|| base.HasAccess(Policies.CanGetByIdUnrestricted<Org>());
if (authRestricted)
{
return query.Where(i => i.Id == AuthService.User.OrgId());
}
else if (authUnrestricted)
{
return query;
}
// no auth at all - auth is enforced on controller as well - just extra defensive
throw new JsonApiException(new Error(HttpStatusCode.Unauthorized)
{
Title = "Unauthorized to retrieve Org"
});
}
}
Environment
- JsonApiDotNetCore Version: master branch as of 11/15/20 - was using beta1 nuget, but needed the bug fix for #671
- Other Relevant Package Versions: