예제 #1
0
        private static void UpdateRequireESignature(ReviewType reviewType, ReviewSettings updatedReviewSettings, ReviewPackageRawData reviewRawData)
        {
            var settingChanged = (!reviewRawData.IsESignatureEnabled.HasValue && updatedReviewSettings.RequireESignature) ||
                                 (reviewRawData.IsESignatureEnabled.HasValue && reviewRawData.IsESignatureEnabled.Value != updatedReviewSettings.RequireESignature);

            if (!settingChanged)
            {
                return;
            }

            if (reviewType == ReviewType.Formal && reviewRawData.Status == ReviewPackageStatus.Active)
            {
                throw ReviewsExceptionHelper.ReviewActiveFormalException();
            }

            reviewRawData.IsESignatureEnabled = updatedReviewSettings.RequireESignature;
        }
예제 #2
0
        private async Task UpdateRequireMeaningOfSignatureAsync(int reviewId, int userId, int projectId, ReviewType reviewType, ReviewSettings updatedReviewSettings, ReviewPackageRawData reviewRawData)
        {
            var settingChanged = reviewRawData.IsMoSEnabled != updatedReviewSettings.RequireMeaningOfSignature;

            if (!settingChanged)
            {
                return;
            }

            if (reviewType == ReviewType.Formal && reviewRawData.Status == ReviewPackageStatus.Active)
            {
                throw ReviewsExceptionHelper.ReviewActiveFormalException();
            }

            if (updatedReviewSettings.RequireMeaningOfSignature && (!reviewRawData.IsESignatureEnabled.HasValue || !reviewRawData.IsESignatureEnabled.Value))
            {
                throw ReviewsExceptionHelper.RequireESignatureDisabledException(reviewId);
            }

            var projectPermissions = await _permissionsRepository.GetProjectPermissions(projectId);

            if (!projectPermissions.HasFlag(ProjectPermissions.IsMeaningOfSignatureEnabled))
            {
                throw ReviewsExceptionHelper.MeaningOfSignatureIsDisabledInProjectException();
            }

            reviewRawData.IsMoSEnabled = updatedReviewSettings.RequireMeaningOfSignature;

            if (reviewRawData.IsMoSEnabled && reviewRawData.Reviewers != null)
            {
                var meaningOfSignatureParameters = reviewRawData.Reviewers
                                                   .Where(r => r.Permission == ReviewParticipantRole.Approver)
                                                   .Select(r => new MeaningOfSignatureParameter {
                    ParticipantId = r.UserId
                });

                await UpdateMeaningOfSignaturesInternalAsync(reviewId, userId, reviewRawData, meaningOfSignatureParameters, new MeaningOfSignatureUpdateSetDefaultsStrategy());
            }
        }
예제 #3
0
        public async Task <ReviewChangeItemsStatusResult> AssignApprovalRequiredToArtifactsAsync(int reviewId, AssignArtifactsApprovalParameter content, int userId)
        {
            if ((content.ItemIds == null || !content.ItemIds.Any()) && content.SelectionType == SelectionType.Selected)
            {
                throw new BadRequestException("Incorrect input parameters", ErrorCodes.OutOfRangeParameter);
            }

            if (!await _permissionsRepository.HasEditPermissions(reviewId, userId))
            {
                throw ReviewsExceptionHelper.UserCannotModifyReviewException(reviewId);
            }

            var reviewInfo = await GetReviewInfoAsync(reviewId, userId);

            if (reviewInfo.LockedByUserId.GetValueOrDefault() != userId)
            {
                throw ExceptionHelper.ArtifactNotLockedException(reviewId, userId);
            }

            var review = await _reviewsRepository.GetReviewAsync(reviewId, userId);

            if (review.ReviewStatus == ReviewPackageStatus.Closed)
            {
                throw ReviewsExceptionHelper.ReviewClosedException();
            }

            if (review.Contents.Artifacts == null ||
                !review.Contents.Artifacts.Any())
            {
                throw ExceptionHelper.ArtifactDoesNotSupportOperation(reviewId);
            }

            // If review is active and formal we throw conflict exception. No changes allowed
            if (review.ReviewStatus == ReviewPackageStatus.Active &&
                review.ReviewType == ReviewType.Formal)
            {
                throw ReviewsExceptionHelper.ReviewActiveFormalException();
            }
            foreach (var artifact in review.Contents.Artifacts)
            {
                if (artifact.ApprovalNotRequested == null)
                {
                    artifact.ApprovalNotRequested = (review.BaselineId == null);
                }
            }
            var resultErrors = new List <ReviewChangeItemsError>();

            var updatingArtifacts = GetReviewArtifacts(content, resultErrors, review.Contents);

            if (updatingArtifacts.Any())
            {
                // For Informal review
                await ExcludeDeletedAndNotInProjectArtifacts(content, review, reviewInfo.ProjectId, resultErrors, updatingArtifacts);
                await ExcludeArtifactsWithoutReadPermissions(content, userId, resultErrors, updatingArtifacts);

                var reviewRawData = review.ReviewPackageRawData;
                if (review.ReviewStatus == ReviewPackageStatus.Active &&
                    updatingArtifacts.Any() &&
                    content.ApprovalRequired)
                {
                    var hasArtifactsRequireApproval = review.Contents.Artifacts.FirstOrDefault(a => a.ApprovalNotRequested == false) != null;
                    // if Review has already artifacts require approval before current action it means that it is already converted to formal
                    if (!hasArtifactsRequireApproval)
                    {
                        var approver =
                            reviewRawData.Reviewers?.FirstOrDefault(r => r.Permission == ReviewParticipantRole.Approver);
                        if (approver != null)
                        {
                            throw new ConflictException(
                                      "Could not update review artifacts because review needs to be converted to Formal.",
                                      ErrorCodes.ReviewNeedsToMoveBackToDraftState);
                        }
                    }
                }

                foreach (var updatingArtifact in updatingArtifacts)
                {
                    updatingArtifact.ApprovalNotRequested = !content.ApprovalRequired;
                }

                var resultArtifactsXml = ReviewRawDataHelper.GetStoreData(review.Contents);

                await _reviewsRepository.UpdateReviewArtifactsAsync(reviewId, userId, resultArtifactsXml, null, false);

                if (content.ApprovalRequired)
                {
                    await EnableRequireESignatureWhenProjectESignatureEnabledByDefaultAsync(reviewId, userId, reviewInfo.ProjectId, reviewRawData);
                }
            }

            var result = new ReviewChangeItemsStatusResult();

            result.ReviewType = await _reviewsRepository.GetReviewTypeAsync(reviewId, userId);

            if (resultErrors.Any())
            {
                result.ReviewChangeItemErrors = resultErrors;
            }

            return(result);
        }