public void ShouldCanEditOwnQuery()
        {
            const long userId = 123;

            const int queryId = 5235;

            var query = new Queries
            {
                CreatedById = userId,
                Id          = queryId
            };

            var result = _target.IsCanEdit(query, userId);

            result.Should().BeTrue();
        }
Пример #2
0
        public bool Execute(CanEditQueryQuery dataQuery)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException(nameof(dataQuery));
            }

            var query = _queryRepository.GetById(dataQuery.QueryId);

            return(_queryAccessValidator.IsCanEdit(query, _userPrincipal.Info.Id));
        }
Пример #3
0
        public void Update(
            long queryId,
            string textQuery,
            string name,
            string comment,
            QueryPrivacyType privacyType,
            QueryVisibilityType visibilityType)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            using (var telemetryScope = _telemetryScopeProvider.Create <Queries>(TelemetryOperationNames.Query.Update))
            {
                try
                {
                    var query = _queryRepository.GetById(queryId);

                    if (query == null)
                    {
                        throw new QueryDoesNotExistsException(queryId);
                    }

                    telemetryScope.SetEntity(query);

                    var canEditQuery = _queryAccessValidator.IsCanEdit(query, _userPrincipal.Info.Id);

                    if (!canEditQuery)
                    {
                        throw new UnauthorizedAccessException();
                    }

                    if (!string.IsNullOrEmpty(textQuery))
                    {
                        var queryModel = _queryModelProcessor.FromText(textQuery, query.ProjectId, query.IsSystem);

                        _queryModelValidator.Validate(queryModel);

                        query.JsonQuery = queryModel.ToJson();
                    }
                    else
                    {
                        query.JsonQuery = null;
                    }

                    query.Comment     = comment;
                    query.ModifiedUtc = _timeService.GetUtc();
                    query.Name        = name;
                    query.Privacy     = (int)privacyType;
                    query.Query       = textQuery;
                    query.Visibility  = (int)visibilityType;

                    _queryRepository.Save();

                    telemetryScope.WriteSuccess();
                }
                catch (Exception ex)
                {
                    telemetryScope.WriteException(ex);

                    throw;
                }
            }
        }