def on_new_history_entry(sender, instance, created, **kwargs):
    if not created:
        return None

    if instance.is_hidden:
        return None

    model = history_service.get_model_from_key(instance.key)
    pk = history_service.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)

    hipchathooks = _get_project_hipchathooks(obj.project)

    if instance.type == HistoryType.create:
        task = tasks.create_hipchathook
        extra_args = []
    elif instance.type == HistoryType.change:
        task = tasks.change_hipchathook
        extra_args = [instance]
    elif instance.type == HistoryType.delete:
        task = tasks.delete_hipchathook
        extra_args = []

    for hipchathook in hipchathooks:
        args = [hipchathook["url"], hipchathook["notify"], obj] + extra_args

        if settings.CELERY_ENABLED:
            task.delay(*args)
        else:
            task(*args)
示例#2
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if instance._importing:
        return

    if instance.is_hidden:
        return None

    model = history_services.get_model_from_key(instance.key)
    pk = history_services.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)
    project = obj.project

    if instance.type == HistoryType.create:
        event_type = "create"
    elif instance.type == HistoryType.change:
        event_type = "change"
    elif instance.type == HistoryType.delete:
        event_type = "delete"

    user = User.objects.get(id=instance.user["pk"])

    extra_data = {
        "values_diff": instance.values_diff,
        "user": extract_user_info(user),
        "comment": instance.comment,
        "comment_html": instance.comment_html,
    }

    _push_to_timelines(project, user, obj, event_type, extra_data=extra_data)
示例#3
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if not settings.WEBHOOKS_ENABLED:
        return None

    if instance.is_hidden:
        return None

    model = history_service.get_model_from_key(instance.key)
    pk = history_service.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)

    webhooks = _get_project_webhooks(obj.project)

    if instance.type == HistoryType.create:
        task = tasks.create_webhook
        extra_args = []
    elif instance.type == HistoryType.change:
        task = tasks.change_webhook
        extra_args = [instance]
    elif instance.type == HistoryType.delete:
        task = tasks.delete_webhook
        extra_args = [timezone.now()]

    for webhook in webhooks:
        args = [webhook["id"], webhook["url"], webhook["key"], obj
                ] + extra_args

        if settings.CELERY_ENABLED:
            task.delay(*args)
        else:
            task(*args)
def on_new_history_entry(sender, instance, created, **kwargs):
    if not settings.WEBHOOKS_ENABLED:
        return None

    if instance.is_hidden:
        return None

    model = history_service.get_model_from_key(instance.key)
    pk = history_service.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)

    webhooks = _get_project_webhooks(obj.project)

    if instance.type == HistoryType.create:
        task = tasks.create_webhook
        extra_args = []
    elif instance.type == HistoryType.change:
        task = tasks.change_webhook
        extra_args = [instance]
    elif instance.type == HistoryType.delete:
        task = tasks.delete_webhook
        extra_args = [timezone.now()]

    for webhook in webhooks:
        args = [webhook["id"], webhook["url"], webhook["key"], obj] + extra_args

        if settings.CELERY_ENABLED:
            connection.on_commit(lambda: task.delay(*args))
        else:
            connection.on_commit(lambda: task(*args))
示例#5
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if instance._importing:
        return

    if instance.is_hidden:
        return None

    model = history_services.get_model_from_key(instance.key)
    pk = history_services.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)
    project = obj.project

    if instance.type == HistoryType.create:
        event_type = "create"
    elif instance.type == HistoryType.change:
        event_type = "change"
    elif instance.type == HistoryType.delete:
        event_type = "delete"

    user = User.objects.get(id=instance.user["pk"])

    extra_data = {
        "values_diff": instance.values_diff,
        "user": extract_user_info(user),
        "comment": instance.comment,
        "comment_html": instance.comment_html,
    }

    _push_to_timelines(project, user, obj, event_type, extra_data=extra_data)
def set_current_values_of_blocked_note_and_is_blocked_to_the_last_snapshot(
        apps, schema_editor):
    HistoryEntry = apps.get_model("history", "HistoryEntry")

    for history_entry in HistoryEntry.objects.filter(
            is_snapshot=True).order_by("created_at"):
        model = get_model_from_key(history_entry.key)
        pk = get_pk_from_key(history_entry.key)
        try:
            obj = model.objects.get(pk=pk)
            save = False
            if hasattr(obj, "is_blocked"
                       ) and "is_blocked" not in history_entry.snapshot:
                history_entry.snapshot["is_blocked"] = obj.is_blocked
                save = True

            if hasattr(obj, "blocked_note"
                       ) and "blocked_note" not in history_entry.snapshot:
                history_entry.snapshot["blocked_note"] = obj.blocked_note
                save = True

            if save:
                history_entry.save()

        except ObjectDoesNotExist as e:
            pass
def on_new_history_entry(sender, instance, created, **kwargs):
    if not settings.WEBHOOKS_ENABLED:
        return None

    if instance.is_hidden:
        return None

    model = history_service.get_model_from_key(instance.key)
    pk = history_service.get_pk_from_key(instance.key)
    try:
        obj = model.objects.get(pk=pk)
    except model.DoesNotExist:
        # Catch simultaneous DELETE request
        return None

    webhooks = _get_project_webhooks(obj.project)

    if instance.type == HistoryType.create:
        task = tasks.create_webhook
        extra_args = []
    elif instance.type == HistoryType.change:
        task = tasks.change_webhook
        extra_args = [instance]
    elif instance.type == HistoryType.delete:
        task = tasks.delete_webhook
        extra_args = [timezone.now()]

    for webhook in webhooks:
        args = [webhook["id"], webhook["url"], webhook["key"], obj] + extra_args

        if settings.CELERY_ENABLED:
            connection.on_commit(lambda: task.delay(*args))
        else:
            connection.on_commit(lambda: task(*args))
示例#8
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if instance._importing:
        return

    if instance.is_hidden:
        return None

    if instance.user["pk"] is None:
        return None

    refresh_totals = getattr(instance, "refresh_totals", True)

    model = history_services.get_model_from_key(instance.key)
    pk = history_services.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)
    project = obj.project

    if instance.type == HistoryType.create:
        event_type = "create"
    elif instance.type == HistoryType.change:
        event_type = "change"
    elif instance.type == HistoryType.delete:
        event_type = "delete"

    user = get_user_model().objects.get(id=instance.user["pk"])
    values_diff = instance.values_diff
    _clean_description_fields(values_diff)

    extra_data = {
        "values_diff": values_diff,
        "user": extract_user_info(user),
        "comment": instance.comment,
        "comment_html": instance.comment_html,
    }

    # Detect deleted comment
    if instance.delete_comment_date:
        extra_data["comment_deleted"] = True

    # Detect edited comment
    if instance.comment_versions is not None and len(
            instance.comment_versions) > 0:
        extra_data["comment_edited"] = True

    created_datetime = instance.created_at
    _push_to_timelines(
        project,
        user,
        obj,
        event_type,
        created_datetime,
        extra_data=extra_data,
        refresh_totals=refresh_totals,
    )
示例#9
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if instance._importing:
        return

    if instance.is_hidden:
        return None

    if instance.user["pk"] is None:
        return None

    refresh_totals = getattr(instance, "refresh_totals", True)

    model = history_services.get_model_from_key(instance.key)
    pk = history_services.get_pk_from_key(instance.key)
    obj = model.objects.get(pk=pk)
    project = obj.project

    if instance.type == HistoryType.create:
        event_type = "create"
    elif instance.type == HistoryType.change:
        event_type = "change"
    elif instance.type == HistoryType.delete:
        event_type = "delete"

    user = get_user_model().objects.get(id=instance.user["pk"])
    values_diff = instance.values_diff
    _clean_description_fields(values_diff)

    extra_data = {
        "values_diff": values_diff,
        "user": extract_user_info(user),
        "comment": instance.comment,
        "comment_html": instance.comment_html,
    }

    # Detect deleted comment
    if instance.delete_comment_date:
        extra_data["comment_deleted"] = True

    # Detect edited comment
    if instance.comment_versions is not None and len(instance.comment_versions)>0:
        extra_data["comment_edited"] = True

    created_datetime = instance.created_at
    _push_to_timelines(project, user, obj, event_type, created_datetime, extra_data=extra_data, refresh_totals=refresh_totals)
def set_current_values_of_blocked_note_and_is_blocked_to_the_last_snapshot(apps, schema_editor):
    HistoryEntry = apps.get_model("history", "HistoryEntry")

    for history_entry in HistoryEntry.objects.filter(is_snapshot=True).order_by("created_at"):
        model = get_model_from_key(history_entry.key)
        pk = get_pk_from_key(history_entry.key)
        try:
            obj = model.objects.get(pk=pk)
            save = False
            if hasattr(obj, "is_blocked") and "is_blocked" not in history_entry.snapshot:
                history_entry.snapshot["is_blocked"] = obj.is_blocked
                save = True

            if hasattr(obj, "blocked_note") and "blocked_note" not in history_entry.snapshot:
                history_entry.snapshot["blocked_note"] = obj.blocked_note
                save = True

            if save:
                history_entry.save()

        except ObjectDoesNotExist as e:
            pass
示例#11
0
def on_new_history_entry(sender, instance, created, **kwargs):
    if not settings.WEBHOOKS_ENABLED:
        return None

    if instance.is_hidden:
        return None

    model = history_service.get_model_from_key(instance.key)
    pk = history_service.get_pk_from_key(instance.key)
    try:
        obj = model.objects.get(pk=pk)
    except model.DoesNotExist:
        # Catch simultaneous DELETE request
        return None

    webhooks = _get_project_webhooks(obj.project)

    if instance.type == HistoryType.create:
        task = tasks.create_webhook
        extra_args = []
    elif instance.type == HistoryType.change:
        task = tasks.change_webhook
        extra_args = [instance]
    elif instance.type == HistoryType.delete:
        task = tasks.delete_webhook
        extra_args = []

    by = instance.owner
    date = timezone.now()

    for webhook in webhooks:
        args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args

        if settings.CELERY_ENABLED:
            connection.on_commit(lambda: task.delay(*args))
        else:
            connection.on_commit(lambda: task(*args))
示例#12
0
 def check_permissions(self, request, view, obj=None):
     model = get_model_from_key(obj.key)
     pk = get_pk_from_key(obj.key)
     project = model.objects.get(pk=pk)
     return is_project_admin(request.user, project)
示例#13
0
 def check_permissions(self, request, view, obj=None):
     model = get_model_from_key(obj.key)
     pk = get_pk_from_key(obj.key)
     project = model.objects.get(pk=pk)
     return is_project_admin(request.user, project)