Exemplo n.º 1
0
        /// <summary>
        /// Returns all ContentItems selected in ContentPickerFields that are set to have all their
        /// selected items processed.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private IEnumerable<ContentItem> AllItemsToProcessFromAllVersions(GDPRContentContext context) {
            var allParts = context.AllVersions.SelectMany(civ => civ.Parts);
            var allFields = allParts
                .SelectMany(pa => pa.Fields.Where(fi => // get their fields
                    fi is ContentPickerField // that are ContentPickerFields
                    && context.ShouldProcess(fi) // that should be processed
                    && CheckFlag(context, (ContentPickerField)fi))) // that should have selected items processed as well
                .Cast<ContentPickerField>(); // cast the fields to ContentPickerFields

            var allItems = allFields
                .SelectMany(cpf => cpf.ContentItems) // select all the selected items of all those fields
                .GroupBy(ci => ci.Id)
                .Select(group => group.First()); // do not process them twice

            return allItems;

            //return 
            //    context.AllVersions.SelectMany(civ => civ.Parts) // from all parts
            //        .SelectMany(pa => pa.Fields.Where(fi => // get their fields
            //            fi is ContentPickerField // that are ContentPickerFields
            //            && context.ShouldProcess(fi) // that should be processed
            //            && CheckFlag(context, (ContentPickerField)fi))) // that should have selected items processed as well
            //        .Cast<ContentPickerField>() // cast the fields to ContentPickerFields
            //        .SelectMany(cpf => cpf.ContentItems) // select all the selected items of all those fields
            //        .Distinct(); // do not process them twice
        }
 private void PostProcess(GDPRContentContext context, GDPRPart part)
 {
     // if we should detach items, this is the place
     if (context.ShouldProcess(part))
     {
         // each version of the item will have their own
         foreach (var itemVersion in context.AllVersions)
         {
             var mlpfs = AllMLPFsFromContent(context, itemVersion);
             foreach (var mlpf in mlpfs)
             {
                 Func <ContentItem, bool> shouldRemain = ci => true;
                 if (ShoulDetachAll(context, mlpf))   // remove all?
                 {
                     shouldRemain = ci => false;
                 }
                 else if (ShouldDetachPersonal(context, mlpf))     // remove personal info?
                 {
                     shouldRemain = ci => !ci.Is <GDPRPart>();
                 }
                 mlpf.Ids = RemainingIds(mlpf, shouldRemain);
             }
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Returns for the ContentItem passed as parameter all ContentPickerFields that should
 /// be processed as well
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 private IEnumerable<ContentPickerField> AllCPFsFromContent(
     GDPRContentContext context, ContentItem contentItem) {
     return contentItem.Parts
         .SelectMany(pa => pa.Fields.Where(fi =>
             fi is ContentPickerField
             && context.ShouldProcess(fi)))
         .Cast<ContentPickerField>();
 }
 /// <summary>
 /// Returns for the ContentItem passed as parameter all MediaLibraryPickerFields that should
 /// be processed as well
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 private IEnumerable <MediaLibraryPickerField> AllMLPFsFromContent(
     GDPRContentContext context, ContentItem contentItem)
 {
     return(contentItem.Parts
            .SelectMany(pa => pa.Fields.Where(fi =>
                                              fi is MediaLibraryPickerField &&
                                              context.ShouldProcess(fi)))
            .Cast <MediaLibraryPickerField>());
 }
 /// <summary>
 /// Returns all ContentItems selected in MediaLibraryPickerFields that are set to have all their
 /// selected items processed.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 private IEnumerable <ContentItem> AllItemsToProcessFromAllVersions(GDPRContentContext context)
 {
     return
         (context.AllVersions.SelectMany(civ => civ.Parts) // from all parts
          .SelectMany(pa => pa.Fields.Where(fi =>          // get their fields
                                            fi is MediaLibraryPickerField && // that are ContentPickerFields
                                            context.ShouldProcess(fi) && // that should be processed
                                            CheckFlag(context, (MediaLibraryPickerField)fi))) // that should have selected items processed as well
          .Cast <MediaLibraryPickerField>()                                                   // cast the fields to MediaLibraryPickerFields
          .SelectMany(mlpf => mlpf.MediaParts)                                                // select all the selected items of all those fields
          .Distinct()                                                                         // do not process them twice
          .Select(mp => mp.ContentItem));                                                     // we want the actual ContentItem
 }
Exemplo n.º 6
0
 /// <summary>
 /// This method is used to verify whether a specific field requires processing.
 /// </summary>
 /// <param name="context">The context object.</param>
 /// <param name="field">The field we are testing.</param>
 /// <param name="dictionaryFunc">This Func parameter is used to tell which dictionary should be
 /// validated for the reflection settings. In practice, this means that this Func discriminates
 /// between a check for Anonymization and one for erasure.</param>
 /// <returns>True for a field that need processing and has something configured to be done in reflection.
 /// False otherwise.</returns>
 private bool IsFieldToProcess(
     GDPRContentContext context,
     ContentField field,
     Func <GDPRPartFieldSettings, Dictionary <string, string> > dictionaryFunc)
 {
     if (context.ShouldProcess(field))
     {
         var settings = field.PartFieldDefinition
                        .Settings.GetModel <GDPRPartFieldSettings>();
         if (ValidDictionary(dictionaryFunc(settings)))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        private void Processing(
            GDPRContentContext context, 
            GDPRPart part, 
            Action<ContentItem, GDPRContentContext> process) {

            // If there are ContentPickerFields whose selected items we should process, do so
            if (context.ShouldProcess(part)) {
                var items = AllItemsToProcessFromAllVersions(context);
                foreach (var item in items) {
                    if (!context.ChainOfItems.Any(ci => ci.Id == item.Id)) {
                        // We only process the item if it's not alredy being processed in the current processing "chain".
                        // This helps preventing recursion, and propagates information regarding the other items.
                        // Then, the Manager will check whether the process is possible.
                        process(item, context);
                    }
                }
            }
        }