Skip to content

Commit

Permalink
Issue #445 & #434 : Cleaning up from Edit modal and ensuring it's not…
Browse files Browse the repository at this point in the history
… fetched when it's not supposed to.
  • Loading branch information
dcuellar322 committed Feb 20, 2023
1 parent 4ccdad9 commit 0931333
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 85 deletions.
7 changes: 4 additions & 3 deletions app/models/yara_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def metadata_values(self):

def to_dict(self, include_yara_rule_string=None, short=False, include_relationships=True, include_metadata=True,
include_tags=True, include_comments=True, metadata_cache=None, users_cache=None, tags_mapping_cache=None,
comments_cache=None):
comments_cache=None, include_revisions=True):
yara_dict = dict(
creation_date=self.creation_date.isoformat() if self.creation_date else None,
last_revision_date=self.last_revision_date.isoformat() if self.last_revision_date else None,
Expand Down Expand Up @@ -185,8 +185,9 @@ def to_dict(self, include_yara_rule_string=None, short=False, include_relationsh
yara_dict["owner_user"] = self.owner_user.to_dict() if self.owner_user else None

if not short:
revision_limit = int(cfg_settings.Cfg_settings.get_setting("FETCH_REVISION_COUNT_LIMIT") or 25)
revisions = Yara_rule_history.query.filter_by(yara_rule_id=self.id).order_by(Yara_rule_history.date_created.desc()).limit(revision_limit).all()
if include_revisions:
revision_limit = int(cfg_settings.Cfg_settings.get_setting("FETCH_REVISION_COUNT_LIMIT") or 25)
revisions = Yara_rule_history.query.filter_by(yara_rule_id=self.id).order_by(Yara_rule_history.date_created.desc()).limit(revision_limit).all()
comments = Comments.query.filter_by(entity_id=self.id).filter_by(
entity_type=ENTITY_MAPPING["SIGNATURE"]).all()
files = Files.query.filter_by(entity_id=self.id).filter_by(entity_type=ENTITY_MAPPING["SIGNATURE"]).all()
Expand Down
3 changes: 2 additions & 1 deletion app/routes/yara_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def get_yara_rule(id):
"""Return yara_rule artifact associated with the given id
Return: yara_rule artifact dictionary"""
include_yara_string = request.args.get("include_yara_string", False)
include_revisions = request.args.get("include_revisions", True)
short = distutils.util.strtobool(request.args.get("short", "false"))

if include_yara_string:
Expand All @@ -253,7 +254,7 @@ def get_yara_rule(id):
if not current_user.admin and entity.owner_user_id != current_user.id:
abort(403)

return_dict = entity.to_dict(include_yara_string, short)
return_dict = entity.to_dict(include_yara_string, short, include_revisions)
return_dict["bookmarked"] = True if is_bookmarked(ENTITY_MAPPING["SIGNATURE"], id, current_user.id) \
else False

Expand Down
6 changes: 3 additions & 3 deletions app/static/js/yara_rule/yara_rule-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,20 +410,20 @@ angular.module('ThreatKB')
};

$scope.update = function (id) {
$scope.yara_rule = Yara_rule.resource.get({id: id, include_yara_string: 1});
$scope.yara_rule = Yara_rule.resource.get({id: id, include_yara_string: 1, include_revisions: 0});
$scope.cfg_states = Cfg_states.query();
$scope.users = Users.query();
$scope.cfg_category_range_mapping = CfgCategoryRangeMapping.query();
$scope.edit(id);
};

$scope.viewRule = function (id) {
$scope.yara_rule = Yara_rule.resource.get({id: id, include_yara_string: 1});
$scope.yara_rule = Yara_rule.resource.get({id: id, include_yara_string: 1, include_revisions: 0});
$scope.view(id);
};

$scope.viewRevision = function (id) {
$scope.yara_rule = Yara_rule.resource.get({id: id, include_yara_string: 1});
$scope.yara_rule = Yara_rule.resource.get({id: id, include_yara_string: 1, include_revisions: 1});
$scope.revision_view(id);
};

Expand Down
78 changes: 0 additions & 78 deletions app/static/views/yara_rule/yara_rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -684,84 +684,6 @@ <h4 class="modal-title" id="myC2ipLabel" style="float: left">
</uib-accordion>
</div>
</div>

<div ng-if="yara_rule.id && yara_rule.revisions && yara_rule.revisions.length">
<style type="text/css">
.yara-revisions {
}

.yara-revisions > div.yara-revisions-select {
display: flex;
}

.yara-revisions > div.yara-revisions-select > div {
flex: 1;
padding: 4px 8px;
}

.yara-revisions > div.yara-revisions-select > div > label {
display: block;
}

.yara-revisions > div.yara-revisions-select > div > select {
display: block;
width: 100%;
}

.yara-revisions > div.yara-revisions-view {
overflow-y: auto;
}

.yara-revisions > div.yara-revisions-view > pre {
height: 320px;
}

.yara-revisions > div.yara-revisions-view > pre del {
background: #fdaeb7;
}

.yara-revisions > div.yara-revisions-view > pre ins {
background: #cdffd8;
}
</style>
<label>Revisions ({{ yara_rule.revisions.length + 1 }})</label>
<div class="yara-revisions">
<div class="yara-revisions-select">
<div>
<label>View</label>
<select ng-model="selectedRevisions.main">
<option ng-value="null">
CURRENT @{{ yara_rule.last_revision_date | date:'yyyy-MM-dd' }}
by {{ yara_rule.modified_user.email }}
</option>
<option ng-repeat="rev in yara_rule.revisions | orderBy:'-date_created'"
ng-value="rev">
Rev. {{ rev.revision }} @{{ rev.date_created | date:'yyyy-MM-dd' }}
by {{ rev.user.email }}
{{ rev.releases ? ' - Releases: ' + rev.releases : '' }}
</option>
</select>
</div>
<div>
<label>Diff</label>
<select ng-model="selectedRevisions.compared">
<option ng-value="null"> None</option>
<option ng-repeat="rev in yara_rule.revisions | orderBy:'-date_created'"
ng-value="rev"
ng-show="rev.revision < (selectedRevisions.main ? selectedRevisions.main.revision : yara_rule.revision)">
Rev. {{ rev.revision }} @{{ rev.date_created | date:'yyyy-MM-dd' }}
by {{ rev.user.email }}
</option>
</select>
</div>
</div>
<div class="yara-revisions-view" ng-controller="Yara_revisionController">
<pre ng-if="revision_diff"><code ng-bind-html="revision_diff"></code></pre>
<pre ng-if="!revision_diff"><code> {{ selectedRevisions.main ? selectedRevisions.main.yara_rule_string : yara_rule.yara_rule_string }} </code></pre>
</div>
</div>

</div>
</div>

<div class="modal-footer">
Expand Down

0 comments on commit 0931333

Please sign in to comment.