DeletionPolicyHowTo

From Catglobe Wiki
Jump to: navigation, search
Keep data
Keep user link Yes Delete Qnaire Delete QAS Delete Data
Yes Scenario 1 Scenario 9
Yes, anonymize Scenario 2
No, destroy user Scenario 3 Scenario 5 Scenario 7
No, unset Scenario 4 Scenario 6 Scenario 8

Red scenarios are impossible. Yellow scenarios make no sense.

Scenario 1

Do nothing

Scenario 2

Option 1 (Via GUI):

0. Check that the user isn’t used in any other questionnaire
1. Delete all those data marked with "delete when anonymizing" in the questionnaire
2. Delete email/phone number/name/address … from user in such a way we cannot undo it

Option 2 (Via CgScript):

number qnaireRId = xxxx;
number userRId = xxxxx;
array otherQnaireRId;
array qas = QAS_getByUserResourceId (userRId);
for(i for 0; qas.Count)
{
    if (qas[i][QAS_QUESTIONNAIRE_RESOURCE_ID] == qnaireRId)
    {
        //Delete data marked with "delete when anonymizing" in the questionnaire
        //	TODO
    }
    else otherQnaireRId.Add(qas[i][QAS_QUESTIONNAIRE_RESOURCE_ID]);
}
if(otherQnaireRId == empty)
{
    array user = User_getUserByResourceId(userRId);
    user[USER_FIRST_NAME] = "";
    user[USER_MIDDLE_NAME] = "";
    user[USER_LAST_NAME] = "";
    user[USER_PHONE_NUMBER] = {};
    user[USER_EMAIL] = "";
    user[USER_CURRENCY] = "";
    user[USER_TIMEZONE] = 0;
    user[USER_ADDRESS] = "";
    user[USER_CITY] = "";
    user[USER_ZIPCODE] = "";
    user[USER_REGION] = "";
    user[USER_COUNTRY] = "";
    user[USER_POSTBOX] = "";
    user[USER_WEBSITE] = "";
    User_save(user);
    print("The user is anonymized");
}
else print("The user is not anonymized due to being use on another qnaire:"+ convertToString(otherQnaireRId));

Scenario 3

Option 1 (Via GUI):

0. Check that the user isn’t used in any other questionnaire
1. Delete the User
2. Converting the QAS to no user
3. Delete data marked with "delete when anonymizing" in the questionnaire
4. Destroy the user

Option 2 (Via CgScript):

 
number qnaireRId = xxxx;
number userRId = xxxx;
array otherQnaireRId;
array qas = QAS_getByUserResourceId (userRId);
for(i for 0; qas.Count)
{
    if (qas[i][QAS_QUESTIONNAIRE_RESOURCE_ID] == qnaireRId)
    {
        //Delete data marked with "delete when anonymizing" in the questionnaire
        //TODO
        qas[i].UserResourceId = 0;
        qas[i].Save();
    }
    else otherQnaireRId.Add(qas[i][QAS_QUESTIONNAIRE_RESOURCE_ID] );
}
if(otherQnaireRId == empty )
{
    Resource_delete(userRId);
    print("Already deleted user and remove user link ");
}
else print("The user is not deleted due to being use on another qnaire:"+ convertToString(otherQnaireRId)+". So just remove user link");

Scenario 4

Option 1 (Via GUI):

0. Converting the QAS to no user
1. Delete all those data marked with "delete when anonymizing" in the questionnaire

Option 2 (Via CgScript):

number qnaireRId = xxxx;
number userRId = xxxx;
array qas = QAS_getByUserResourceId (userRId, qnaireRId);
for (i for 0; qas.Count)
{   
    qas[i].UserResourceId = 0;
    qas[i].Save();
    //Delete data marked with "delete when anonymizing" in the questionnaire
    //TODO
}

Scenario 5

Option 1 (Via GUI):

0. Check that users of the questionnaire aren’t used in any other questionnaire
1. Delete all associated users of the questionnaire
2. Converting all QASs of the questionnaire to no user
3. Destroy all associated users of the questionnaire
4. Delete the Questionnaire

Option 2 (Via CgScript):

number qnaireRId = xxxx;
number newParentRId = xxxx;
Dictionary userUsedInOtherQnaire;
array userRIdChangedPath;
array qQAS = QAS_getByQuestionnaireResourceId(qnaireRId);
for(j for 0; qQAS.Count)
{
    number userRId = qQAS[j].UserResourceId;
    if(userRId != 0)
    {
        array otherQnaireRId;
        array qas = QAS_getByUserResourceId (userRId);
        for(i for 0; qas.Count)
        {
            if(qas[i][QAS_QUESTIONNAIRE_RESOURCE_ID] == qnaireRId)
            {
                QAS_deleteData({qas[i].Id});
                qas[i].Test= true;
                qas[i].UserResourceId = 0;
                qas[i].Save();
            }
            else
            {
                otherQnaireRId.Add(qas[i][QAS_QUESTIONNAIRE_RESOURCE_ID]);
            }
        }
        if(otherQnaireRId == empty )
        {
            Resource_delete(userRId);
        }
        else
        {
            array userParent  = Resource_getParentResource(userRId);
            if (userParent[0][RESOURCE_RESOURCE_ID] == qnaireRId)
            {
                Resource_setParentResource(userRId, newParentRId);
                userRIdChangedPath.Add(userRId);
            }
            userUsedInOtherQnaire.Add(convertToString(userRId),otherQnaireRId);
        }
    }
}
Resource_delete(qnaireRId);
print("The qnaire is deleted. Associated users also deleted. Some user are not deleted due to being use on another qnaire"+convertToString(userUsedInOtherQnaire)+". And some of them change to new Path because under the deleted qnaire"+convertToString(userRIdChangedPath));

Scenario 6

Option 1 (Via GUI):

0. Converting all QAS of the questionnaire to no user
1. Delete all those data marked with "delete when anonymizing" in the questionnaire
2. Delete the questionnaire

Option 2 (Via CgScript):

number qnaireRId = xxxx;
number newParentRId = xxxx;
array isChangedPathUserRId;
array qas = QAS_getByQuestionnaireResourceId(qnaireRId);
for(i for 0; qas.Count)
{
    number userRId = qas[i].UserResourceId;
    if (userRId !=0)
    {
        array userParent  = Resource_getParentResource(userRId);
        if (userParent[0][RESOURCE_RESOURCE_ID] == qnaireRId)
        {
            Resource_setParentResource(userRId, newParentRId );
            isChangedPathUserRId.Add(userRId);
        }
    }
    QAS_deleteData({qas[i].Id});
    qas[i].Test= true;
    qas[i].UserResourceId = 0;
    qas[i].Save();
}
Resource_delete(qnaireRId);
print("The qnaire is deleted. List UserRId under qnaire already moved to other parent:"+ convertToString(isChangedPathUserRId));

Scenario 7

Option 1 (Via GUI):

0. Check that the user isn’t used in any other questionnaire
1. Delete User
2. Delete QAS
3. Destroy user

Option 2 (Via CgScript):

number qnaireRId = xxxx;
number userRId = xxxx;
array otherQnaireRId;
array qas = QAS_getByUserResourceId (userRId);
for (i for 0; qas.Count )
{
    if(qas[i][QAS_QUESTIONNAIRE_RESOURCE_ID] == qnaireRId)
    {
        QAS_deleteData({qas[i].Id});
        qas[i].Test= true;
        qas[i].UserResourceId = 0;
        qas[i].Save();
    }
    else otherQnaireRId.Add(qas[i][QAS_QUESTIONNAIRE_RESOURCE_ID]);
}
if(otherQnaireRId == empty)
{
    Resource_delete(userRId);
    print("Already deleted user and associated QASs, data");
}
else print("The user is not deleted due to being use on another qnaire:" + convertToString(otherQnaireRId) + ". So just delete associated QASs and data, remove user link");

Scenario 8

Option 1 (Via GUI):

0. Converting the QAS to no user
1. Delete the QAS

Option 2 (Via CgScript):

number qnaireRId = xxxx;
number userRId = xxxx;
array qas = QAS_getByUserResourceId (userRId, qnaireRId);
for(i for 0; qas.Count)
{
    QAS_deleteData({qas[i].Id});
    qas[i].Test= true;
    qas[i].UserResourceId = 0;
    qas[i].Save();
}

Scenario 9

Option 1 (Via GUI):

0. Set data of all questions in the QAS to empty

Option 2 (Via CgScript):

number qnaireRId = xxxx;
number userRId = xxxx;
array qas = QAS_getByUserResourceId (userRId, qnaireRId);
for(i for 0; qas.Count)
{
    QAS_deleteData({qas[i].Id});
}