Created
November 7, 2021 10:40
-
-
Save balteravishay/1c99a1cf9d478e10b046add66e6f35e3 to your computer and use it in GitHub Desktop.
Reader Access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace PMVProxy.API.Middleware | |
{ | |
using Hl7.Fhir.Model; | |
... | |
internal class OwnerAccess : IAccessByRole | |
{ | |
... | |
public async System.Threading.Tasks.Task Access<TResource>(TResource resource, | |
string userFhirId, IFhirService fhirService) where TResource : Resource | |
{ | |
var resourceId = $"{resource.TypeName}/{resource.Id}"; | |
if (await fhirService.ExistsAsync<Consent>(new string[] { | |
$"data={resourceId}" , $"actor={userFhirId}", "status=active"})) | |
{ | |
_logger.LogInformation($"user {userFhirId} has consent over resource {resource.Id}"); | |
return; | |
} | |
else | |
{ | |
_logger.LogWarning($"user {userFhirId} does not have consent to read {resource.Id}"); | |
throw new AuthorizationException("you do not have consent for this document"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment