Пример #1
0
        public void Delete(long reportId)
        {
            using (var telemetryScope = _telemetryScopeProvider.Create <Reports>(TelemetryOperationNames.Report.Delete))
            {
                try
                {
                    var report = GetReport(reportId);

                    telemetryScope.SetEntity(report);

                    if (!_reportAuthorityValidator.CanEdit(_userPrincipal.Info.Id, report))
                    {
                        throw new UnauthorizedAccessException();
                    }

                    _reportRepository.Delete(report);

                    _reportRepository.Save();

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

                    throw;
                }
            }
        }
Пример #2
0
        public void ShouldValidateReportEditAuthority(bool isHasAuthority)
        {
            const long userId = 4234;

            long?projectId = 4233123;

            var report = new Reports
            {
                IsSystem  = false,
                ProjectId = projectId
            };

            _userAuthorityValidator
            .Setup(_ => _.HasUserAuthorities(userId, new[] { Authorities.UI.Reports.Edit }, projectId))
            .Returns(isHasAuthority);

            var result = _target.CanEdit(userId, report);

            result.ShouldBeEquivalentTo(isHasAuthority);
        }