示例#1
0
def remove_classify_log(sender, **kwargs):
    doc = kwargs.get("document")
    user = kwargs.get("user")

    log = AuditLog(content_type=DOCUMENT_CONTENT_TYPE,
                   object_id=doc.id,
                   user=user,
                   event=events.REMOVE_CLASSIFY_DOCUMENT)
    log.save()
示例#2
0
 def log(self):
     log = AuditLog(user_id=self.user.id,
                    ext_key = self.upgrade.id,
                    apply_level = self.upgrade.apply_level, #当前等级非要升级的等级!
                    result = self.is_valid_result and 1 or 0,#1通过0失败
                    memo   = u'用户升级-自动审核-UpgradeID:%s,Msg:%s' % (self.upgrade.id,string.join(self.msg,sep=','))
                    ) 
     log.save()
     _loginfo.info(string.join(self.msg,sep=','))
示例#3
0
 def log(self):
     log = AuditLog(user_id=self.apply.pk,
                    ext_key = 0,
                    apply_level = 0, #需要修改,注册申请等级是否只能从最低级别开始?
                    type   = 1,
                    result = self.valid_result and 1 or 0,
                    memo   = self.valid_result and u'用户注册-自动审核-通过' or string.join(self.msg,sep=',')
                    ) 
     log.save()
示例#4
0
    def test_data_dog_track_event_not_called_on_audit_log_saved_when_not_configured(
            self, datadog_mock):
        # Given Audit log and project not configured for Datadog
        audit_log = AuditLog(project=self.project, log='Some audit log')

        # When Audit log saved
        audit_log.save()

        # Then datadog track even should not be triggered
        datadog_mock.track_event_async.assert_not_called()
示例#5
0
    def test_organisation_webhooks_are_called_when_audit_log_saved(
            self, mock_call_webhooks):
        # Given
        audit_log = AuditLog(project=self.project, log='Some audit log')

        # When
        audit_log.save()

        # Then
        mock_call_webhooks.assert_called()
示例#6
0
def tag_remove_to_document(sender, **kwargs):
    doc = kwargs.get("document")
    tag = kwargs.get("tag")
    user = kwargs.get("user")

    log = AuditLog(content_type=DOCUMENT_CONTENT_TYPE,
                   object_id=doc.id,
                   user=user,
                   event=events.REMOVE_TAG_TO_DOCUMENT)
    log.save()

    log_detail = AuditLogDetail(audit_log=log, description=tag.name)
    log_detail.save()
示例#7
0
def create_feature_segment_audit_log(instance, history_user, history_instance,
                                     **kwargs):
    # due to referential integrity issues that come from cascade deletes, we skip creating
    # audit logs for deleted feature segments for now
    # TODO: handle audit log in middleware instead
    project = None if history_instance.history_type == "-" else instance.feature.project

    message = FEATURE_SEGMENT_UPDATED_MESSAGE % (instance.feature.name,
                                                 instance.environment.name)
    AuditLog.create_record(obj=instance.feature,
                           obj_type=RelatedObjectType.FEATURE,
                           log_message=message,
                           author=history_user,
                           project=project)
示例#8
0
def post_detach_file(sender, **kwargs):
    doc = kwargs.get("document")
    file = kwargs.get("file")
    user = kwargs.get("user")

    log = AuditLog(content_type=DOCUMENT_CONTENT_TYPE,
                   object_id=doc.id,
                   user=user,
                   event=events.FILE_DETACHED)
    log.save()

    log_detail = AuditLogDetail(audit_log=log,
                                description="%s (%s)" %
                                (file.filename, kilobytefy(file.filesize)))
    log_detail.save()
示例#9
0
def download_attachment_log(sender, **kwargs):
    user = kwargs.get("user")
    doc = kwargs.get("document")
    file = kwargs.get("file")

    log = AuditLog(content_type=DOCUMENT_CONTENT_TYPE,
                   object_id=doc.id,
                   user=user,
                   event=events.DOWNLOAD_ATTACHMENT)
    log.save()

    log_detail = AuditLogDetail(audit_log=log,
                                description="%s (%s)" %
                                (file.filename, kilobytefy(file.filesize)))
    log_detail.save()
示例#10
0
def document_unshared_to_all_log(sender, **kwargs):
    shared_from = kwargs.get("shared_from")
    doc = kwargs.get("document")
    permission = kwargs.get("permission")

    log = AuditLog(content_type=DOCUMENT_CONTENT_TYPE,
                   object_id=doc.id,
                   user=shared_from,
                   event=events.DOCUMENT_UNSHARED)
    log.save()

    log_detail = AuditLogDetail(audit_log=log,
                                description="Todos Usuarios nao podem %s" %
                                (_translate_permission(permission)))
    log_detail.save()
示例#11
0
def document_shared_to_group_log(sender, **kwargs):
    shared_from = kwargs.get("shared_from")
    shared_to = kwargs.get("shared_to")
    doc = kwargs.get("document")
    permission = kwargs.get("permission")

    log = AuditLog(content_type=DOCUMENT_CONTENT_TYPE,
                   object_id=doc.id,
                   user=shared_from,
                   event=events.DOCUMENT_SHARED)
    log.save()

    log_detail = AuditLogDetail(audit_log=log,
                                description="Grupo %s pode %s" %
                                (shared_to, _translate_permission(permission)))
    log_detail.save()
示例#12
0
def create_feature_segment_audit_log(instance, history_user, history_instance, **kwargs):
    deleted = history_instance.history_type == "-"

    # if the feature segment has been deleted, this could have been a cascade delete from the project being deleted
    # if it is, then we can skip creating the audit log.
    project = instance.feature.project
    with transaction.atomic():
        if deleted and not Project.objects.filter(id=project.id).exists():
            return

    message = FEATURE_SEGMENT_UPDATED_MESSAGE % (instance.feature.name, instance.environment.name)
    AuditLog.create_record(
        obj=instance.feature,
        obj_type=RelatedObjectType.FEATURE,
        log_message=message,
        author=history_user,
        project=instance.feature.project
    )
示例#13
0
def classify_log(sender, **kwargs):
    doc = kwargs.get("document")
    user = kwargs.get("user")

    log = AuditLog(content_type=DOCUMENT_CONTENT_TYPE,
                   object_id=doc.id,
                   user=user,
                   event=events.CLASSIFY_DOCUMENT)
    log.save()

    log_detail = AuditLogDetail(audit_log=log,
                                description="Categoria: %s" %
                                (doc.category.title))
    log_detail.save()

    for doc_attr in DocumentAttribute.objects.filter(document=doc):
        value = InheritanceQuerySet(
            model=AbstractValue).select_subclasses().get(id=doc_attr.value.id)
        log_detail = AuditLogDetail(audit_log=log,
                                    description="%s: %s" %
                                    (doc_attr.attribute.name, value.value))
        log_detail.save()
示例#14
0
    def test_data_dog_track_event_not_called_on_audit_log_saved_when_wrong(
            self, datadog_mock):
        # Given Audit log and project configured for Datadog integration
        DataDogConfiguration.objects.create(project=self.project,
                                            base_url='http"//test.com',
                                            api_key='123key')

        audit_log = AuditLog(project=self.project, log='Some audit log')
        audit_log2 = AuditLog(
            project=self.project,
            log='Some audit log',
            related_object_type=RelatedObjectType.ENVIRONMENT.name)

        # When Audit log saved with wrong types
        audit_log.save()
        audit_log2.save()

        # Then datadog track even should not be triggered
        datadog_mock.track_event_async.assert_not_called()
示例#15
0
def get_or_404(key, next=None):
    logging.debug("key: %s" % key)
    if not key:
        return None
    if isinstance(key, basestring):
        key = ndb.Key(urlsafe=key)
    o = key.get()
    if not o:
        if next:
            raise Http302(next)
        # check if there is an audit log for delete
        from audit.models import AuditLog
        audit_log = AuditLog.query(ancestor=key).filter(AuditLog.log_action == "D").get()
        if audit_log:
            msg = _(u"Obiekt „{0}” został wcześniej usunięty przez użytkownika o adresie {1}.")
            raise Http410(msg.format(key.kind(), audit_log.log_email))
        logging.warning("Http404: %s" % key.urlsafe())
        msg = _(u"No {0} was found for key {1}")
        raise Http404(msg.format(key.kind(), key.urlsafe()))
    return o