fix: 修复多对多审计内容太长报错&全局组织没有审计

pull/6595/head
xinwen 3 years ago committed by 老广
parent 22406f47f7
commit 66b499b8e3

@ -5,7 +5,7 @@ from django.db.models import Q
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils import timezone from django.utils import timezone
from orgs.mixins.models import OrgModelMixin from orgs.mixins.models import OrgModelMixin, Organization
from orgs.utils import current_org from orgs.utils import current_org
__all__ = [ __all__ = [
@ -63,6 +63,11 @@ class OperateLog(OrgModelMixin):
def __str__(self): def __str__(self):
return "<{}> {} <{}>".format(self.user, self.action, self.resource) return "<{}> {} <{}>".format(self.user, self.action, self.resource)
def save(self, *args, **kwargs):
if current_org.is_root() and not self.org_id:
self.org_id = Organization.ROOT_ID
return super(OperateLog, self).save(*args, **kwargs)
class PasswordChangeLog(models.Model): class PasswordChangeLog(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True) id = models.UUIDField(default=uuid.uuid4, primary_key=True)

@ -199,7 +199,7 @@ def on_m2m_changed(sender, action, instance, reverse, model, pk_set, **kwargs):
resource = resource_tmpl.format(**{ resource = resource_tmpl.format(**{
instance_name: instance_value, instance_name: instance_value,
model_name: str(obj) model_name: str(obj)
}) })[:128] # `resource` 字段只有 128 个字符长 😔
to_create.append(OperateLog( to_create.append(OperateLog(
user=user, action=action, resource_type=resource_type, user=user, action=action, resource_type=resource_type,

Loading…
Cancel
Save