diff --git a/app/models/yara_rule.py b/app/models/yara_rule.py index 937b6ba..56b21fc 100755 --- a/app/models/yara_rule.py +++ b/app/models/yara_rule.py @@ -185,7 +185,8 @@ 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: - revisions = Yara_rule_history.query.filter_by(yara_rule_id=self.id).all() + 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() diff --git a/app/routes/releases.py b/app/routes/releases.py index 63062b7..d6d0fde 100644 --- a/app/routes/releases.py +++ b/app/routes/releases.py @@ -149,26 +149,19 @@ def create_release(): db.session.commit() if not release.is_test_release: - history = db.session.query(yara_rule.Yara_rule_history.id, yara_rule.Yara_rule_history.yara_rule_id, - yara_rule.Yara_rule_history.revision).all() - history_mapping = {} - for h in history: - id_, rule_id, revision = h - if not rule_id in history_mapping: - history_mapping[rule_id] = {} - if not revision in history_mapping[rule_id]: - history_mapping[rule_id][revision] = id_ - release_data = release.release_data_dict release_yara_rule_history_list = [] for sig_id in release_data["Signatures"]["Signatures"].keys(): revision = release_data["Signatures"]["Signatures"][sig_id]["revision"] sig_id = int(sig_id) revision = int(revision) - if not sig_id in history_mapping: - history_mapping[sig_id] = {} - if not revision in history_mapping[sig_id]: + revision_entity = db.session.query(yara_rule.Yara_rule_history) \ + .filter_by(yara_rule_id=sig_id) \ + .filter_by(revision=revision) \ + .first() + + if not revision_entity: yr = db.session.query(yara_rule.Yara_rule).get(sig_id) latest = yara_rule.Yara_rule_history( date_created=datetime.datetime.now(), @@ -180,10 +173,10 @@ def create_release(): ) db.session.add(latest) db.session.flush() - history_mapping[sig_id][revision] = latest.id + revision_entity = latest release_yara_rule_history_list.append( - {"yara_rules_history_id": history_mapping[sig_id][revision], "release_id": release.id}) + {"yara_rules_history_id": revision_entity.id, "release_id": release.id}) if release_yara_rule_history_list: app.logger.debug( diff --git a/app/static/js/yara_rule/yara_rule-controller.js b/app/static/js/yara_rule/yara_rule-controller.js index 48d5877..a921f99 100755 --- a/app/static/js/yara_rule/yara_rule-controller.js +++ b/app/static/js/yara_rule/yara_rule-controller.js @@ -273,7 +273,7 @@ angular.module('ThreatKB') }, { name: 'Actions', - width: '160', + width: '180', enableFiltering: false, enableColumnMenu: false, enableSorting: false, @@ -290,6 +290,12 @@ angular.module('ThreatKB') + '' + '' + ' ' + + '' + + ' ' + ' + Edit + + + +