Answers.Body: <p>I assume writing a little extension that picks up the delete with the civicrm_pre hook is a fairy elegant way?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-14T09:21:14.817Z
Answers.LastActivityDate: 2017-06-14T09:21:14.817Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>Another way to approach this, if you're trying to avoid coding, would be to take away the "delete contacts" permission at the CMS permissions level. This would take away the ability to delete contacts unless that permission is explicitly granted by an ACL rule.</p>
  
  <p>The <a href="https://docs.civicrm.org/user/en/latest/initial-set-up/permissions-and-access-control/#native-civicrm-acls" rel="nofollow noreferrer">ACL system</a> lets you get very specific about which contacts may delete other contacts. You could create a static group "Senior Staff" which has permission to delete contacts in a smart group called "Deletables." The task of defining the criteria for inclusion in this smart group is left to the reader.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-21T13:49:31.873Z
Answers.LastActivityDate: 2017-06-21T13:49:31.873Z
Answers.UserDisplayName: universalhandle
Answers.Body: <p>Elaborating on the answer of Erik, I created an extension with the following hook</p>
  
  <pre><code>function preventcontactdelete_civicrm_pre($op, $objectName, $id, &amp;$params) {
    if ($objectName == 'Individual' &amp;&amp; $op == 'update') {
      if ($params['is_deleted'] &amp;&amp; CRM_Preventcontactdelete_Check::hasRecentContribution($id)) {
        throw new Exception("Delete of contact $id not allowed - it has recent contributions");
      }
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-14T17:36:27.360Z
Answers.LastActivityDate: 2017-06-14T17:36:27.360Z
Answers.UserDisplayName: Kainuk - CiviCooP
Answers.Body: <p>If I am not mistaken, CiviCRM will (at least via the UI) does not allow contacts with live finacial transactions (so everyone with a completed donation) to be permanently deleted, unless you delete the contributions first. </p>
  
  <p>This way, accidental deletion would not be possible and you can always not grant users the permission to delet contributions... </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-21T20:41:06.720Z
Answers.Text: This really seems like the best answer ;-)
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T11:52:33.380Z
Answers.Text: It is true you cannot delete a contact with financial transactions. However, it is possible tot put it in trash
Answers.UserDisplayName: Kainuk - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-21T15:39:22.573Z
Answers.LastActivityDate: 2017-06-21T16:03:33.127Z
Answers.LastEditDate: 2017-06-21T16:03:33.127Z
Answers.UserDisplayName: Fabian
Body: <p>In the Netherlands, the taxpayer can deduct gifts to charities from his income tax. The tax authorities take samples and can ask a charity to report the gifts it received from a particular contact. The length of the period they can ask this is seven years. So the records of this contact must be kept in these years.
  Is there an elegant way to prevent deleting, or trashing a contact that gave a contribution in the last seven years?</p>
  
Tags: <contacts><delete>
Title: How to prevent the accidental the deletion of contacts, when an obligation exists to keep their records?
ThreadText: # How to prevent the accidental the deletion of contacts, when an obligation exists to keep their records?
  
  (Asked by: username_0 on 2017-06-14)
  
  In the Netherlands, the taxpayer can deduct gifts to charities from his income tax. The tax authorities take samples and can ask a charity to report the gifts it received from a particular contact. The length of the period they can ask this is seven years. So the records of this contact must be kept in these years.
  Is there an elegant way to prevent deleting, or trashing a contact that gave a contribution in the last seven years?
  
  **Tags:** contacts, delete
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2017-06-14. Score: 2 | Accepted answer
  
  I assume writing a little extension that picks up the delete with the civicrm\_pre hook is a fairy elegant way?
  
  
  ---
  
  ### Answer by username_2 on 2017-06-21. Score: 2
  
  Another way to approach this, if you're trying to avoid coding, would be to take away the "delete contacts" permission at the CMS permissions level. This would take away the ability to delete contacts unless that permission is explicitly granted by an ACL rule.
  
  The [ACL system](https://docs.civicrm.org/user/en/latest/initial-set-up/permissions-and-access-control/#native-civicrm-acls) lets you get very specific about which contacts may delete other contacts. You could create a static group "Senior Staff" which has permission to delete contacts in a smart group called "Deletables." The task of defining the criteria for inclusion in this smart group is left to the reader.
  
  
  ---
  
  ### Answer by username_0 on 2017-06-14. Score: 1
  
  Elaborating on the answer of Erik, I created an extension with the following hook
  function preventcontactdelete_civicrm_pre($op, $objectName, $id, &$params) {
    if ($objectName == 'Individual' && $op == 'update') {
      if ($params['is_deleted'] && CRM_Preventcontactdelete_Check::hasRecentContribution($id)) {
        throw new Exception("Delete of contact $id not allowed - it has recent contributions");
      }
    }
  }
  
  
  ---
  
  ### Answer by username_3 on 2017-06-21. Score: 1
  
  If I am not mistaken, CiviCRM will (at least via the UI) does not allow contacts with live finacial transactions (so everyone with a completed donation) to be permanently deleted, unless you delete the contributions first.
  
  This way, accidental deletion would not be possible and you can always not grant users the permission to delet contributions...
  
  > **Comments:**
  > **username_4**: This really seems like the best answer ;-)  
  > **username_0**: It is true you cannot delete a contact with financial transactions. However, it is possible tot put it in trash  
  
  ---
  
  