Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: remove audit logs app #1505

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions terraso_backend/apps/audit_logs/api.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.

from django.contrib import admin
# Generated by Django 5.1.1 on 2024-10-15 00:10

from .models import Log
from django.db import migrations

admin.site.register(Log)

class Migration(migrations.Migration):

dependencies = [
("audit_logs", "0001_initial"),
]

operations = [
migrations.DeleteModel(
name="Log",
),
]
46 changes: 0 additions & 46 deletions terraso_backend/apps/audit_logs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
# along with this program. If not, see https://www.gnu.org/licenses/.

from enum import Enum
from typing import Optional

from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.db import models


class Events(Enum):
Expand All @@ -30,44 +25,3 @@ class Events(Enum):
@classmethod
def choices(cls):
return [(key.value, key.name) for key in cls]


class Log(models.Model):
"""
Log model for audits logs
"""

timestamp = models.DateTimeField(auto_now_add=True)
client_timestamp = models.DateTimeField()
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.PROTECT, verbose_name="user"
)
user_human_readable = models.CharField(max_length=255)
event = models.CharField(max_length=50, choices=Events.choices(), default=Events.CREATE)

resource_id = models.UUIDField()
resource_content_type = models.ForeignKey(
"contenttypes.ContentType",
on_delete=models.CASCADE,
verbose_name="content type",
blank=True,
null=True,
)
resource_object = GenericForeignKey("resource_content_type", "resource_id")
resource_json_repr = models.JSONField()
resource_human_readable = models.CharField(max_length=255)

metadata = models.JSONField(default=dict)

def __str__(self):
return str(self.client_timestamp) + " - " + str(self.metadata)

def get_string(self, template: Optional[str] = None) -> str:
if template is None:
return str(self)
return template.format(**self.metadata)

class Meta:
indexes = [
models.Index(fields=["resource_content_type", "resource_id"]),
]
131 changes: 0 additions & 131 deletions terraso_backend/apps/audit_logs/services.py

This file was deleted.

2 changes: 0 additions & 2 deletions terraso_backend/apps/core/management/commands/harddelete.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def all_objects(cutoff_date):
app_models = apps.get_models()
objects = []
for model in app_models:
if model._meta.label in settings.DELETION_EXCEPTION_LIST:
continue
for field in model._meta.fields:
if field.name == "deleted_at" and isinstance(field, models.fields.DateTimeField):
objects.extend(
Expand Down
71 changes: 0 additions & 71 deletions terraso_backend/apps/graphql/schema/audit_logs.py

This file was deleted.

17 changes: 2 additions & 15 deletions terraso_backend/apps/graphql/schema/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from graphene.types.generic import GenericScalar
from graphql import get_nullable_type

from apps.audit_logs import api as audit_log_api
from apps.audit_logs import services as audit_log_services
from apps.core.formatters import from_camel_to_snake_case
from apps.graphql.exceptions import (
GraphQLNotAllowedException,
Expand Down Expand Up @@ -179,18 +177,7 @@ def not_found(cls, model=None, field=None, msg=None):
raise super().not_found(msg, field=field, model=model or cls.model_class)


class LoggerMixin:
logger: Optional[audit_log_api.AuditLog] = None

@classmethod
def get_logger(cls):
"""Returns the logger instance."""
if not cls.logger:
cls.logger = audit_log_services.new_audit_logger()
return cls.logger


class BaseWriteMutation(BaseAuthenticatedMutation, LoggerMixin):
class BaseWriteMutation(BaseAuthenticatedMutation):
skip_field_validation: Optional[str] = None

@classmethod
Expand Down Expand Up @@ -281,7 +268,7 @@ def remove_null_fields(kwargs, options=[str]):
return kwargs


class BaseDeleteMutation(BaseAuthenticatedMutation, LoggerMixin):
class BaseDeleteMutation(BaseAuthenticatedMutation):
@classmethod
def mutate_and_get_payload(cls, root, info, **kwargs):
if "model_instance" in kwargs:
Expand Down
Loading
Loading