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
        public async Task <IActionResult> OnPostRetractAsync(int proposalId)
        {
            await TryUpdateModelAsync(RetractSection, nameof(RetractSection));

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var(proposal, error) = await LoadProposalAsync(proposalId);

            if (proposal == null)
            {
                return(error);
            }

            var sectionHandler = _sectionHandlers.Single(h => h.Id == RetractSection.Section);

            if (!await AuthorizeAsync(proposal, FormSectionOperation.Retract(sectionHandler.ModelType)))
            {
                return(Forbid());
            }

            foreach (var approval in sectionHandler.GetAssociatedApprovals(proposal))
            {
                approval.Status      = ApprovalStatus.NotSubmitted;
                approval.ValidatedBy = null;
            }

            InvalidateDependentSections(proposal, sectionHandler);

            await UpdateProposalAsync(proposal);

            return(RedirectToPage(null, null, new { proposalId }, RetractSection.Section));
        }