protected internal IEnumerable <Claim> GetOrganizationClaims(string username)
        {
            var hasCentralAccess = _organizationUserQueryService.HasCentralAccess(username);

            if (hasCentralAccess)
            {
                yield return(new Claim(ReportingModuleClaimTypes.AccessAllOrganizations, True));
            }
            var organizationUsers = _organizationUserQueryService.GetByUsername(username).ToArray();
            var organizationRoles = new List <OrganizationRole>();
            var organizationIds   = new List <int>();

            foreach (var organizationUserViewModel in organizationUsers)
            {
                var managedOrganizationIds = _organizationQueryService.GetManagedOrganizationIds(organizationUserViewModel.Organization.Id);
                var orgIds = new[] { organizationUserViewModel.Organization.Id }.Concat(managedOrganizationIds).ToArray().Distinct().ToArray();
                organizationIds.AddRange(orgIds);
                organizationRoles.AddRange(orgIds.Select(o => new OrganizationRole {
                    Id = o, Role = organizationUserViewModel.Role
                }).ToArray());
            }
            yield return(new Claim(ReportingModuleClaimTypes.OrganizationAccess, string.Join("|", organizationIds.Distinct().ToArray())));

            var organizationRoleClaims = organizationRoles.Distinct()
                                         .OrderBy(o => o.Id)
                                         .ThenBy(o => o.Role)
                                         .Select(o => new Claim(ReportingModuleClaimTypes.OrganizationRole,
                                                                $"{o.Id}|{o.Role}")).ToArray();

            foreach (var claim in organizationRoleClaims)
            {
                yield return(claim);
            }
        }
 public SearchResult <ReportViewModel> Search(AllReportSearchTerms searchTerms)
 {
     return(_session.Query <ReportViewModel>()
            .ApplyOrganizationReferenceFilter(_userContext)
            .ApplyQuickSearch(searchTerms.QuickSearch)
            .ApplyTimestampFromSearch(searchTerms.TimestampFrom)
            .ApplyTimestampToSearch(searchTerms.TimestampTo)
            .ApplyReportingPeriodStartDateFromSearch(searchTerms.ReportingPeriodStartDateFrom)
            .ApplyReportingPeriodEndDateToSearch(searchTerms.ReportingPeriodEndDateTo)
            .ApplyReportStatusSearch(searchTerms.Status)
            .ApplyOrganizationTypeSearch(searchTerms.OrganizationalType)
            .ApplyReportingFrequencySearch(searchTerms.ReportingFrequency)
            .ApplyReportingTermSearch(searchTerms.ReportingTerm)
            .ApplyMyReportSearch(searchTerms.MyReports ? _organizationUserQueryService.GetByUsername(UserContext.GetLoggedInUsername()).Select(s => s.Organization.Id) : new int[0])
            .ApplyParentSearch(searchTerms.Parent, searchTerms.Parent.HasValue ?
                               _organizationQueryService.GetManagedOrganizationIds(searchTerms.Parent.Value)
             : new int[0])
            .ApplyOrganizationSearch(searchTerms.Organization)
            .OrderByDescending(o => o.ReportingPeriod.StartDate)
            .ThenBy(o => o.Organization.OrganizationType)
            .ThenBy(o => o.Organization.Description)
            .FetchSimpleSearchResult(searchTerms.PagingData ?? new PagingData(1, DefaultPageSize, 0)));
 }
Ejemplo n.º 3
0
        protected internal IEnumerable <Claim> GetOrganizationClaims(string username)
        {
            var organizationUsers = _organizationUserQueryService.GetByUsername(username).ToArray();

            var orgIds = organizationUsers.Select(o => o.Organization.Id).ToArray();

            yield return(new Claim(ReportingModuleClaimTypes.OrganizationAccess, string.Join("|", orgIds)));

            var organizationRoleClaims = organizationUsers.Select(o => new Claim(ReportingModuleClaimTypes.OrganizationRole,
                                                                                 $"{o.Organization.Id}|{o.Role}")).ToArray();

            foreach (var claim in organizationRoleClaims)
            {
                yield return(claim);
            }
        }