public async Task RemoveAsync(int mailId) { var authId = GetClaimId(ClaimType.UserId); var activeId = GetActiveUserId(); bool canDeleteAll = HasPermission(Permission.DeleteAnyMail); var mail = await _mailRepository.GetByIdAsync(mailId); if (mail == null) { _logger.LogInformation($"User {activeId} tried to remove {mailId} which doesn't exist."); return; } else { if (mail.ToUserId == activeId || canDeleteAll) { var siteId = GetCurrentSiteId(); if (mail.ToUserId != null) { _cache.Remove(UnreadMailCacheKey(siteId, (int)mail.ToUserId)); } else { _cache.Remove(UnhandledMailCount(siteId)); } await _mailRepository.RemoveSaveAsync(authId, mailId); return; } } _logger.LogError($"User {activeId} doesn't have permission remove mail {mailId}."); throw new GraException("Permission denied."); }
public async Task RemoveAsync(int mailId) { var authId = GetClaimId(ClaimType.UserId); var activeId = GetActiveUserId(); bool canDeleteAll = HasPermission(Permission.DeleteAnyMail); var mail = await _mailRepository.GetByIdAsync(mailId); if (mail.ToUserId == activeId || canDeleteAll) { if (mail.ToUserId != null) { _memoryCache.Remove($"{CacheKey.UserUnreadMailCount}?u{mail.ToUserId}"); } else { var siteId = GetCurrentSiteId(); _memoryCache.Remove($"{CacheKey.UnhandledMailCount}?s{siteId}"); } await _mailRepository.RemoveSaveAsync(authId, mailId); return; } _logger.LogError($"User {activeId} doesn't have permission remove mail {mailId}."); throw new Exception("Permission denied."); }