Beispiel #1
0
        public async Task <IHttpActionResult> RemoveArtifactsFromCollectionAsync(
            int id, string remove, ItemsRemovalParams removalParams)
        {
            removalParams.Validate();

            var result = await _collectionsService.RemoveArtifactsFromCollectionAsync(id, removalParams, Session.UserId);

            return(Ok(result));
        }
Beispiel #2
0
        public async Task RemoveArtifactsFromCollectionAsync_AllParametersAreValid_Success()
        {
            var removalParameters =
                new ItemsRemovalParams
            {
                ItemIds = new List <int> {
                    1, 2, 3
                }
            };

            _collectionsServiceMock.Setup(svc => svc.RemoveArtifactsFromCollectionAsync(_collectionId, removalParameters, _sessionUserId)).ReturnsAsync(_removeArtifactsFromCollectionResult);

            var result = await _collectionsController.RemoveArtifactsFromCollectionAsync(_collectionId, "remove", removalParameters) as OkNegotiatedContentResult <RemoveArtifactsFromCollectionResult>;

            Assert.IsNotNull(result);
            Assert.AreEqual(_removeArtifactsFromCollectionResult, result.Content);
        }
Beispiel #3
0
        public async Task <RemoveArtifactsFromCollectionResult> RemoveArtifactsFromCollectionAsync(
            int collectionId, ItemsRemovalParams removalParams, int userId)
        {
            if (collectionId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(collectionId));
            }

            if (userId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }

            RemoveArtifactsFromCollectionResult result = null;

            Func <IDbTransaction, long, Task> action = async(transaction, transactionId) =>
            {
                var collection = await ValidateCollectionAsync(collectionId, userId, transaction);

                var searchArtifactsResult = await _searchEngineService.Search(
                    collection.Id, null, ScopeType.Contents, true, userId, transaction);

                var artifactsToRemove = removalParams.SelectionType == SelectionType.Selected ?
                                        searchArtifactsResult.ArtifactIds.Intersect(removalParams.ItemIds).ToList() :
                                        searchArtifactsResult.ArtifactIds.Except(removalParams.ItemIds).ToList();

                var accessibleArtifacts = await GetAccessibleArtifactsAsync(artifactsToRemove, userId, transaction);

                var accessibleArtifactIds = accessibleArtifacts.Select(a => a.HolderId);

                var removedCount = await _collectionsRepository.RemoveArtifactsFromCollectionAsync(
                    collection.Id, accessibleArtifactIds, userId, transaction);

                result = new RemoveArtifactsFromCollectionResult
                {
                    RemovedCount = removedCount,
                    Total        = removalParams.SelectionType == SelectionType.Selected ?
                                   removalParams.ItemIds.Count() :
                                   searchArtifactsResult.ArtifactIds.Except(removalParams.ItemIds).Count()
                };
            };

            await _sqlHelper.RunInTransactionAsync(ServiceConstants.RaptorMain, action);

            return(result);
        }
        public static void VerifyNotLastApproverInFormalReview(ItemsRemovalParams content, Review review)
        {
            if (review.ReviewType != ReviewType.Formal)
            {
                return;
            }

            var approverIds =
                review.ReviewPackageRawData.Reviewers.Where(
                    r => r.Permission == ReviewParticipantRole.Approver).Select(a => a.UserId).ToList();

            if (approverIds.IsEmpty())
            {
                return;
            }

            if (content.SelectionType == SelectionType.Selected)
            {
                // If content.ItemIds containsAll approverIds
                if (approverIds.Except(content.ItemIds).IsEmpty())
                {
                    throw new ConflictException(
                              "Cannot remove last approver from active review. Not possible to convert Active Formal review back to Informal",
                              ErrorCodes.LastApproverInActiveReview);
                }
            }
            else
            {
                if (approverIds.Intersect(content.ItemIds).IsEmpty())
                {
                    throw new ConflictException(
                              "Cannot remove last approver from active review. Not possible to convert Active Formal review back to Informal",
                              ErrorCodes.LastApproverInActiveReview);
                }
            }
        }
Beispiel #5
0
 public Task RemoveParticipantsFromReviewAsync(int reviewId, [FromBody] ItemsRemovalParams removeParams)
 {
     return(_sqlReviewsRepository.RemoveParticipantsFromReviewAsync(reviewId, removeParams, Session.UserId));
 }
Beispiel #6
0
        public void Initialize()
        {
            _sqlHelperMock                 = new SqlHelperMock();
            _collectionsRepository         = new Mock <ICollectionsRepository>();
            _artifactRepository            = new Mock <IArtifactRepository>();
            _lockArtifactsRepository       = new Mock <ILockArtifactsRepository>();
            _itemInfoRepository            = new Mock <IItemInfoRepository>();
            _artifactPermissionsRepository = new Mock <IArtifactPermissionsRepository>();
            _searchEngineService           = new Mock <ISearchEngineService>();
            _artifactListService           = new Mock <IArtifactListService>();
            _collectionService             = new CollectionsService(
                _collectionsRepository.Object,
                _artifactRepository.Object,
                _lockArtifactsRepository.Object,
                _itemInfoRepository.Object,
                _artifactPermissionsRepository.Object,
                _sqlHelperMock,
                _searchEngineService.Object,
                _artifactListService.Object);


            _artifactIds = new HashSet <int> {
                1, 2, 3
            };
            _collectionId          = 1;
            _searchArtifactsResult = new SearchArtifactsResult
            {
                ArtifactIds = _artifactIds,
                Total       = _artifactIds.Count
            };

            _profileColumnsSettings = new ProfileColumns(
                new List <ProfileColumn>
            {
                new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Number, 2)
            });

            _collectionPermissions = new Dictionary <int, RolePermissions>
            {
                { _collectionId, RolePermissions.Read | RolePermissions.Edit }
            };

            _collectionDetails = new ArtifactBasicDetails
            {
                ArtifactId   = _collectionId,
                ProjectId    = 1,
                DraftDeleted = false,
                PrimitiveItemTypePredefined = (int)ItemTypePredefined.ArtifactCollection,
                LockedByUserId = _userId
            };

            _artifacts = new List <ItemDetails>
            {
                new ItemDetails
                {
                    Name                        = "Artifact1",
                    ItemTypeId                  = 2,
                    VersionProjectId            = 1,
                    EndRevision                 = int.MaxValue,
                    PrimitiveItemTypePredefined = (int)ItemTypePredefined.Actor
                }
            };

            _artifactPermissions = new Dictionary <int, RolePermissions>();

            foreach (var itemDetails in _artifacts)
            {
                _artifactPermissions.Add(itemDetails.ItemTypeId, RolePermissions.Read);
            }

            _profileColumns = new ProfileColumns(
                new List <ProfileColumn>
            {
                new ProfileColumn("Custom", PropertyTypePredefined.CustomGroup, PropertyPrimitiveType.Text, 2)
            });

            _propertyTypeInfos = new List <PropertyTypeInfo>
            {
                new PropertyTypeInfo
                {
                    Id            = 2,
                    Predefined    = PropertyTypePredefined.CustomGroup,
                    Name          = "Custom",
                    PrimitiveType = PropertyPrimitiveType.Number
                }
            };

            _artifactRepository
            .Setup(r => r.GetArtifactBasicDetails(_collectionId, _userId, null))
            .ReturnsAsync(_collectionDetails);

            _artifactPermissionsRepository
            .Setup(r => r.GetArtifactPermissions(_collectionId, _userId, It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync(_collectionPermissions);

            _artifactPermissionsRepository
            .Setup(r => r.GetArtifactPermissions(It.IsAny <IEnumerable <int> >(), _userId, It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null))
            .ReturnsAsync(_artifactPermissions);

            _collectionsRepository
            .Setup(r => r.GetContentArtifactIdsAsync(_collectionId, _userId, It.IsAny <bool>()))
            .ReturnsAsync(_artifactIds.ToList());

            _collectionsRepository
            .Setup(r => r.RemoveArtifactsFromCollectionAsync(_collectionId, It.IsAny <IEnumerable <int> >(), _userId, null))
            .ReturnsAsync(_artifacts.Count);

            _itemInfoRepository
            .Setup(r => r.GetItemsDetails(It.IsAny <int>(), It.IsAny <List <int> >(), It.IsAny <bool>(), It.IsAny <int>(), null))
            .ReturnsAsync(_artifacts);

            _searchEngineService
            .Setup(s => s.Search(It.IsAny <int>(), It.IsAny <Pagination>(), It.IsAny <ScopeType>(), It.IsAny <bool>(), It.IsAny <int>(), null))
            .ReturnsAsync(_searchArtifactsResult);

            InitializeProfileColumnsAndPropertyTypeInfos(_profileColumnsSettings, _propertyTypeInfos);

            _reviewItemsRemovalParams =
                new ItemsRemovalParams
            {
                ItemIds = new List <int> {
                    1, 2, 3
                },
                SelectionType = SelectionType.Selected
            };
        }