diff options
Diffstat (limited to 'plugins/PrivacyManager/API.php')
-rw-r--r-- | plugins/PrivacyManager/API.php | 110 |
1 files changed, 107 insertions, 3 deletions
diff --git a/plugins/PrivacyManager/API.php b/plugins/PrivacyManager/API.php index cfea40529e..93f96101be 100644 --- a/plugins/PrivacyManager/API.php +++ b/plugins/PrivacyManager/API.php @@ -8,10 +8,14 @@ namespace Piwik\Plugins\PrivacyManager; -use Piwik\DataTable; -use Piwik\DataTable\Row; use Piwik\Piwik; use Piwik\Config as PiwikConfig; +use Piwik\Plugins\PrivacyManager\Model\DataSubjects; +use Piwik\Plugins\PrivacyManager\Dao\LogDataAnonymizer; +use Piwik\Plugins\PrivacyManager\Model\LogDataAnonymizations; +use Piwik\Plugins\PrivacyManager\Validators\VisitsDataSubject; +use Piwik\Site; +use Piwik\Validators\BaseValidator; /** * API for plugin PrivacyManager @@ -20,11 +24,103 @@ use Piwik\Config as PiwikConfig; */ class API extends \Piwik\Plugin\API { + /** + * @var DataSubjects + */ + private $gdpr; + + /** + * @var LogDataAnonymizations + */ + private $logDataAnonymizations; + + /** + * @var LogDataAnonymizer + */ + private $logDataAnonymizer; + + public function __construct(DataSubjects $gdpr, LogDataAnonymizations $logDataAnonymizations, LogDataAnonymizer $logDataAnonymizer) + { + $this->gdpr = $gdpr; + $this->logDataAnonymizations = $logDataAnonymizations; + $this->logDataAnonymizer = $logDataAnonymizer; + } + + private function checkDataSubjectVisits($visits) + { + BaseValidator::check('visits', $visits, [new VisitsDataSubject()]); + + $idSites = array(); + foreach ($visits as $index => $visit) { + $idSites[] = $visit['idsite']; + } + Piwik::checkUserHasAdminAccess($idSites); + } + + public function deleteDataSubjects($visits) + { + Piwik::checkUserHasSomeAdminAccess(); + + $this->checkDataSubjectVisits($visits); + + return $this->gdpr->deleteDataSubjects($visits); + } + + public function exportDataSubjects($visits) + { + Piwik::checkUserHasSomeAdminAccess(); + + $this->checkDataSubjectVisits($visits); + + return $this->gdpr->exportDataSubjects($visits); + } + + public function anonymizeSomeRawData($idSites, $date, $anonymizeIp = false, $anonymizeLocation = false, $anonymizeUserId = false, $unsetVisitColumns = [], $unsetLinkVisitActionColumns = []) + { + Piwik::checkUserHasSuperUserAccess(); + + if ($idSites === 'all' || empty($idSites)) { + $idSites = null; // all websites + } else { + $idSites = Site::getIdSitesFromIdSitesString($idSites); + } + $requester = Piwik::getCurrentUserLogin(); + $this->logDataAnonymizations->scheduleEntry($requester, $idSites, $date, $anonymizeIp, $anonymizeLocation, $anonymizeUserId, $unsetVisitColumns, $unsetLinkVisitActionColumns); + } + + public function getAvailableVisitColumnsToAnonymize() + { + Piwik::checkUserHasSuperUserAccess(); + + $columns = $this->logDataAnonymizer->getAvailableVisitColumnsToAnonymize(); + return $this->formatAvailableColumnsToAnonymize($columns); + } + + public function getAvailableLinkVisitActionColumnsToAnonymize() + { + Piwik::checkUserHasSuperUserAccess(); + + $columns = $this->logDataAnonymizer->getAvailableLinkVisitActionColumnsToAnonymize(); + return $this->formatAvailableColumnsToAnonymize($columns); + } + + private function formatAvailableColumnsToAnonymize($columns) + { + ksort($columns); + $formatted = array(); + foreach ($columns as $column => $default) { + $formatted[] = array( + 'column_name' => $column, + 'default_value' => $default + ); + } + return $formatted; + } /** * @internal */ - public function setAnonymizeIpSettings($anonymizeIPEnable, $maskLength, $useAnonymizedIpForVisitEnrichment) + public function setAnonymizeIpSettings($anonymizeIPEnable, $maskLength, $useAnonymizedIpForVisitEnrichment, $anonymizeUserId = false, $anonymizeOrderId = false) { Piwik::checkUserHasSuperUserAccess(); @@ -40,6 +136,14 @@ class API extends \Piwik\Plugin\API $privacyConfig->ipAddressMaskLength = (int) $maskLength; $privacyConfig->useAnonymizedIpForVisitEnrichment = (bool) $useAnonymizedIpForVisitEnrichment; + if (false !== $anonymizeUserId) { + $privacyConfig->anonymizeUserId = (bool) $anonymizeUserId; + } + + if (false !== $anonymizeOrderId) { + $privacyConfig->anonymizeOrderId = (bool) $anonymizeOrderId; + } + return true; } |