Skip to content

Commit

Permalink
Merge branch 'release/3.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Dec 20, 2017
2 parents a78299a + 4c9f327 commit 5a86df3
Show file tree
Hide file tree
Showing 24 changed files with 760 additions and 355 deletions.
504 changes: 258 additions & 246 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ object Dependencies {

val reflections = "org.reflections" % "reflections" % "0.9.11"
val zip4j = "net.lingala.zip4j" % "zip4j" % "1.3.2"
val elastic4play = "org.cert-bdf" %% "elastic4play" % "1.4.1"
val elastic4play = "org.cert-bdf" %% "elastic4play" % "1.4.2"
}
}
11 changes: 2 additions & 9 deletions thehive-backend/app/global/Filters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ package global

import javax.inject.{ Inject, Provider, Singleton }

import scala.collection.immutable

import play.api.Logger
import play.api.http.{ HttpFilters, SessionConfiguration }
import play.api.http.SessionConfiguration
import play.api.libs.crypto.CSRFTokenSigner
import play.api.mvc.{ EssentialFilter, RequestHeader }
import play.api.mvc.RequestHeader
import play.filters.csrf.CSRF.{ ErrorHandler, TokenProvider }
import play.filters.csrf.CSRFConfig

import akka.stream.Materializer

@Singleton
class TheHiveFilters @Inject() (injectedFilters: immutable.Set[EssentialFilter]) extends HttpFilters {
override val filters: Seq[EssentialFilter] = injectedFilters.toSeq
}

object CSRFFilter {
private[CSRFFilter] lazy val logger = Logger(getClass)

Expand Down
8 changes: 1 addition & 7 deletions thehive-backend/app/global/TheHive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package global
import scala.collection.JavaConverters._

import play.api.libs.concurrent.AkkaGuiceSupport
import play.api.mvc.EssentialFilter
import play.api.{ Configuration, Environment, Logger, Mode }

import com.google.inject.AbstractModule
Expand All @@ -19,7 +18,7 @@ import services._

import org.elastic4play.models.BaseModelDef
import org.elastic4play.services.auth.MultiAuthSrv
import org.elastic4play.services.{ AuthSrv, MigrationOperations, TempFilter }
import org.elastic4play.services.{ AuthSrv, MigrationOperations }

class TheHive(
environment: Environment,
Expand Down Expand Up @@ -65,11 +64,6 @@ class TheHive(
authBindings.addBinding.to(authSrvClass)
}

val filterBindings = ScalaMultibinder.newSetBinder[EssentialFilter](binder)
filterBindings.addBinding.to[StreamFilter]
filterBindings.addBinding.to[TempFilter]
filterBindings.addBinding.to[CSRFFilter]

bind[MigrationOperations].to[Migration]
bind[AuthSrv].to[TheHiveAuthSrv]

Expand Down
4 changes: 3 additions & 1 deletion thehive-backend/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Dependencies._

resolvers += "elastic" at "https://artifacts.elastic.co/maven"

libraryDependencies ++= Seq(
Library.Play.cache,
Library.Play.ws,
Expand All @@ -12,4 +14,4 @@ libraryDependencies ++= Seq(
Library.reflections
)

play.sbt.routes.RoutesKeys.routesImport -= "controllers.Assets.Asset"
play.sbt.routes.RoutesKeys.routesImport -= "controllers.Assets.Asset"
20 changes: 13 additions & 7 deletions thehive-backend/conf/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
# !!! This file must not be modified !!!
# Custom configuration must be set in application.conf file.

# name of cookie in which the CSRF token is transmitted to client
play.filters.csrf.cookie.name = XSRF-TOKEN
# name of header in which the client should send CSRD token
play.filters.csrf.header.name = X-XSRF-TOKEN
# HTTP filters
play.filters {
# name of cookie in which the CSRF token is transmitted to client
csrf.cookie.name = XSRF-TOKEN
# name of header in which the client should send CSRD token
csrf.header.name = X-XSRF-TOKEN

enabled = [
services.StreamFilter,
org.elastic4play.services.TempFilter,
global.CSRFFilter
]
}

# handler for errors (transform exception to related http status code
play.http.errorHandler = org.elastic4play.ErrorHandler

# Register module for dependency injection
play.modules.enabled += global.TheHive

# handler for requests (check if database is in maintenance or not)
#play.http.requestHandler = TheHiveHostRequestHandler

play.http.filters = global.TheHiveFilters

# ElasticSearch
search {
Expand Down
2 changes: 2 additions & 0 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@
<script src="scripts/directives/dashboard/bar.js"></script>
<script src="scripts/directives/dashboard/counter.js"></script>
<script src="scripts/directives/dashboard/donut.js"></script>
<script src="scripts/directives/dashboard/filter-editor.js"></script>
<script src="scripts/directives/dashboard/item.js"></script>
<script src="scripts/directives/dashboard/line.js"></script>
<script src="scripts/directives/dashboard/multiline.js"></script>
<script src="scripts/directives/dateTimePicker.js"></script>
<script src="scripts/directives/dt-picker.js"></script>
<script src="scripts/directives/entityLink.js"></script>
Expand Down
5 changes: 3 additions & 2 deletions ui/app/scripts/controllers/dashboard/DashboardViewCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@

this.options = {
dashboardAllowedTypes: ['container'],
containerAllowedTypes: ['bar', 'line', 'donut', 'counter'],
containerAllowedTypes: ['bar', 'line', 'donut', 'counter', 'multiline'],
maxColumns: 3,
cls: DashboardSrv.typeClasses,
labels: {
container: 'Row',
bar: 'Bar',
donut: 'Donut',
line: 'Line',
counter: 'Counter'
counter: 'Counter',
multiline: 'Multi Lines'
},
editLayout: !_.find(this.definition.items, function(row) {
return row.items.length > 0;
Expand Down
65 changes: 65 additions & 0 deletions ui/app/scripts/directives/dashboard/filter-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
(function() {
'use strict';
angular.module('theHiveDirectives').directive('filterEditor', function($q, UserSrv) {
return {
restrict: 'E',
scope: {
filter: '=?',
entity: '=',
metadata: '='
},
templateUrl: 'views/directives/dashboard/filter-editor.html',
link: function(scope) {
scope.editorFor = function(filter) {
if (filter.type === null) {
return;
}
var field = scope.metadata[scope.entity].attributes[filter.field];

if(!field) {
return;
}
var type = field.type;

if ((type === 'string' || type === 'number') && field.values.length > 0) {
return 'enumeration';
}

return filter.type;
};

scope.promiseFor = function(filter, query) {
var field = scope.metadata[scope.entity].attributes[filter.field];

var promise = null;

if(field.type === 'user') {
promise = UserSrv.autoComplete(query);
} else if (field.values.length > 0) {
promise = $q.resolve(
_.map(field.values, function(item, index) {
return {
text: item,
label: field.labels[index] || item
};
})
);
} else {
promise = $q.resolve([]);
}

return promise.then(function(response) {
var list = [];

list = _.filter(response, function(item) {
var regex = new RegExp(query, 'gi');
return regex.test(item.label);
});

return $q.resolve(list);
});
};
}
};
});
})();
84 changes: 12 additions & 72 deletions ui/app/scripts/directives/dashboard/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,14 @@
scope.aggregations = DashboardSrv.aggregations;
scope.serieTypes = DashboardSrv.serieTypes;
scope.sortOptions = DashboardSrv.sortOptions;
scope.skipFields = DashboardSrv.skipFields;
scope.pickFields = DashboardSrv.pickFields;
scope.fieldsForAggregation = DashboardSrv.fieldsForAggregation;

scope.layout = {
activeTab: 0
};
scope.query = null;
scope.skipFields = function(fields, types) {
return _.filter(fields, function(item) {
return types.indexOf(item.type) === -1;
});
};

scope.pickFields = function(fields, types) {
return _.filter(fields, function(item) {
return types.indexOf(item.type) !== -1;
});
}

scope.fieldsForAggregation = function(fields, agg) {
if(agg === 'count') {
return [];
} else if(agg === 'sum' || agg === 'avg') {
return scope.pickFields(fields, ['number']);
} else {
return fields;
}
}

if(scope.component.id) {
scope.$on('edit-chart-' + scope.component.id, function(data) {
Expand All @@ -77,17 +59,18 @@
modalInstance.result.then(function(definition) {
var entity = scope.component.options.entity;

if(!entity) {
//if(!entity) {
if(!DashboardSrv.hasMinimalConfiguration(scope.component)) {
return;
}

// Set the computed query
definition.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity].attributes, scope.component.options.filters);
definition.query = DashboardSrv.buildFiltersQuery(entity ? scope.metadata[entity].attributes : null, scope.component.options.filters);

// Set the computed querie of series if available
_.each(definition.series, function(serie) {
if(serie.filters) {
serie.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity].attributes, serie.filters);
serie.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity || serie.entity].attributes, serie.filters);
}
})

Expand All @@ -99,52 +82,6 @@
});
};

scope.editorFor = function(filter) {
if (filter.type === null) {
return;
}
var field = scope.metadata[scope.component.options.entity].attributes[filter.field];
var type = field.type;

if ((type === 'string' || type === 'number') && field.values.length > 0) {
return 'enumeration';
}

return filter.type;
};

scope.promiseFor = function(filter, query) {
var field = scope.metadata[scope.component.options.entity].attributes[filter.field];

var promise = null;

if(field.type === 'user') {
promise = UserSrv.autoComplete(query);
} else if (field.values.length > 0) {
promise = $q.resolve(
_.map(field.values, function(item, index) {
return {
text: item,
label: field.labels[index] || item
};
})
);
} else {
promise = $q.resolve([]);
}

return promise.then(function(response) {
var list = [];

list = _.filter(response, function(item) {
var regex = new RegExp(query, 'gi');
return regex.test(item.label);
});

return $q.resolve(list);
});
};

scope.addFilter = function() {
scope.component.options.filters = scope.component.options.filters || [];

Expand All @@ -158,10 +95,13 @@
scope.component.options.filters.splice(index, 1);
};

scope.setFilterField = function(filter) {
var entity = scope.component.options.entity;
scope.setFilterField = function(filter, entity) {
var field = scope.metadata[entity].attributes[filter.field];

if(!field) {
return;
}

filter.type = field.type;

if (field.type === 'date') {
Expand Down
Loading

0 comments on commit 5a86df3

Please sign in to comment.