def _get_object(self, object_id, eagerload=False, **kwargs): """ Given the object_id and extra route params, get an instance of ``self.model_class`` """ confirmed = self._get_querystring_boolean_field('confirmed') active = self._get_querystring_boolean_field('active') status = flask.request.args.get('status') extra_query = None if status and status in Vulnerability.STATUSES: extra_query = f"status='{status}'" self._validate_object_id(object_id) query = db.session.query(Workspace).filter_by(name=object_id) if active is not None: query = query.filter_by(active=active) query = query.options( with_expression( Workspace.vulnerability_web_count, _make_vuln_count_property('vulnerability_web', confirmed=confirmed, extra_query=extra_query, use_column_property=False), ), with_expression( Workspace.vulnerability_standard_count, _make_vuln_count_property('vulnerability', confirmed=confirmed, extra_query=extra_query, use_column_property=False)), with_expression( Workspace.vulnerability_total_count, _make_vuln_count_property(type_=None, confirmed=confirmed, extra_query=extra_query, use_column_property=False)), with_expression( Workspace.vulnerability_code_count, _make_vuln_count_property('vulnerability_code', extra_query=extra_query, use_column_property=False), ), with_expression( Workspace.active_agents_count, _make_active_agents_count_property(), ), ) query = count_vulnerability_severities(query, Workspace, status=status, confirmed=confirmed, all_severities=True) try: obj = query.one() except NoResultFound: flask.abort(404, f'Object with name "{object_id}" not found') return obj
def _get_object(self, object_id, eagerload=False, **kwargs): """ Given the object_id and extra route params, get an instance of ``self.model_class`` """ confirmed = self._get_querystring_boolean_field('confirmed') active = self._get_querystring_boolean_field('active') self._validate_object_id(object_id) query = db.session.query(Workspace).filter_by(name=object_id) if active is not None: query = query.filter_by(active=active) query = query.options( with_expression( Workspace.vulnerability_web_count, _make_vuln_count_property('vulnerability_web', confirmed=confirmed, use_column_property=False), ), with_expression( Workspace.vulnerability_standard_count, _make_vuln_count_property('vulnerability', confirmed=confirmed, use_column_property=False)), with_expression( Workspace.vulnerability_total_count, _make_vuln_count_property(type_=None, confirmed=confirmed, use_column_property=False)), with_expression( Workspace.vulnerability_code_count, _make_vuln_count_property('vulnerability_code', use_column_property=False)), ) try: obj = query.one() except NoResultFound: flask.abort(404, 'Object with name "%s" not found' % object_id) return obj