Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#243 : adding tags to ui-grid for c2dns/c2ip. #272

Merged
merged 1 commit into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/routes/c2dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from dateutil import parser
from sqlalchemy import exc, and_

from app.models.tags_mapping import Tags_mapping
from app.models.tags import Tags
from app.models.users import KBUser
from app.models.metadata import Metadata, MetadataMapping
from app.models.cfg_states import verify_state
Expand Down Expand Up @@ -39,8 +41,7 @@ def get_all_c2dns():

searches = json.loads(searches)

if searches and any(
[search_key not in c2dns.C2dns.__table__.columns.keys() for search_key, val in searches.items()]):
if searches and any([search_key not in c2dns.C2dns.__table__.columns.keys() and search_key != "tags" for search_key, val in searches.items()]):
entities = c2dns.C2dns.query.outerjoin(Metadata, Metadata.artifact_type == ENTITY_MAPPING["DNS"]).join(
MetadataMapping,
and_(
Expand All @@ -61,6 +62,13 @@ def get_all_c2dns():
KBUser.email.like("%" + str(value) + "%"))
continue

if column == "tags":
entities = entities.outerjoin(Tags_mapping, c2dns.C2dns.id == Tags_mapping.source_id)\
.filter(Tags_mapping.source_table == c2dns.C2dns.__tablename__)\
.join(Tags, Tags_mapping.tag_id == Tags.id)\
.filter(Tags.text.like("%" + str(value) + "%"))
continue

try:
column = getattr(c2dns.C2dns, column)
entities = entities.filter(column.like("%" + str(value) + "%"))
Expand Down
11 changes: 10 additions & 1 deletion app/routes/c2ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from dateutil import parser
from sqlalchemy import exc, and_

from app.models.tags_mapping import Tags_mapping
from app.models.tags import Tags
from app.models.users import KBUser
from app.models.metadata import Metadata, MetadataMapping
from app.models.cfg_states import verify_state
Expand Down Expand Up @@ -38,7 +40,7 @@ def get_all_c2ips():

searches = json.loads(searches)

if searches and any([search_key not in c2ip.C2ip.__table__.columns.keys() for search_key, val in searches.items()]):
if searches and any([search_key not in c2ip.C2ip.__table__.columns.keys() and search_key != "tags" for search_key, val in searches.items()]):
entities = c2ip.C2ip.query.outerjoin(Metadata, Metadata.artifact_type == ENTITY_MAPPING["IP"]).join(
MetadataMapping,
and_(
Expand All @@ -59,6 +61,13 @@ def get_all_c2ips():
KBUser.email.like("%" + str(value) + "%"))
continue

if column == "tags":
entities = entities.outerjoin(Tags_mapping, c2ip.C2ip.id == Tags_mapping.source_id)\
.filter(Tags_mapping.source_table == c2ip.C2ip.__tablename__)\
.join(Tags, Tags_mapping.tag_id == Tags.id)\
.filter(Tags.text.like("%" + str(value) + "%"))
continue

try:
column = getattr(c2ip.C2ip, column)
entities = entities.filter(column.like("%" + str(value) + "%"))
Expand Down
19 changes: 16 additions & 3 deletions app/static/js/c2dns/c2dns-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ angular.module('ThreatKB')
[
{
field: 'domain_name',
width: '320',
width: '300'
},
{
field: 'date_created',
displayName: "Created Date",
enableSorting: true,
width: '180',
width: '150',
cellFilter: 'date:\'yyyy-MM-dd HH:mm:ss\''
},
{
Expand All @@ -112,6 +112,7 @@ angular.module('ThreatKB')
{
field: 'state',
displayName: 'State',
width: '130',
enableSorting: true,
cellTemplate: '<ui-select append-to-body="true" ng-model="row.entity.state"'
+ ' on-select="grid.appScope.save(row.entity)">'
Expand All @@ -128,7 +129,7 @@ angular.module('ThreatKB')
{
field: 'owner_user.email',
displayName: 'Owner',
width: '180',
width: '170',
enableSorting: false,
cellTemplate: '<ui-select append-to-body="true" ng-model="row.entity.owner_user"'
+ ' on-select="grid.appScope.save(row.entity)">'
Expand All @@ -142,6 +143,18 @@ angular.module('ThreatKB')
+ '</ui-select>'
+ '</div>'
},
{
field: 'tags',
displayName: 'Tags',
width: '180',
enableSorting: false,
cellTemplate: '<ul class="gridTags" append-to-body="true" ng-model="row.entity.tags">'
+ '<li ng-repeat="tag in (row.entity.tags | filter: $select.search) track by tag.id">'
+ '<small>{{tag.text}}</small>'
+ '</li>'
+ '</ul>'
+ '</div>'
},
{
name: 'Actions',
width: '120',
Expand Down
18 changes: 15 additions & 3 deletions app/static/js/c2ip/c2ip-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ angular.module('ThreatKB')
field: 'date_created',
displayName: "Created Date",
enableSorting: true,
width: '180',
width: '150',
cellFilter: 'date:\'yyyy-MM-dd HH:mm:ss\''
},
{
Expand All @@ -114,7 +114,7 @@ angular.module('ThreatKB')
{
field: 'state',
displayName: 'State',
width: '180',
width: '130',
enableSorting: true,
cellTemplate: '<ui-select append-to-body="true" ng-model="row.entity.state"'
+ ' on-select="grid.appScope.save(row.entity)">'
Expand All @@ -131,7 +131,7 @@ angular.module('ThreatKB')
{
field: 'owner_user.email',
displayName: 'Owner',
width: '180',
width: '170',
enableSorting: false,
cellTemplate: '<ui-select append-to-body="true" ng-model="row.entity.owner_user"'
+ ' on-select="grid.appScope.save(row.entity)">'
Expand All @@ -145,6 +145,18 @@ angular.module('ThreatKB')
+ '</ui-select>'
+ '</div>'
},
{
field: 'tags',
displayName: 'Tags',
width: '180',
enableSorting: false,
cellTemplate: '<ul class="gridTags" append-to-body="true" ng-model="row.entity.tags">'
+ '<li ng-repeat="tag in (row.entity.tags | filter: $select.search) track by tag.id">'
+ '<small>{{tag.text}}</small>'
+ '</li>'
+ '</ul>'
+ '</div>'
},
{
name: 'Actions',
width: '120',
Expand Down
20 changes: 20 additions & 0 deletions app/static/views/c2dns/c2dns.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,26 @@ <h4 class="modal-title" id="myC2dnsLabel">
</button>
</div>
<br>
<style type="text/css">
.gridTags {
padding: 0;
width:180px;
height: 2em;
line-height: 1em;
text-overflow: ellipsis;
word-break: break-all;
overflow:hidden;
white-space: nowrap;
}
.gridTags:hover{
overflow: visible;
white-space: normal;
height:auto;
}
.gridTags li:not(:last-child):after {
content: ", ";
}
</style>
<div ui-if="gridOptions.data.length > 0" ui-grid="gridOptions" ng-style="getTableHeight()"
ui-grid-pagination ui-grid-auto-resize>
</div>
Expand Down
20 changes: 20 additions & 0 deletions app/static/views/c2ip/c2ips.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,26 @@ <h4 class="modal-title" id="myC2ipLabel">
</button>
</div>
<br>
<style type="text/css">
.gridTags {
padding: 0;
width:180px;
height: 2em;
line-height: 1em;
text-overflow: ellipsis;
word-break: break-all;
overflow:hidden;
white-space: nowrap;
}
.gridTags:hover{
overflow: visible;
white-space: normal;
height:auto;
}
.gridTags li:not(:last-child):after {
content: ", ";
}
</style>
<div ui-if="gridOptions.data.length > 0" ui-grid="gridOptions" ng-style="getTableHeight()"
ui-grid-pagination ui-grid-auto-resize>
</div>
Expand Down