| | | 1 | | using Chronicis.Api.Data; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | |
| | | 4 | | namespace Chronicis.Api.Services; |
| | | 5 | | |
| | | 6 | | public sealed class SummaryAccessService : ISummaryAccessService |
| | | 7 | | { |
| | | 8 | | private readonly ChronicisDbContext _context; |
| | | 9 | | private readonly IReadAccessPolicyService _readAccessPolicy; |
| | | 10 | | |
| | | 11 | | public SummaryAccessService(ChronicisDbContext context, IReadAccessPolicyService readAccessPolicy) |
| | | 12 | | { |
| | 4 | 13 | | _context = context; |
| | 4 | 14 | | _readAccessPolicy = readAccessPolicy; |
| | 4 | 15 | | } |
| | | 16 | | |
| | | 17 | | public async Task<bool> CanAccessArticleAsync(Guid articleId, Guid userId) |
| | | 18 | | { |
| | | 19 | | return await _readAccessPolicy |
| | | 20 | | .ApplyAuthenticatedWorldArticleFilter(_context.Articles, userId) |
| | | 21 | | .Where(a => a.Id == articleId) |
| | | 22 | | .AnyAsync(); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | public async Task<bool> CanAccessCampaignAsync(Guid campaignId, Guid userId) |
| | | 26 | | { |
| | | 27 | | return await _readAccessPolicy |
| | | 28 | | .ApplyAuthenticatedCampaignFilter(_context.Campaigns, userId) |
| | | 29 | | .Where(c => c.Id == campaignId) |
| | | 30 | | .AnyAsync(); |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | public async Task<bool> CanAccessArcAsync(Guid arcId, Guid userId) |
| | | 34 | | { |
| | | 35 | | return await _readAccessPolicy |
| | | 36 | | .ApplyAuthenticatedArcFilter(_context.Arcs, userId) |
| | | 37 | | .Where(a => a.Id == arcId) |
| | | 38 | | .AnyAsync(); |
| | | 39 | | } |
| | | 40 | | } |
| | | 41 | | |