Ejemplo n.º 1
0
        private async Task LoadSectionAsync(Proposal proposal, IFormSectionHandler sectionHandler)
        {
            var userId = _userManager.GetUserId(User);

            await sectionHandler.LoadAsync(this, proposal);

            var model = sectionHandler.GetModel(this);

            model.CanEdit = await AuthorizeAsync(proposal, FormSectionOperation.Edit(sectionHandler.ModelType));

            model.CanSubmit = await AuthorizeAsync(proposal, FormSectionOperation.Submit(sectionHandler.ModelType));

            model.CanRetract = await AuthorizeAsync(proposal, FormSectionOperation.Retract(sectionHandler.ModelType));

            model.Approvals = await proposal.Approvals
                              .Where(a => sectionHandler.HasApprovalAuthorityRole(a.AuthorityRole))
                              .ToAsyncEnumerable()
                              .SelectAwait(async approval =>
            {
                var authorities = await _authorityProvider.GetAuthoritiesByRoleAsync(proposal, approval.AuthorityRole);

                ProjectDbUser authority;
                if (approval.Status is ApprovalStatus.Approved or ApprovalStatus.Rejected)
                {
                    // Show authority who approved the section at the time as opposed to current approval role
                    authority = await _userManager.GetUserByIdAsync(approval.ValidatedBy);
                }
Ejemplo n.º 2
0
        private ICollection <IFormSectionHandler> InvalidateDependentSections(Proposal proposal, IFormSectionHandler sectionHandler)
        {
            IEnumerable <IFormSectionHandler> FindDependentSections(IFormSectionHandler section)
            {
                var dependentSections = _sectionHandlers
                                        .Where(h => h.NeedsApprovalBy(proposal).Any(section.HasApprovalAuthorityRole))
                                        .ToList();

                return(dependentSections.Concat(dependentSections.SelectMany(FindDependentSections)));
            }

            var invalidatedSections = FindDependentSections(sectionHandler)
                                      .Distinct()
                                      .Where(h => h.GetAssociatedApprovals(proposal).Any(a => a.Status != ApprovalStatus.NotSubmitted))
                                      .ToList();

            foreach (var approval in invalidatedSections.SelectMany(h => h.GetAssociatedApprovals(proposal)))
            {
                approval.Status      = ApprovalStatus.NotSubmitted;
                approval.ValidatedBy = null;
            }

            return(invalidatedSections);
        }