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); } } } }
/// <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 }
/// <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>(); }
private bool CheckFlag(GDPRContentContext context, MediaLibraryPickerField fi) { var settings = fi.PartFieldDefinition.Settings.GetModel <MediaLibraryPickerFieldGDPRPartFieldSettings>(); return(context.Erase ? settings.AttemptToEraseItems : settings.AttemptToAnonymizeItems); }
/// <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>()); }
private IEnumerable <UserPart> PartVersions(GDPRContentContext context) { return(context.AllVersions .Select(civ => civ .Parts .FirstOrDefault(pa => pa is UserPart)) .Where(pa => pa != null) .Cast <UserPart>()); }
public GDPRContentContext(ContentItem contentItem, GDPRContentContext previousContext) : this(contentItem) { ChainOfContexts.Add(previousContext); if (previousContext?.ChainOfContexts != null) { // we called the other ctor, thus ChainOfContexts was initialized as empty. // Then we add to it whatever was there already. // The result of this is that this.ChainOfContexts is ordered with the current item // being the first element, and the item on which the process began last. ChainOfContexts.AddRange(previousContext.ChainOfContexts); } }
private void DisableUser(GDPRContentContext context, UserPart userPart) { // for all versions, make sure the user is amrked as disabled var partVersions = PartVersions(context); foreach (var uPart in partVersions) { // disable the user. uPart.RegistrationStatus = UserStatus.Pending; uPart.EmailStatus = UserStatus.Pending; } }
/// <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 }
/// <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); }
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); } } } }
private void ClearUser(GDPRContentContext context, UserPart userPart) { // for all versions, clear username and email address. We make them into unique // strings. var partVersions = PartVersions(context); foreach (var uPart in partVersions) { // UserName uPart.UserName = uPart.UserName.GenerateUniqueString(); uPart.NormalizedUserName = uPart.UserName.ToLowerInvariant(); // Email uPart.Email = uPart.Email.GenerateUniqueString(); // then disable the user (again, just in case). uPart.RegistrationStatus = UserStatus.Pending; uPart.EmailStatus = UserStatus.Pending; } }
public EraseContentContext(ContentItem contentItem, GDPRContentContext previousContext) : base(contentItem, previousContext) { Erase = true; }
private bool ShoulDetachAll(GDPRContentContext context, ContentPickerField field) { return context.Erase ? Setting(field).DetachAllItemsOnErase : Setting(field).DetachAllItemsOnAnonymize; }
private bool ShouldDetachPersonal(GDPRContentContext context, MediaLibraryPickerField field) { return(context.Erase ? Setting(field).DetachGDPRItemsOnErase : Setting(field).DetachGDPRItemsOnAnonymize); }
public AnonymizeContentContext(ContentItem contentItem, GDPRContentContext previousContext) : base(contentItem, previousContext) { Erase = false; }