public void ShouldValidateReportViewAuthority(bool isHasAuthority) { const long userId = 4234; long?projectId = 4233123; var report = new Reports { IsSystem = false, ProjectId = projectId }; _userAuthorityValidator .Setup(_ => _.HasUserAuthorities(userId, new[] { Authorities.UI.Reports.View }, projectId)) .Returns(isHasAuthority); var result = _target.CanView(userId, report); result.ShouldBeEquivalentTo(isHasAuthority); }
public IQueryable <Reports> GetUserQuery() { var userId = _userPrincipal.Info.Id; var projectIds = _reportAuthorityValidator.GetProjects(userId, ReportAccessType.View); var projectReports = _reportRepository.Get(projectIds); var userReportIds = new List <long>(); foreach (var projectReport in projectReports) { if (_reportAuthorityValidator.CanView(userId, projectReport)) { userReportIds.Add(projectReport.Id); } } return(_reportRepository.Query() .Where(_ => userReportIds.Contains(_.Id))); }