Beispiel #1
0
def subscribe_to_source(username, source):
    """
    Subscribe a user to a source.

    :param username: The user to query for.
    :type username: str
    :param source: The name of the source.
    :type source: str
    :returns: dict with keys "success" (boolean) and "message" (str) if failed.
    """

    from crits.core.user import EmbeddedSourceSubscription
    from crits.core.user import CRITsUser
    username = str(username)
    user = CRITsUser.objects(username=username).first()
    es = EmbeddedSourceSubscription()
    es.name = source
    user.subscriptions['Source'].append(es)
    try:
        user.save()
        return {'success': True}
    except ValidationError, e:
        return {'success': False, 'message': e}
Beispiel #2
0
def subscribe_to_source(username, source):
    """
    Subscribe a user to a source.

    :param username: The user to query for.
    :type username: str
    :param source: The name of the source.
    :type source: str
    :returns: dict with keys "success" (boolean) and "message" (str) if failed.
    """

    from crits.core.user import EmbeddedSourceSubscription
    from crits.core.user import CRITsUser
    username = str(username)
    user = CRITsUser.objects(username=username).first()
    es = EmbeddedSourceSubscription()
    es.name = source
    user.subscriptions['Source'].append(es)
    try:
        user.save()
        return {'success': True}
    except ValidationError, e:
        return {'success': False,
                'message': e}