Пример #1
0
 protected override void Anonymizing(AnonymizeContentContext context)
 {
     // this check is a trick to verify that the ContentItem has a GDPRPart and
     // that it is not protected or anything.
     if (context.ShouldProcess(context.GDPRPart))
     {
         // go through every part in context.ContentItem
         foreach (var part in context.ContentItem.Parts)
         {
             // get the subset of all the part's fields that include those that need processing
             var fieldsToProcess = part.Fields.Where(fi =>
                                                     IsFieldToProcess(context, fi, set => set.AnonymizationPropertyValuePairs));
             // we get the part's settings to check whether they areconfigured for reflection
             var partSettings = part.TypePartDefinition
                                .Settings.GetModel <GDPRPartPartSettings>();
             // Only do stuff if either the part should be processed and has a configuration for reflection,
             // or that is true for any of its fields.
             var IsPartToProcess = context.ShouldProcess(part) &&
                                   ValidDictionary(partSettings.AnonymizationPropertyValuePairs);
             if (IsPartToProcess || fieldsToProcess.Any())
             {
                 // We will need this part's definition to look for it in previous versions of the
                 // content item
                 var partName = part.PartDefinition.Name;
                 // we get all the versions of this part. We get this here before checking whether we
                 // should process the part because we will need it if there are fields to process.
                 var partVersions = context.AllVersions
                                    .Select(ci => ci.Parts.FirstOrDefault(pa => pa.PartDefinition.Name == partName))
                                    .Where(pa => pa != null);
                 var partVersionAction = new Action <ContentPart>(pv => { });
                 if (IsPartToProcess)
                 {
                     partVersionAction = pv => SetAllProperties(pv, partSettings.AnonymizationPropertyValuePairs);
                 }
                 var fieldVersionAction = new Action <ContentPart>((pv) => { });
                 if (fieldsToProcess.Any())
                 {
                     fieldVersionAction = (pv) => {
                         foreach (var field in fieldsToProcess)
                         {
                             // get the default setting for reflection (we verified it exists in IsFieldToProcess)
                             var fieldSettings = field.PartFieldDefinition
                                                 .Settings.GetModel <GDPRPartFieldSettings>();
                             //get the field
                             var fieldVersion = pv.Fields
                                                .FirstOrDefault(fi => fi.Name == field.Name);
                             // use reflection to set property values
                             SetAllProperties(fieldVersion, fieldSettings.AnonymizationPropertyValuePairs);
                         }
                     };
                 }
                 foreach (var partVersion in partVersions)
                 {
                     partVersionAction(partVersion);
                     fieldVersionAction(partVersion);
                 }
             }
         }
     }
 }
 protected override void Anonymized(AnonymizeContentContext context)
 {
     // this check returns true if the item has a GDPRPart. It should not be required
     // but it's there for safety
     if (context.ShouldProcess(context.GDPRPart))
     {
         _workflowManager.TriggerEvent("ContentAnonymized", context.ContentItem,
                                       () => new Dictionary <string, object> {
             { "Content", context.ContentItem },
             { "GDPRContentContext", context }
         });
     }
 }