-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
managegdpr.controller.js
159 lines (137 loc) · 5.87 KB
/
managegdpr.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*!
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
(function () {
angular.module('piwikApp').controller('ManageGdprController', ManageGdprController);
ManageGdprController.$inject = ["$scope", "piwikApi", "piwik", "$timeout"];
function ManageGdprController($scope, piwikApi, piwik, $timeout) {
var self = this;
this.isLoading = false;
this.isDeleting = false;
this.site = {id: 'all', name: 'All Websites'};
this.segment_filter = 'userId==';
this.dataSubjects = [];
this.toggleAll = true;
this.hasSearched = false
var sitesPromise = piwikApi.fetch({method: 'SitesManager.getSitesIdWithAdminAccess', filter_limit: '-1'});
this.linkTo = function (action){
var currentUrl = window.location.pathname + window.location.search;
var newUrl = piwik.broadcast.updateParamValue('module=PrivacyManager', currentUrl);
newUrl = piwik.broadcast.updateParamValue('action=' + action, newUrl);
return newUrl;
}
function showSuccessNotification(message)
{
var UI = require('piwik/UI');
var notification = new UI.Notification();
notification.show(message, {context: 'success', id: 'manageGdpr'});
$timeout(function () {
notification.scrollToNotification();
}, 200);
}
this.toggleActivateAll = function () {
var toggleAll = this.toggleAll;
angular.forEach(this.dataSubjects, function (dataSubject) {
dataSubject.dataSubjectActive = toggleAll;
});
};
this.hasActiveDataSubjects = function()
{
return !!this.getActivatedDataSubjects().length;
};
this.getActivatedDataSubjects = function () {
var visitsToDelete = [];
angular.forEach(this.dataSubjects, function (visit) {
if (visit.dataSubjectActive) {
visitsToDelete.push({idsite: visit.idSite, idvisit: visit.idVisit});
}
});
return visitsToDelete;
}
this.showProfile = function (visitorId, idSite) {
require('piwik/UI').VisitorProfileControl.showPopover(visitorId, idSite);
};
this.exportDataSubject = function () {
var visitsToDelete = this.getActivatedDataSubjects();
piwikApi.post({
module: 'API',
method: 'PrivacyManager.exportDataSubjects',
format: 'json',
filter_limit: -1,
}, {visits: visitsToDelete}).then(function (visits) {
showSuccessNotification('Visits were successfully exported');
piwik.helper.sendContentAsDownload('exported_data_subjects.json', JSON.stringify(visits));
});
};
this.deleteDataSubject = function () {
piwik.helper.modalConfirm('#confirmDeleteDataSubject', {yes: function () {
self.isDeleting = true;
var visitsToDelete = self.getActivatedDataSubjects();
piwikApi.post({
module: 'API',
method: 'PrivacyManager.deleteDataSubjects',
filter_limit: -1,
}, {visits: visitsToDelete}).then(function (visits) {
self.dataSubjects = [];
self.isDeleting = false;
showSuccessNotification('Visits were successfully deleted');
self.findDataSubjects();
}, function () {
self.isDeleting = false;
});
}});
};
this.addFilter = function (segment, value) {
this.segment_filter += ',' + segment + '==' + value;
this.findDataSubjects();
};
this.findDataSubjects = function () {
this.dataSubjects = [];
this.isLoading = true;
this.toggleAll = true;
function addDatePadding(number)
{
if (number < 10) {
return '0' + number;
}
return number;
}
var now = new Date();
var dateString = (now.getFullYear() + 2) + '-' + addDatePadding(now.getMonth() + 1) + '-' + addDatePadding(now.getDay());
// we are adding two years to make sure to also capture some requests in the future as we fetch data across
// different sites and different timezone and want to avoid missing any possible requests
sitesPromise.then(function (idsites) {
var siteIds = self.site.id;
if (siteIds === 'all' && !piwik.hasSuperUserAccess) {
// when superuser, we speed the request up a little and simply use 'all'
siteIds = idsites;
if (angular.isArray(idsites)) {
siteIds = idsites.join(',');
}
}
piwikApi.fetch({
idSite: siteIds,
period: 'range',
date: '1998-01-01,today',
module: 'API',
method: 'Live.getLastVisitsDetails',
segment: self.segment_filter,
filter_limit: 401,
doNotFetchActions: 1
}).then(function (visits) {
self.hasSearched = true;
angular.forEach(visits, function (visit) {
visit.dataSubjectActive = true;
});
self.dataSubjects = visits;
self.isLoading = false;
}, function () {
self.isLoading = false;
});
});
};
}
})();