Skip to content

Commit

Permalink
Merge pull request #58 from eduNEXT/mgs/audit_model-logging
Browse files Browse the repository at this point in the history
Add eox-audit-model and drop support for Ironwood
  • Loading branch information
MoisesGSalas authored Feb 5, 2021
2 parents eb7bd4b + af44bba commit ec1fd96
Show file tree
Hide file tree
Showing 22 changed files with 798 additions and 147 deletions.
7 changes: 2 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ workflows:
only: /v?[0-9]+(\.[0-9]+)*/
matrix:
parameters:
python_version: ["2.7", "3.5"]
django_version: ["django111", "django22"]
exclude:
- python_version: "2.7"
django_version: "django22"
python_version: ["3.5"]
django_version: ["django22"]
- pypi:
requires:
- test
Expand Down
6 changes: 3 additions & 3 deletions eox_tagging/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_search_results(self, request, queryset, search_term):
"""
Custom search to support searching on the tagged objects
"""
queryset, use_distinct = super(TagAdmin, self).get_search_results(
queryset, use_distinct = super().get_search_results(
request,
queryset,
search_term
Expand Down Expand Up @@ -71,7 +71,7 @@ def tagged_object(self, tag):
except Exception as error:
return str(error)

def add_view(self, request, *args, **kwargs): # pylint: disable=arguments-differ
def add_view(self, request, form_url='', extra_context=None):
"""
Custom method to handle the specific case of tagging course_keys
Expand Down Expand Up @@ -106,7 +106,7 @@ def add_view(self, request, *args, **kwargs): # pylint: disable=arguments-diffe
request.POST['target_type'] = ContentType.objects.get(model='OpaqueKeyProxyModel').id
request.POST['target_object_id'] = opaque_key_proxy.id

return super(TagAdmin, self).add_view(request, *args, **kwargs)
return super().add_view(request, form_url='', extra_context=None)


admin.site.register(Tag, TagAdmin)
2 changes: 1 addition & 1 deletion eox_tagging/api/v1/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TagFilter(filters.FilterSet):
expiration_date = filters.DateTimeFromToRangeFilter()
access = filters.CharFilter(method="filter_access_type")

class Meta: # pylint: disable=old-style-class, useless-suppression
class Meta:
"""Meta class."""
model = Tag
fields = ["key", "status", "tag_type", "tag_value"]
Expand Down
2 changes: 1 addition & 1 deletion eox_tagging/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TagSerializer(serializers.ModelSerializer):
access = fields.EnumField(enum=AccessLevel, required=False)
status = fields.EnumField(enum=Status, required=False)

class Meta: # pylint: disable=old-style-class, useless-suppression
class Meta:
"""Meta class."""
model = Tag
fields = ('meta', 'key', 'tag_value', 'tag_type', 'access', 'activation_date', 'expiration_date',
Expand Down
27 changes: 27 additions & 0 deletions eox_tagging/api/v1/viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Viewset for Tags.
"""
from django_filters import rest_framework as filters
from eox_audit_model.decorators import audit_method
from rest_framework import viewsets
from rest_framework.authentication import SessionAuthentication

Expand Down Expand Up @@ -36,6 +37,32 @@ def get_queryset(self):

return queryset

def create(self, request, *args, **kwargs):
""""Hijack the create method and use a wrapper function to perform the
audit process. The original parameters of create are not very useful in
raw form, this way we pass more useful information to our wrapper
function to be audited
"""

@audit_method(action="eox_tagging-api-v1-viewset:tagviewset-create")
def audited_create(headers, body): # pylint: disable=unused-argument
return super(TagViewSet, self).create(request, *args, **kwargs)

return audited_create(headers=request.headers, body=request.data)

def destroy(self, request, *args, **kwargs):
""""Hijack the destroy method and use a wrapper function to perform the
audit process. The original parameters of destroy are not very useful in
raw form, this way we pass more useful information to our wrapper
function to be audited
"""

@audit_method(action="eox_tagging-api-v1-viewset:tagviewset-destroy")
def audited_destroy(headers, path): # pylint: disable=unused-argument
return super(TagViewSet, self).destroy(request, *args, **kwargs)

return audited_destroy(headers=request.headers, path=request.path)

def __get_objects_by_status(self, queryset):
"""Method that returns queryset filtered by tag status."""
include_inactive = self.request.query_params.get("include_inactive")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_bearer_authentication():
BearerAuthentication function.
"""
try:
from openedx.core.lib.api.authentication import BearerAuthentication
from openedx.core.lib.api.authentication import BearerAuthentication # pylint: disable=import-outside-toplevel
except ImportError:
BearerAuthentication = object
return BearerAuthentication
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def get_course_overview():
"""Backend to get course overview."""
try:
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview # pylint: disable=import-outside-toplevel
except ImportError:
CourseOverview = object
return CourseOverview
2 changes: 1 addition & 1 deletion eox_tagging/edxapp_wrappers/backends/enrollment_i_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def get_enrollment_object():
"""Backend to get enrollment object."""
try:
from student.models import CourseEnrollment
from student.models import CourseEnrollment # pylint: disable=import-outside-toplevel
except ImportError:
CourseEnrollment = object
return CourseEnrollment
12 changes: 6 additions & 6 deletions eox_tagging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ class Tag(models.Model):

objects = TagQuerySet().as_manager()

class Meta: # pylint: disable=old-style-class, useless-suppression
class Meta:
"""Meta class. """
verbose_name = "tag"
verbose_name_plural = "tags"
app_label = "eox_tagging"

def __str__(self):
return self.tag_value
return str(self.tag_value)

@property
def target_object_type(self):
Expand Down Expand Up @@ -308,15 +308,15 @@ def full_clean(self, exclude=None, validate_unique=False):
self.clean()
self.clean_fields()

def save(self, *args, **kwargs): # pylint: disable=arguments-differ
def save(self, *args, **kwargs): # pylint: disable=signature-differs
self.full_clean()
super(Tag, self).save(*args, **kwargs)
super().save(*args, **kwargs)

def delete(self): # pylint: disable=arguments-differ
self.inactivated_at = timezone.now()
self.status = Status.INACTIVE
super(Tag, self).save()
super().save()

def hard_delete(self):
"""Deletes object from database."""
super(Tag, self).delete()
super().delete()
1 change: 1 addition & 0 deletions eox_tagging/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'django.contrib.auth',
'django.contrib.contenttypes',
'rest_framework',
'eox_audit_model.apps.EoxAuditModelConfig',
'eox_tagging',
]

Expand Down
1 change: 0 additions & 1 deletion eox_tagging/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ def plugin_settings(settings): # pylint: disable=unused-argument
Set of plugin settings used by the Open Edx platform.
More info: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst
"""
pass
4 changes: 1 addition & 3 deletions eox_tagging/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
from .common import * # pylint: disable=wildcard-import


class SettingsClass(object):
class SettingsClass:
""" dummy settings class """

pass


SETTINGS = SettingsClass()
# This is executing the plugin_settings method imported from common module
Expand Down
4 changes: 2 additions & 2 deletions eox_tagging/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
DATETIME_FORMAT_VALIDATION = "%Y-%m-%d %H:%M:%S"


class TagValidators(object):
class TagValidators:
""" Defines all validator methods.
"""

Expand Down Expand Up @@ -352,7 +352,7 @@ def validate_equals(self, field, value):
if not field_value:
raise ValidationError("EOX_TAGGING | The field '{}' is required and must be equal to '{}'."
.format(field, value))
elif field_value.lower() != value.lower():
if field_value.lower() != value.lower():
raise ValidationError("EOX_TAGGING | The field '{}' must be equal to '{}'.".format(field, value))

def validate_between(self, field, value):
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Main requirements of your plugin application.
-c constraints.txt

eox-audit-model
eox-core
Loading

0 comments on commit ec1fd96

Please sign in to comment.