Skip to content

Commit

Permalink
Vendor django-automated-logging (#1794)
Browse files Browse the repository at this point in the history
* Vendor django-automated-logging
* Update requirements
* Fix middleware module
* Specify log for automated logging
* Moved vendored package to _vendor folder
* Missed updating flake8
* Ignore _vendor directory in check-manifest
* Forgot __init__.py ...

Issue: AAH-2388
  • Loading branch information
bmclaughlin authored Jul 19, 2023
1 parent 95cd3e5 commit 11b5926
Show file tree
Hide file tree
Showing 66 changed files with 6,604 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES/2388.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Vendor django-automated-logging to provide Django 4.x compatibility
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ exclude netlify.toml
exclude docs
exclude docs_requirements.txt
exclude .readthedocs.yaml
include django-automated-logging-LICENSE.txt
include galaxy_ng/automated_logging/templates/dal/admin/view.html
21 changes: 21 additions & 0 deletions django-automated-logging-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Bilal Mahmoud

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions flake8.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exclude =
.ci/scripts/*,
.github/workflows/scripts/*,
.venv/*,
./galaxy_ng/_vendor/automated_logging/*,

ignore = BLK,W503,Q000,D,D100,D101,D102,D103,D104,D105,D106,D107,D200,D401,D402,E203
max-line-length = 100
Expand Down
5 changes: 5 additions & 0 deletions galaxy_ng/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import sys
from ._vendor import automated_logging

sys.modules.setdefault("automated_logging", automated_logging)

__version__ = "4.8.0dev"

default_app_config = "galaxy_ng.app.PulpGalaxyPluginAppConfig"
Empty file added galaxy_ng/_vendor/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions galaxy_ng/_vendor/automated_logging/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Django Automated Logging makes logging easy.
Django Automated Logging (DAL) is a package with the purpose of
making logging in django automated and easy.
"""
default_app_config = 'automated_logging.apps.AutomatedloggingConfig'
9 changes: 9 additions & 0 deletions galaxy_ng/_vendor/automated_logging/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
""" This is just a file that imports all admin interfaces defined in this package """

from automated_logging.admin.model_entry import *
from automated_logging.admin.model_event import *
from automated_logging.admin.model_mirror import *

from automated_logging.admin.request_event import *

from automated_logging.admin.unspecified_event import *
70 changes: 70 additions & 0 deletions galaxy_ng/_vendor/automated_logging/admin/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from django.contrib.admin.options import BaseModelAdmin, ModelAdmin, TabularInline
from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.shortcuts import resolve_url
from django.utils.html import format_html
from django.utils.safestring import SafeText

from automated_logging.models import BaseModel


class MixinBase(BaseModelAdmin):
"""
TabularInline and ModelAdmin readonly mixin have both the same methods and
return the same, because of that fact we have a mixin base
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.readonly_fields = [f.name for f in self.model._meta.get_fields()]

def get_actions(self, request):
""" get_actions from ModelAdmin, but remove all write operations."""
actions = super().get_actions(request)
actions.pop('delete_selected', None)

return actions

def has_add_permission(self, request, instance=None):
""" no-one should have the ability to add something => r/o"""
return False

def has_delete_permission(self, request, instance=None):
""" no-one should have the ability to delete something => r/o """
return False

def has_change_permission(self, request, instance=None):
""" no-one should have the ability to edit something => r/o """
return False

def save_model(self, request, instance, form, change):
""" disable saving by doing nothing """
pass

def delete_model(self, request, instance):
""" disable deleting by doing nothing """
pass

def save_related(self, request, form, formsets, change):
""" we don't need to save related, because save_model does nothing """
pass

# helpers
def model_admin_url(self, instance: BaseModel, name: str = None) -> str:
""" Helper to return a URL to another object """
url = resolve_url(
admin_urlname(instance._meta, SafeText("change")), instance.pk
)
return format_html('<a href="{}">{}</a>', url, name or str(instance))


class ReadOnlyAdminMixin(MixinBase, ModelAdmin):
""" Disables all editing capabilities for the model admin """

change_form_template = "dal/admin/view.html"


class ReadOnlyTabularInlineMixin(MixinBase, TabularInline):
""" Disables all editing capabilities for inline """

model = None
79 changes: 79 additions & 0 deletions galaxy_ng/_vendor/automated_logging/admin/model_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""
Everything related to the admin interface of ModelEntry is located in here
"""

from django.contrib.admin import register
from django.shortcuts import redirect

from automated_logging.admin.model_event import ModelEventAdmin
from automated_logging.admin.base import ReadOnlyAdminMixin, ReadOnlyTabularInlineMixin
from automated_logging.models import ModelEntry, ModelEvent


class ModelEventInline(ReadOnlyTabularInlineMixin):
""" inline for all attached events """

model = ModelEvent

def __init__(self, *args, **kwargs):
super(ModelEventInline, self).__init__(*args, **kwargs)

self.readonly_fields = [*self.readonly_fields, 'get_uuid', 'get_modifications']

def get_uuid(self, instance):
""" make the uuid small """
return self.model_admin_url(instance, str(instance.id).split('-')[0])

get_uuid.short_description = 'UUID'

def get_modifications(self, instance):
""" ModelEventAdmin already implements this functions, we just refer to it"""
return ModelEventAdmin.get_modifications(self, instance)

get_modifications.short_description = 'Modifications'

fields = ('get_uuid', 'updated_at', 'user', 'get_modifications')

ordering = ('-updated_at',)

verbose_name = 'Event'
verbose_name_plural = 'Events'


@register(ModelEntry)
class ModelEntryAdmin(ReadOnlyAdminMixin):
""" admin page specification for ModelEntry """

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.readonly_fields = [*self.readonly_fields, 'get_model', 'get_application']

def changelist_view(self, request, **kwargs):
""" instead of showing the changelist view redirect to the parent app_list"""
return redirect('admin:app_list', self.model._meta.app_label)

def has_module_permission(self, request):
""" remove model entries from the index.html list """
return False

def get_model(self, instance):
""" get the model mirror """
return self.model_admin_url(instance.mirror)

get_model.short_description = 'Model'

def get_application(self, instance):
""" get the application """
return instance.mirror.application

get_application.short_description = 'Application'

fieldsets = (
(
'Information',
{'fields': ('id', 'get_model', 'get_application', 'primary_key', 'value')},
),
)

inlines = [ModelEventInline]
Loading

0 comments on commit 11b5926

Please sign in to comment.