Пример #1
0
        private async Task <IShape> BuildEventShapeAsync(string shapeType, AuditTrailEvent auditTrailEvent, string displayType)
        {
            dynamic auditTrailEventActionsShape = await _shapeFactory.CreateAsync(shapeType, Arguments.From(new Dictionary <string, object>
            {
                { "AuditTrailEvent", auditTrailEvent },
                { "Descriptor", _auditTrailManager.DescribeEvent(auditTrailEvent) },
                { "EventData", auditTrailEvent.Get(auditTrailEvent.EventName) }
            }));

            if (auditTrailEvent.Category == "Content")
            {
                var contentItem = auditTrailEvent.Get(auditTrailEvent.EventName).ToObject <ContentItem>();

                var availableVersionsCount = await _session.Query <ContentItem, ContentItemIndex>()
                                             .Where(index => index.ContentItemId == contentItem.ContentItemId).CountAsync();

                auditTrailEventActionsShape.AvailableVersionsCount = availableVersionsCount;
            }

            var metaData = auditTrailEventActionsShape.Metadata;

            metaData.DisplayType = displayType;
            metaData.Alternates.Add($"{shapeType}_{displayType}");
            metaData.Alternates.Add($"{shapeType}__{auditTrailEvent.Category}");
            metaData.Alternates.Add($"{shapeType}_{displayType}__{auditTrailEvent.Category}");
            metaData.Alternates.Add($"{shapeType}__{auditTrailEvent.Category}__{auditTrailEvent.EventName}");
            metaData.Alternates.Add($"{shapeType}_{displayType}__{auditTrailEvent.Category}__{auditTrailEvent.EventName}");

            return(auditTrailEventActionsShape);
        }
Пример #2
0
        public static string ToEventData(this IAuditTrailManager auditTrailManager, string settingsData)
        {
            var settings = auditTrailManager.DeserializeProviderConfiguration(settingsData);
            var query    =
                from setting in settings
                let descriptor = auditTrailManager.DescribeEvent(setting.EventName)
                                 select new AuditTrailEventSettingEventData {
                EventName        = setting.EventName,
                IsEnabled        = setting.IsEnabled,
                EventCategory    = descriptor.CategoryDescriptor.Name.TextHint,
                EventDisplayName = descriptor.Name.TextHint
            };

            return(SerializeEventData(query));
        }
        public override IDisplayResult Display(AuditTrailEvent auditTrailEvent)
        {
            var descriptor = _auditTrailManager.DescribeEvent(auditTrailEvent);

            return(Combine(
                       Initialize <AuditTrailEventViewModel>("AuditTrailEventTags_SummaryAdmin", model => BuildViewModel(auditTrailEvent, model, descriptor))
                       .Location("SummaryAdmin", "EventTags:10"),
                       Initialize <AuditTrailEventViewModel>("AuditTrailEventMeta_SummaryAdmin", model => BuildViewModel(auditTrailEvent, model, descriptor))
                       .Location("SummaryAdmin", "EventMeta:10"),
                       Initialize <AuditTrailEventViewModel>("AuditTrailEventActions_SummaryAdmin", model => BuildViewModel(auditTrailEvent, model, descriptor))
                       .Location("SummaryAdmin", "Actions:10"),
                       Initialize <AuditTrailEventViewModel>("AuditTrailEventDetail_DetailAdmin", model => BuildViewModel(auditTrailEvent, model, descriptor))
                       .Location("DetailAdmin", "Content:before")
                       ));
        }
        public async Task <ActionResult> Detail(string auditTrailEventId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, AuditTrailPermissions.ViewAuditTrail))
            {
                return(Forbid());
            }

            var auditTrailEvent = await _auditTrailManager.GetAuditTrailEventAsync(auditTrailEventId);

            return(View(new AuditTrailDetailsViewModel
            {
                AuditTrailEvent = auditTrailEvent,
                Descriptor = _auditTrailManager.DescribeEvent(auditTrailEvent),
                DetailsShape = await _auditTrailEventDisplayManager.BuildDisplayAsync(auditTrailEvent, "Detail")
            }));
        }
Пример #5
0
        public ActionResult Detail(int id)
        {
            if (!_authorizer.Authorize(Permissions.ViewAuditTrail))
            {
                return(new HttpUnauthorizedResult());
            }

            var record       = _auditTrailManager.GetRecord(id);
            var descriptor   = _auditTrailManager.DescribeEvent(record);
            var detailsShape = _displayBuilder.BuildDisplay(record, "Detail");
            var viewModel    = new AuditTrailDetailsViewModel {
                Record       = record,
                Descriptor   = descriptor,
                DetailsShape = detailsShape
            };

            return(View(viewModel));
        }
Пример #6
0
        private dynamic BuildEventShape(string shapeType, AuditTrailEventRecord record, string displayType)
        {
            var eventData  = _serializer.Deserialize(record.EventData);
            var descriptor = _auditTrailManager.DescribeEvent(record);
            var auditTrailEventActionsShape = _shapeFactory.Create(shapeType, Arguments.From(new Dictionary <string, object> {
                { "Record", record },
                { "EventData", eventData },
                { "Descriptor", descriptor }
            }));
            var metaData = auditTrailEventActionsShape.Metadata;

            metaData.DisplayType = displayType;
            metaData.Alternates.Add(String.Format("{0}_{1}", shapeType, displayType));
            metaData.Alternates.Add(String.Format("{0}__{1}", shapeType, record.Category));
            metaData.Alternates.Add(String.Format("{0}_{1}__{2}", shapeType, displayType, record.Category));
            metaData.Alternates.Add(String.Format("{0}__{1}__{2}", shapeType, record.Category, record.EventName));
            metaData.Alternates.Add(String.Format("{0}_{1}__{2}__{3}", shapeType, displayType, record.Category, record.EventName));
            return(auditTrailEventActionsShape);
        }
Пример #7
0
        public override async Task <IDisplayResult> DisplayAsync(AuditTrailEvent auditTrailEvent, AuditTrailContentEvent contentEvent, BuildDisplayContext context)
        {
            var contentItemId = contentEvent.ContentItem.ContentItemId;

            if (!_latestVersionId.TryGetValue(contentItemId, out var latestVersionId))
            {
                latestVersionId = (await _session.QueryIndex <ContentItemIndex>(index => index.ContentItemId == contentItemId && index.Latest)
                                   .FirstOrDefaultAsync())
                                  ?.ContentItemVersionId;

                _latestVersionId[contentItemId] = latestVersionId;
            }


            var descriptor = _auditTrailManager.DescribeEvent(auditTrailEvent);

            return(Combine(
                       Initialize <AuditTrailContentEventViewModel>("AuditTrailContentEventData_SummaryAdmin", m => BuildSummaryViewModel(m, auditTrailEvent, contentEvent, descriptor, latestVersionId))
                       .Location("SummaryAdmin", "EventData:10"),
                       Initialize <AuditTrailContentEventViewModel>("AuditTrailContentEventContent_SummaryAdmin", m => BuildSummaryViewModel(m, auditTrailEvent, contentEvent, descriptor, latestVersionId))
                       .Location("SummaryAdmin", "Content:10"),
                       Initialize <AuditTrailContentEventViewModel>("AuditTrailContentEventActions_SummaryAdmin", m => BuildSummaryViewModel(m, auditTrailEvent, contentEvent, descriptor, latestVersionId))
                       .Location("SummaryAdmin", "Actions:5"),
                       Initialize <AuditTrailContentEventDetailViewModel>("AuditTrailContentEventDetail_DetailAdmin", async m =>
            {
                BuildSummaryViewModel(m, auditTrailEvent, contentEvent, descriptor, latestVersionId);
                var previousContentItem = (await _session.Query <AuditTrailEvent, AuditTrailEventIndex>(collection: AuditTrailEvent.Collection)
                                           .Where(index =>
                                                  index.Category == "Content" &&
                                                  index.CreatedUtc <= auditTrailEvent.CreatedUtc &&
                                                  index.EventId != auditTrailEvent.EventId &&
                                                  index.CorrelationId == contentEvent.ContentItem.ContentItemId)
                                           .OrderByDescending(index => index.Id)
                                           .FirstOrDefaultAsync())?
                                          .As <AuditTrailContentEvent>()
                                          .ContentItem;

                if (previousContentItem != null)
                {
                    var current = JObject.FromObject(contentEvent.ContentItem);
                    var previous = JObject.FromObject(previousContentItem);
                    previous.Remove(nameof(AuditTrailPart));
                    current.Remove(nameof(AuditTrailPart));

                    m.PreviousContentItem = previousContentItem;

                    m.Previous = previous.ToString();
                    m.Current = current.ToString();
                }
            }).Location("DetailAdmin", "Content:5"),
                       Initialize <AuditTrailContentEventDetailViewModel>("AuditTrailContentEventDiff_DetailAdmin", async m =>
            {
                BuildSummaryViewModel(m, auditTrailEvent, contentEvent, descriptor, latestVersionId);
                var previousContentItem = (await _session.Query <AuditTrailEvent, AuditTrailEventIndex>(collection: AuditTrailEvent.Collection)
                                           .Where(index =>
                                                  index.Category == "Content" &&
                                                  index.CreatedUtc <= auditTrailEvent.CreatedUtc &&
                                                  index.EventId != auditTrailEvent.EventId &&
                                                  index.CorrelationId == contentEvent.ContentItem.ContentItemId)
                                           .OrderByDescending(index => index.Id)
                                           .FirstOrDefaultAsync())?
                                          .As <AuditTrailContentEvent>()
                                          .ContentItem;

                if (previousContentItem != null)
                {
                    var current = JObject.FromObject(contentEvent.ContentItem);
                    var previous = JObject.FromObject(previousContentItem);
                    previous.Remove(nameof(AuditTrailPart));
                    current.Remove(nameof(AuditTrailPart));

                    m.PreviousContentItem = previousContentItem;

                    m.Previous = previous.ToString();
                    m.Current = current.ToString();
                }
            }).Location("DetailAdmin", "Content:5#Diff")
                       ));
        }