Пример #1
0
        public async Task <IEnumerable <AuthorHistory> > GetAuthorHistoriesWithPermissionsCheck(IEnumerable <int> artifactIds, int userId)
        {
            if (artifactIds == null)
            {
                throw new ArgumentOutOfRangeException(nameof(artifactIds));
            }

            var artifactsPermissions = await ArtifactPermissionsRepository.GetArtifactPermissions(artifactIds, userId);

            var readPermissions = artifactsPermissions.Where(perm => perm.Value.HasFlag(RolePermissions.Read));

            return(await GetAuthorHistories(readPermissions.Select(rp => rp.Key).ToList()));
        }
Пример #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());
        }
Пример #3
0
        public async Task <IEnumerable <ProcessInfoDto> > GetProcessInformationAsync(IEnumerable <int> artifactIds, int userId)
        {
            if (artifactIds == null)
            {
                throw new ArgumentOutOfRangeException(nameof(artifactIds));
            }

            var artifactsPermissions = await ArtifactPermissionsRepository.GetArtifactPermissions(artifactIds, userId);

            artifactIds = artifactsPermissions.Where(p => p.Value.HasFlag(RolePermissions.Read)).Select(p => p.Key);

            var param = new DynamicParameters();

            param.Add("@artifactIds", SqlConnectionWrapper.ToDataTable(artifactIds));
            var artifacts = await ConnectionWrapper.QueryAsync <ProcessInfo>("GetProcessInformation", param, commandType : CommandType.StoredProcedure);

            return(ProcessInfoMapper.Map(artifacts));
        }
Пример #4
0
        public async Task <List <Artifact> > GetArtifactNavigationPathAsync(int artifactId, int userId)
        {
            if (artifactId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(artifactId));
            }
            if (userId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }

            var artifactBasicDetails = await GetArtifactBasicDetails(ConnectionWrapper, artifactId, userId);

            if (artifactBasicDetails == null || artifactBasicDetails.LatestDeleted)
            {
                var errorMessage = I18NHelper.FormatInvariant("Item (Id:{0}) is not found.", artifactId);
                throw new ResourceNotFoundException(errorMessage, ErrorCodes.ResourceNotFound);
            }
            var itemIdsPermissions = (await ArtifactPermissionsRepository.GetArtifactPermissions(new[] { artifactId }, userId));

            if (!itemIdsPermissions.ContainsKey(artifactId) || !itemIdsPermissions[artifactId].HasFlag(RolePermissions.Read))
            {
                var errorMessage = I18NHelper.FormatInvariant("User does not have permissions for Artifact (Id:{0}).", artifactId);
                throw new AuthorizationException(errorMessage, ErrorCodes.UnauthorizedAccess);
            }

            var prm = new DynamicParameters();

            prm.Add("@artifactId", artifactId);
            prm.Add("@userId", userId);

            var ancestorsAndSelf = (await ConnectionWrapper.QueryAsync <ArtifactVersion>("GetArtifactNavigationPath", prm, commandType: CommandType.StoredProcedure))
                                   .ToList();

            return(OrderAncestors(ancestorsAndSelf, artifactId).Select(a => new Artifact
            {
                Id = a.ItemId,
                Name = a.Name,
                ProjectId = a.VersionProjectId,
                ItemTypeId = a.ItemTypeId
            }).ToList());
        }