Skip to content

Commit 2a932a6

Browse files
committed
Merge pull request #313 from apinf/feature/filtering-data-by-api
Feature/filtering data by api
2 parents 7be901f + 0cd7b7e commit 2a932a6

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

client/views/dashboard/charts/charts.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ Template.chartsLayout.rendered = function () {
1111
index : "api-umbrella-logs-v1-"+currentYearAndMonth,
1212
type : "log",
1313
limit : initialLimit,
14-
query : {
15-
match_all: {}
16-
},
1714
fields: [
1815
'request_at',
1916
'request_ip_country',

client/views/dashboard/charts/filter/filter.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ Template.chartsLayout.events({
2323
index : "api-umbrella-logs-v1-"+year+"-"+month,
2424
type : "log",
2525
limit : limit,
26-
query : {
27-
match_all: {}
28-
},
2926
fields: [
3027
'request_at',
3128
'request_ip_country',

server/methods/elasticSearch.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
Meteor.methods({
22
"getChartData": function (data) {
33

4+
// initialise variables
5+
var loggedInUser;
6+
var apiKey;
7+
var query;
8+
9+
// get user object
10+
loggedInUser = Meteor.user();
11+
12+
// get user role & check user role
13+
if (Roles.userIsInRole(loggedInUser, ['admin'])) {
14+
15+
// if admin - match_all
16+
// construct query
17+
query = {
18+
match_all: {}
19+
}
20+
21+
} else{
22+
23+
// else - user - match api_key: api_key
24+
25+
// get user's api_key
26+
apiKey = loggedInUser.profile.apiKey;
27+
28+
// construct query
29+
query = {
30+
"match": {
31+
"api_key": apiKey
32+
}
33+
}
34+
35+
}
36+
437
var newSearch = new ElasticRest(
538
data.index,
639
data.type,
740
data.limit,
8-
data.query,
41+
query,
942
data.fields
1043
);
1144

0 commit comments

Comments
 (0)