Consent Data Eraser Not Working

Francis Carroll asked on August 25, 2022 11:52

Hi,

I have a Kentico 13.0.70 on IIS 10 using ASP .NET Core.

I am having issues folling the content in this link https://docs.xperience.io/configuring-xperience/data-protection/gdpr-compliance/implementing-personal-data-erasure

I have followed this link and i cant seem to get it to work for me.

The variables in the ascx.cs are not being picked up and are unidentified aswell as the cms:Labels are also not being picked up.

The <cms:LocalizedHeader> and <cms:CheckBox> is highlighted and is showing the prompt, Element '' is not known. This can occur if their is a compliation error in the website or web.config.

The conpliation error is being shown as, the name chbActivies does not exist in the current context.

ContactDataEraser.cs

using System.Collections.Generic;
using System.Linq;
using CMS.Activities;
using CMS.Base;
using CMS.ContactManagement;
using CMS.DataEngine;
using CMS.DataProtection;
using CMS.Helpers;
namespace KenticoAdmin.DataProtection.DataEraser
{
    public class ContactDataEraser : IPersonalDataEraser
    {
        public void Erase(IEnumerable<BaseInfo> identities, IDictionary<string, object> configuration)
        {
            // Gets all contact objects added by registered IIdentityCollector implementations
            var contacts = identities.OfType<ContactInfo>();

            // Does nothing if no contacts were collected
            if (!contacts.Any())
            {
                return;
            }

            // Gets a list of identifiers for the contacts
            List<int> contactIds = contacts.Select(c => c.ContactID).ToList();

            // The context ensures that objects are permanently deleted with all versions, without creating recycle bin records
            // Contact and activity objects do not support versioning,
            // but we recommend using this action context in general when deleting personal data
            using (new CMSActionContext() { CreateVersion = false })
            {
                // Deletes the activities of the given contacts (if enabled in the configuration)
                DeleteActivities(contactIds, configuration);

                // Deletes the given contacts (if enabled in the configuration)
                // Also automatically deletes activities of the given contacts (contacts are parent objects of activities)
                DeleteContacts(contacts, configuration);
            }
        }

        private void DeleteActivities(List<int> contactIds, IDictionary<string, object> configuration)
        {
            // Checks whether deletion of activities is enabled in the configuration options
            object deleteActivities;
            if (configuration.TryGetValue("deleteActivities", out deleteActivities)
                && ValidationHelper.GetBoolean(deleteActivities, false))
            {
                // Deletes the activities of the specified contacts
                // The system may contain a very large number of activity records, so the example uses the BulkDelete API
                // This is more efficient, but does not perform general actions, such as logging of synchronization tasks
                ActivityInfoProvider.ProviderObject.BulkDelete(
                    new WhereCondition().WhereIn("ActivityContactID", contactIds));
            }
        }

        private static void DeleteContacts(IEnumerable<ContactInfo> contacts, IDictionary<string, object> configuration)
        {
            // Checks whether deletion of contacts is enabled in the configuration options
            object deleteContacts;
            if (configuration.TryGetValue("deleteContacts", out deleteContacts)
                && ValidationHelper.GetBoolean(deleteContacts, false))
            {
                // Deletes the specified contacts
                foreach (ContactInfo contact in contacts)
                {
                    ContactInfo.Provider.Delete(contact);
                }
            }
        }
    }
}

ContactDataEraserConfiguration.ascx

<%@ Control Language="C#" CodeBehind="ContactDataEraserConfiguration.ascx.cs" Inherits="KenticoAdmin.DataProtection.DataErasure.ContactDataEraserConfiguration" %>
<%@ Register Assembly="CMS.Base.Web.UI" Namespace="CMS.Base.Web.UI" TagPrefix="CMS" %>

<div class="cms-bootstrap">
    <div class="form-horizontal">
        <cms:LocalizedHeading runat="server" Level="4" Text="Contact data" />
        <cms:CMSCheckBox ID="chbDeleteContacts" runat="server" Text="Delete contacts" />
        <cms:CMSCheckBox id="chbDeleteActivities" runat="server" text="Delete contact activities" />
    </div>
</div>

ContactDataEraserConfiguration.ascx.cs

using System.Collections.Generic;

using CMS.UIControls;

namespace KenticoAdmin.DataProtection.DataErasure
{
    public partial class ContactDataEraserConfiguration : ErasureConfigurationControl
    {
        public override IDictionary<string, object> GetConfiguration(IDictionary<string, object> configuration)
        {
            // The configuration keys must match the values checked in your IPersonalDataEraser implementations
            configuration.Add("deleteContacts", chbDeleteContacts.Checked);
            configuration.Add("deleteActivities", chbDeleteActivities.Checked);

            return configuration;
        }

        // Validates the eraser configuration provider by the user
        public override bool IsValid()
        {
            // Validates that at least one deletion checkbox is selected
            bool isValid = chbDeleteContacts.Checked || chbDeleteActivities.Checked;

            if (!isValid)
            {
                // Adds an error message that the control displays when the validation fails
                AddError("No data was selected for deletion.");
            }

            return isValid;
        }
    }
}

Correct Answer

Francis Carroll answered on September 13, 2022 09:01

Hi,

So i made a simple mistake and i was implementing this code in the front end application in a custom library, This code needs to be implemented in the back end CMSApp.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Ali Khan answered on November 11, 2022 16:52

Yes you are correct that custom library code need to add in Admin site(CMSAPP solution)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.