def __init__(self, username, *args, **kwargs): super(SourceForm, self).__init__(*args, **kwargs) self.fields['name'].choices = [(c.name, c.name) for c in get_source_names(True, True, username)] self.fields['name'].initial = get_user_organization(username)
def __init__(self, username, *args, **kwargs): super(EmailAddressForm, self).__init__(*args, **kwargs) self.fields['source'].choices = [ (c.name, c.name) for c in get_source_names(True, True, username) ] self.fields['source'].initial = get_user_organization(username) add_bucketlist_to_form(self) add_ticket_to_form(self)
def __init__(self, username, *args, **kwargs): super(AddObjectForm, self).__init__(*args, **kwargs) self.fields['object_type'].choices = [ (c, c) for c in ObjectTypes.values(sort=True) ] self.fields['object_type'].widget.attrs = {'class': 'object-types'} self.fields['source'].choices = [ (c.name, c.name) for c in get_source_names(True, True, username) ] self.fields['source'].initial = get_user_organization(username)
def __init__(self, username, *args, **kwargs): super(UserNameForm, self).__init__(*args, **kwargs) self.fields['source'].choices = [(c.name, c.name) for c in get_source_names(True, True, username)] self.fields['source'].initial = get_user_organization(username) add_bucketlist_to_form(self) add_ticket_to_form(self)
def __init__(self, username, *args, **kwargs): super(EventForm, self).__init__(*args, **kwargs) self.fields["source"].choices = [(c.name, c.name) for c in get_source_names(True, True, username)] self.fields["source"].initial = get_user_organization(username) self.fields["event_type"].choices = [(c, c) for c in EventTypes.values(sort=True)] self.fields["relationship_type"].choices = relationship_choices self.fields["relationship_type"].initial = RelationshipTypes.RELATED_TO add_bucketlist_to_form(self) add_ticket_to_form(self)
def comment_add(cleaned_data, obj_type, obj_id, method, subscr, analyst): """ Add a new comment. :param cleaned_data: Cleaned data from the Django form submission. :type cleaned_data: dict :param obj_type: The top-level object type to add the comment to. :type obj_type: str :param obj_id: The top-level ObjectId to add the comment to. :type obj_id: str :param method: If this is a reply or not (set method to "reply"). :type method: str :param subscr: The subscription information for the top-level object. :type subscr: dict :param analyst: The user adding the comment. :type analyst: str :returns: dict with keys: 'success' (boolean), 'message': (str), 'html' (str) if successful. """ comment = Comment() comment.comment = cleaned_data['comment'] comment.parse_comment() comment.set_parent_object(obj_type, obj_id) if method == "reply": comment.set_parent_comment(cleaned_data['parent_date'], cleaned_data['parent_analyst']) comment.analyst = analyst comment.set_url_key(cleaned_data['url_key']) source = create_embedded_source(name=get_user_organization(analyst), analyst=analyst) comment.source = [source] try: comment.save(username=analyst) # this is silly :( in the comment object the dates are still # accurate to .###### seconds, but in the database are only # accurate to .### seconds. This messes with the template's ability # to compare creation and edit times. comment.reload() comment.comment_to_html() html = render_to_string( 'comments_row_widget.html', { 'comment': comment, 'user': { 'username': analyst }, 'subscription': subscr }) message = "Comment added successfully!" result = {'success': True, 'html': html, 'message': message} except ValidationError, e: result = {'success': False, 'message': e}
def __init__(self, username, *args, **kwargs): super(AddObjectForm, self).__init__(*args, **kwargs) self.fields['object_type'].choices = [ (c,c) for c in ObjectTypes.values(sort=True) ] self.fields['object_type'].widget.attrs = {'class':'object-types'} self.fields['source'].choices = [(c.name, c.name) for c in get_source_names(True, True, username)] self.fields['source'].initial = get_user_organization(username)
def __init__(self, username, *args, **kwargs): super(EventForm, self).__init__(*args, **kwargs) self.fields['source'].choices = [ (c.name, c.name) for c in get_source_names(True, True, username) ] self.fields['source'].initial = get_user_organization(username) self.fields['event_type'].choices = [ (c, c) for c in EventTypes.values(sort=True) ] self.fields['relationship_type'].choices = relationship_choices self.fields['relationship_type'].initial = RelationshipTypes.RELATED_TO add_bucketlist_to_form(self) add_ticket_to_form(self)
def comment_add(cleaned_data, obj_type, obj_id, method, subscr, analyst): """ Add a new comment. :param cleaned_data: Cleaned data from the Django form submission. :type cleaned_data: dict :param obj_type: The top-level object type to add the comment to. :type obj_type: str :param obj_id: The top-level ObjectId to add the comment to. :type obj_id: str :param method: If this is a reply or not (set method to "reply"). :type method: str :param subscr: The subscription information for the top-level object. :type subscr: dict :param analyst: The user adding the comment. :type analyst: str :returns: dict with keys: 'success' (boolean), 'message': (str), 'html' (str) if successful. """ comment = Comment() comment.comment = cleaned_data['comment'] comment.parse_comment() comment.set_parent_object(obj_type, obj_id) if method == "reply": comment.set_parent_comment(cleaned_data['parent_date'], cleaned_data['parent_analyst']) comment.analyst = analyst comment.set_url_key(cleaned_data['url_key']) source = create_embedded_source(name=get_user_organization(analyst), analyst=analyst) comment.source = [source] try: comment.save(username=analyst) # this is silly :( in the comment object the dates are still # accurate to .###### seconds, but in the database are only # accurate to .### seconds. This messes with the template's ability # to compare creation and edit times. comment.reload() comment.comment_to_html() html = render_to_string('comments_row_widget.html', {'comment': comment, 'user': {'username': analyst}, 'subscription': subscr}) message = "Comment added successfully!" result = {'success': True, 'html': html, 'message': message} except ValidationError, e: result = {'success': False, 'message': e}
def add_new_handler_object(data, rowData, request, is_validate_only=False, is_sort_relationships=False, cache={}, obj=None): """ Add an object to the database. :param data: The data for the object. :type data: dict :param rowData: Data from the row if using mass object upload. :type rowData: dict :param request: The Django request. :type request: :class:`django.http.HttpRequest` :param is_validate_only: Only validate. :type is_validate_only: bool :param cache: Cached data, typically for performance enhancements during bulk operations. :type cache: dict :param obj: The CRIPTs top-level object we are adding objects to. This is an optional parameter used mainly for performance reasons (by not querying mongo if we already have the top level-object). :type obj: :class:`cripts.core.cripts_mongoengine.CriptsBaseAttributes` :returns: tuple (<result>, <retVal>) """ result = False retVal = {} username = request.user.username if data: object_type = data.get('object_type') value = data.get('value') source = data.get('source') method = data.get('method') reference = data.get('reference') otype = data.get('otype') oid = data.get('oid') add_indicator = data.get('add_indicator') elif rowData: object_type = rowData.get(form_consts.Object.OBJECT_TYPE) value = rowData.get(form_consts.Object.VALUE) source = rowData.get(form_consts.Object.SOURCE) method = rowData.get(form_consts.Object.METHOD) reference = rowData.get(form_consts.Object.REFERENCE) otype = rowData.get(form_consts.Object.PARENT_OBJECT_TYPE) oid = rowData.get(form_consts.Object.PARENT_OBJECT_ID) add_indicator = rowData.get(form_consts.Object.ADD_INDICATOR) is_validate_locally = False analyst = "%s" % username # Default the user source to the user's organization if not specified if not source: source = cache.get('object_user_source') if not source: source = get_user_organization(analyst) cache['object_user_source'] = source if (otype == "" or otype == None) or (oid == "" or oid == None): is_validate_locally = True # TODO file_ object_result = add_object(otype, oid, object_type, source, method, reference, analyst, value=value, file_=None, add_indicator=add_indicator, get_objects=False, tlo=obj, is_validate_only=is_validate_only, is_sort_relationships=is_sort_relationships, is_validate_locally=is_validate_locally, cache=cache) if object_result['success']: result = True if 'message' in object_result: retVal['message'] = object_result['message'] if is_validate_only == False: if obj == None: obj = class_from_id(otype, oid) if obj: retVal['secondary'] = {'type': otype, 'id': oid} if object_result.get('relationships'): retVal['secondary']['relationships'] = object_result.get( 'relationships') else: retVal['message'] = object_result['message'] return result, retVal
def add_new_handler_object(data, rowData, request, is_validate_only=False, is_sort_relationships=False, cache={}, obj=None): """ Add an object to the database. :param data: The data for the object. :type data: dict :param rowData: Data from the row if using mass object upload. :type rowData: dict :param request: The Django request. :type request: :class:`django.http.HttpRequest` :param is_validate_only: Only validate. :type is_validate_only: bool :param cache: Cached data, typically for performance enhancements during bulk operations. :type cache: dict :param obj: The CRIPTs top-level object we are adding objects to. This is an optional parameter used mainly for performance reasons (by not querying mongo if we already have the top level-object). :type obj: :class:`cripts.core.cripts_mongoengine.CriptsBaseAttributes` :returns: tuple (<result>, <retVal>) """ result = False retVal = {} username = request.user.username if data: object_type = data.get('object_type') value = data.get('value') source = data.get('source') method = data.get('method') reference = data.get('reference') otype = data.get('otype') oid = data.get('oid') add_indicator = data.get('add_indicator') elif rowData: object_type = rowData.get(form_consts.Object.OBJECT_TYPE) value = rowData.get(form_consts.Object.VALUE) source = rowData.get(form_consts.Object.SOURCE) method = rowData.get(form_consts.Object.METHOD) reference = rowData.get(form_consts.Object.REFERENCE) otype = rowData.get(form_consts.Object.PARENT_OBJECT_TYPE) oid = rowData.get(form_consts.Object.PARENT_OBJECT_ID) add_indicator = rowData.get(form_consts.Object.ADD_INDICATOR) is_validate_locally = False analyst = "%s" % username # Default the user source to the user's organization if not specified if not source: source = cache.get('object_user_source') if not source: source = get_user_organization(analyst) cache['object_user_source'] = source if (otype == "" or otype == None) or (oid == "" or oid == None): is_validate_locally = True # TODO file_ object_result = add_object( otype, oid, object_type, source, method, reference, analyst, value=value, file_=None, add_indicator=add_indicator, get_objects=False, tlo=obj, is_validate_only=is_validate_only, is_sort_relationships=is_sort_relationships, is_validate_locally=is_validate_locally, cache=cache ) if object_result['success']: result = True if 'message' in object_result: retVal['message'] = object_result['message'] if is_validate_only == False: if obj == None: obj = class_from_id(otype, oid) if obj: retVal['secondary'] = {'type': otype, 'id': oid} if object_result.get('relationships'): retVal['secondary']['relationships'] = object_result.get('relationships') else: retVal['message'] = object_result['message'] return result, retVal
def __init__(self, username, *args, **kwargs): super(SourceForm, self).__init__(*args, **kwargs) self.fields['name'].choices = [ (c.name, c.name) for c in get_source_names(True, True, username) ] self.fields['name'].initial = get_user_organization(username)