Esempio n. 1
0
def activity_update(id_, activity, user=None, **kwargs):
    """
    Update activity for an Indicator.

    :param id_: The ObjectId of the indicator to update.
    :type id_: str
    :param activity: The activity information.
    :type activity: dict
    :param user: The user updating the activity.
    :type user: str
    :returns: dict with keys:
              "success" (boolean),
              "message" (str) if failed,
              "object" (dict) if successful.
    """

    sources = user_sources(user)
    indicator = Indicator.objects(id=id_, source__name__in=sources).first()
    if not indicator:
        return {"success": False, "message": "Could not find Indicator"}
    try:
        activity = datetime_parser(activity)
        activity["analyst"] = user
        indicator.edit_activity(
            activity["analyst"], activity["start_date"], activity["end_date"], activity["description"], activity["date"]
        )
        indicator.save(username=user)
        return {"success": True, "object": activity}
    except ValidationError, e:
        return {"success": False, "message": e}
Esempio n. 2
0
def activity_remove(id_, date, user, **kwargs):
    """
    Remove activity from an Indicator.

    :param id_: The ObjectId of the indicator to update.
    :type id_: str
    :param date: The date of the activity to remove.
    :type date: datetime.datetime
    :param user: The user removing this activity.
    :type user: str
    :returns: dict with keys "success" (boolean) and "message" (str) if failed.
    """

    indicator = Indicator.objects(id=id_).first()
    if not indicator:
        return {"success": False, "message": "Could not find Indicator"}
    try:

        date = datetime_parser(date)
        indicator.delete_activity(date)
        indicator.save(username=user)
        return {"success": True}
    except ValidationError, e:
        return {"success": False, "message": e}