Ejemplo n.º 1
0
        public override async Task <IDisplayResult> UpdateAsync(AuditTrailSettings settings, BuildEditorContext context)
        {
            if (!await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext?.User, AuditTrailPermissions.ManageAuditTrailSettings))
            {
                return(null);
            }

            if (context.GroupId == AuditTrailSettingsGroup.Id)
            {
                var model = new AuditTrailSettingsViewModel();
                await context.Updater.TryUpdateModelAsync(model, Prefix);

                settings.Categories = model.Categories
                                      .Select(categorySettings => new AuditTrailCategorySettings()
                {
                    Name   = categorySettings.Name,
                    Events = categorySettings.Events
                             .Select(settings => new AuditTrailEventSettings()
                    {
                        Name      = settings.Name,
                        Category  = settings.Category,
                        IsEnabled = settings.IsEnabled
                    })
                             .ToArray()
                })
                                      .ToArray();

                settings.ClientIpAddressAllowed = model.ClientIpAddressAllowed;
            }

            return(await EditAsync(settings, context));
        }
        protected override DriverResult Editor(AuditTrailSettingsPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            if (!_authorizer.Authorize(Permissions.ManageAuditTrailSettings))
            {
                return(null);
            }

            return(ContentShape("Parts_AuditTrailSettings_Edit", () => {
                var descriptors = _auditTrailManager.DescribeCategories();
                var eventSettings = part.EventSettings.ToList();
                var categoriesQuery =
                    from categoryDescriptor in descriptors
                    let eventsQuery =
                        from eventDescriptor in categoryDescriptor.Events
                        let eventSetting = GetOrCreate(eventSettings, eventDescriptor)
                                           select new AuditTrailEventSettingsViewModel {
                    Event = eventDescriptor.Event,
                    Name = eventDescriptor.Name,
                    Description = eventDescriptor.Description,
                    IsEnabled = eventDescriptor.IsMandatory || eventSetting.IsEnabled,
                    IsMandatory = eventDescriptor.IsMandatory
                }
                select new AuditTrailCategorySettingsViewModel {
                    Category = categoryDescriptor.Category,
                    Name = categoryDescriptor.Name,
                    Events = eventsQuery.ToList()
                };

                var viewModel = new AuditTrailSettingsViewModel {
                    Categories = categoriesQuery.ToList(),
                    EnableClientIpAddressLogging = part.EnableClientIpAddressLogging
                };

                // Update the settings as we may have added new settings.
                part.EventSettings = eventSettings;

                if (updater != null)
                {
                    var eventsDictionary = _auditTrailManager.DescribeProviders().Describe().SelectMany(x => x.Events).ToDictionary(x => x.Event);
                    if (updater.TryUpdateModel(viewModel, Prefix, null, null))
                    {
                        foreach (var eventSettingViewModel in viewModel.Categories.SelectMany(x => x.Events))
                        {
                            var eventSetting = eventSettings.First(x => x.EventName == eventSettingViewModel.Event);
                            var descriptor = eventsDictionary[eventSetting.EventName];

                            eventSetting.IsEnabled = eventSettingViewModel.IsEnabled || descriptor.IsMandatory;
                        }
                        part.EventSettings = eventSettings;
                        part.EnableClientIpAddressLogging = viewModel.EnableClientIpAddressLogging;
                    }
                }

                return shapeHelper.EditorTemplate(TemplateName: "Parts.AuditTrailSettings", Model: viewModel, Prefix: Prefix);
            }).OnGroup("Audit Trail"));
        }
Ejemplo n.º 3
0
        public override async Task <IDisplayResult> UpdateAsync(AuditTrailSettings settings, BuildEditorContext context)
        {
            if (context.GroupId == AuditTrailSettingsGroupId)
            {
                if (!await IsAuthorizedToManageAuditTrailSettingsAsync())
                {
                    return(null);
                }

                var model = new AuditTrailSettingsViewModel();

                await context.Updater.TryUpdateModelAsync(model, Prefix);

                var eventSettings    = model.Categories;
                var eventsDictionary = _auditTrailManager.DescribeProviders().Describe()
                                       .SelectMany(categoryDescriptor => categoryDescriptor.Events)
                                       .ToDictionary(eventDescriptor => eventDescriptor.FullEventName);

                foreach (var eventSettingViewModel in model.Categories.SelectMany(categorySettings => categorySettings.Events))
                {
                    var eventSetting = eventSettings
                                       .SelectMany(categorySettings => categorySettings.Events
                                                   .Where(eventSettings => eventSettings.Event == eventSettingViewModel.Event))
                                       .FirstOrDefault();

                    var descriptor = eventsDictionary[eventSetting.Event];
                    eventSetting.IsEnabled = eventSettingViewModel.IsEnabled || descriptor.IsMandatory;
                }

                settings.EnableClientIpAddressLogging = model.EnableClientIpAddressLogging;
                settings.BlacklistedContentTypes      = model.BlacklistedContentTypes;

                settings.BlacklistedContentTypeNames = model.BlacklistedContentTypes
                                                       .Where(blacklistedContentType => blacklistedContentType.Selected)
                                                       .Select(blacklistedContentType => blacklistedContentType.Name).ToArray();

                settings.EventSettings = eventSettings
                                         .SelectMany(categorySettings => categorySettings.Events
                                                     .Select(eventSettings =>
                                                             new AuditTrailEventSetting {
                    EventName = eventSettings.Event, IsEnabled = eventSettings.IsEnabled
                }));
            }

            return(await EditAsync(settings, context));
        }