public async Task <ReviewRelationshipsResultSet> GetReviewRelationships(int artifactId, int userId, bool addDrafts = true, int?versionId = null)
        {
            var revisionId = await _itemInfoRepository.GetRevisionId(artifactId, userId, versionId);

            var reviewType = new List <int> {
                (int)LinkType.ReviewPackageReference
            };
            var reviewLinks = (await GetLinkInfo(artifactId, userId, addDrafts, revisionId, reviewType)).ToList();
            var result      = new ReviewRelationshipsResultSet {
            };

            if (reviewLinks != null)
            {
                var distinctReviewIds   = reviewLinks.Select(a => a.SourceItemId).Distinct().ToList();
                var reviewIdsWithAccess = new List <int>();
                var reviewPermissions   = await _artifactPermissionsRepository.GetArtifactPermissions(distinctReviewIds, userId);

                foreach (var reviewId in distinctReviewIds)
                {
                    if (SqlArtifactPermissionsRepository.HasPermissions(reviewId, reviewPermissions, RolePermissions.Read))
                    {
                        reviewIdsWithAccess.Add(reviewId);
                    }
                }

                var itemDetailsDictionary = (await _itemInfoRepository.GetItemsDetails(userId, reviewIdsWithAccess, true, revisionId))
                                            .ToDictionary(a => a.HolderId);
                var itemRawDataDictionary = (await _itemInfoRepository.GetItemsRawDataCreatedDate(userId, reviewIdsWithAccess, true, revisionId))
                                            .ToDictionary(a => a.ItemId);
                var referencedReviewArtifacts = new List <ReferencedReviewArtifact>();
                ItemRawDataCreatedDate itemRawDataCreatedDate;
                ItemDetails            itemDetails;
                foreach (var reviewId in reviewIdsWithAccess)
                {
                    if ((itemRawDataDictionary.TryGetValue(reviewId, out itemRawDataCreatedDate)) && (itemDetailsDictionary.TryGetValue(reviewId, out itemDetails)))
                    {
                        var status = ReviewRawDataHelper.ExtractReviewStatus(itemRawDataCreatedDate.RawData);
                        referencedReviewArtifacts.Add(new ReferencedReviewArtifact
                        {
                            ItemId         = reviewId,
                            Status         = status,
                            CreatedDate    = itemRawDataCreatedDate.CreatedDateTime,
                            ItemName       = itemDetails.Name,
                            ItemTypePrefix = itemDetails.Prefix
                        });
                    }
                }
                result.ReviewArtifacts = referencedReviewArtifacts;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <BaselineInfo> > GetBaselineInfo(IEnumerable <int> artifactIds, int userId, bool addDrafts = true, int revisionId = int.MaxValue)
        {
            var artifactsPermissions = await ArtifactPermissionsRepository.GetArtifactPermissions(artifactIds, userId);

            var artifactsWithReadPermissions = artifactsPermissions.Where(p => p.Value.HasFlag(RolePermissions.Read)).Select(p => p.Key);
            var itemsRawData = await _itemInfoRepository.GetItemsRawDataCreatedDate(userId, artifactsWithReadPermissions, addDrafts, revisionId);

            return(itemsRawData.Select(i => new BaselineInfo
            {
                ItemId = i.ItemId,
                IsSealed = BaselineRawDataHelper.ExtractIsSelead(i.RawData),
                UtcTimestamp = BaselineRawDataHelper.ExtractTimestamp(i.RawData)
            }).ToList());
        }