Skip to content

Commit

Permalink
Merge pull request #921 from kobotoolbox/remove-audit-log
Browse files Browse the repository at this point in the history
Remove audit logging
  • Loading branch information
noliveleger authored Mar 22, 2024
2 parents 9eb54e2 + 6920723 commit ef010e7
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 343 deletions.
30 changes: 0 additions & 30 deletions onadata/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding: utf-8
import json
import os
from datetime import datetime

from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -30,7 +29,6 @@
from onadata.libs.mixins.labels_mixin import LabelsMixin
from onadata.libs.renderers import renderers
from onadata.libs.serializers.xform_serializer import XFormSerializer
from onadata.libs.utils import log
from onadata.libs.utils.common_tags import SUBMISSION_TIME
from onadata.libs.utils.csv_import import submit_csv
from onadata.libs.utils.export_tools import (
Expand Down Expand Up @@ -108,17 +106,6 @@ def _generate_new_export(request, xform, query, export_type):
export_type, extension, xform.user.username,
xform.id_string, None, query
)
audit = {
"xform": xform.id_string,
"export_type": export_type
}
log.audit_log(
log.Actions.EXPORT_CREATED, request.user, xform.user,
t("Created %(export_type)s export on '%(id_string)s'.") %
{
'id_string': xform.id_string,
'export_type': export_type.upper()
}, audit, request)
except NoRecordsFoundError:
raise Http404(t("No records found to export"))
else:
Expand Down Expand Up @@ -172,21 +159,6 @@ def value_for_type(form, field, value):
return value


def log_export(request, xform, export_type):
# log download as well
audit = {
"xform": xform.id_string,
"export_type": export_type
}
log.audit_log(
log.Actions.EXPORT_DOWNLOADED, request.user, xform.user,
t("Downloaded %(export_type)s export on '%(id_string)s'.") %
{
'id_string': xform.id_string,
'export_type': export_type.upper()
}, audit, request)


def custom_response_handler(request, xform, query, export_type):
export_type = _get_export_type(export_type)

Expand All @@ -200,8 +172,6 @@ def custom_response_handler(request, xform, query, export_type):
# tends to happen when using newset_export_for.
export = _generate_new_export(request, xform, query, export_type)

log_export(request, xform, export_type)

# get extension from file_path, exporter could modify to
# xlsx if it exceeds limits
path, ext = os.path.splitext(export.filename)
Expand Down
25 changes: 1 addition & 24 deletions onadata/apps/logger/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
import json
import os
import tempfile
import re
from datetime import datetime, date

from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib import messages
from django.core.files.storage import default_storage
from django.http import (
HttpResponse,
Expand All @@ -16,7 +13,6 @@
HttpResponseNotFound,
HttpResponseRedirect,
StreamingHttpResponse,
Http404,
)
from django.shortcuts import get_object_or_404
from django.shortcuts import render
Expand All @@ -25,19 +21,15 @@
from django.views.decorators.http import require_POST
from django.views.decorators.csrf import csrf_exempt

from onadata.apps.main.models import UserProfile
from onadata.apps.logger.import_tools import import_instances_from_zip
from onadata.apps.logger.models.xform import XForm
from onadata.libs.authentication import digest_authentication
from onadata.libs.utils.log import audit_log, Actions
from onadata.libs.utils.logger_tools import BaseOpenRosaResponse
from onadata.libs.utils.logger_tools import response_with_mimetype_and_name
from onadata.libs.utils.user_auth import (
helper_auth_helper,
has_permission,
add_cors_headers,
)
from .tasks import generate_stats_zip
from ...koboform.pyxform_utils import convert_csv_to_xls

IO_ERROR_STRINGS = [
Expand Down Expand Up @@ -128,11 +120,6 @@ def bulksubmission(request, username):
'rejected': total_count - success_count},
'errors': "%d %s" % (len(errors), errors)
}
audit = {
"bulk_submission_log": json_msg
}
audit_log(Actions.USER_BULK_SUBMISSION, request.user, posting_user,
t("Made bulk submissions."), audit, request)
response = HttpResponse(json.dumps(json_msg))
response.status_code = 200
response['Location'] = request.build_absolute_uri(request.path)
Expand Down Expand Up @@ -161,16 +148,6 @@ def download_xlsform(request, username, id_string):
file_path = xform.xls.name

if file_path != '' and default_storage.exists(file_path):
audit = {
"xform": xform.id_string
}
audit_log(
Actions.FORM_XLS_DOWNLOADED, request.user, xform.user,
t("Downloaded XLS file for form '%(id_string)s'.") %
{
"id_string": xform.id_string
}, audit, request)

if file_path.endswith('.csv'):
with default_storage.open(file_path) as ff:
xls_io = convert_csv_to_xls(ff.read())
Expand Down
1 change: 0 additions & 1 deletion onadata/apps/main/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
from .user_profile import UserProfile # flake8: noqa
from .meta_data import MetaData
from .audit import AuditLog
73 changes: 0 additions & 73 deletions onadata/apps/main/models/audit.py

This file was deleted.

30 changes: 0 additions & 30 deletions onadata/apps/main/tests/test_audit_log.py

This file was deleted.

39 changes: 0 additions & 39 deletions onadata/apps/viewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from onadata.apps.viewer.tasks import create_async_export
from onadata.libs.authentication import digest_authentication
from onadata.libs.utils.image_tools import image_url
from onadata.libs.utils.log import audit_log, Actions
from onadata.libs.utils.logger_tools import response_with_mimetype_and_name
from onadata.libs.utils.user_auth import (
HttpResponseNotAuthorized,
Expand Down Expand Up @@ -79,17 +78,6 @@ def create_export(request, username, id_string, export_type):
return HttpResponseBadRequest(
t("%s is not a valid export type" % export_type))
else:
audit = {
"xform": xform.id_string,
"export_type": export_type
}
audit_log(
Actions.EXPORT_CREATED, request.user, owner,
t("Created %(export_type)s export on '%(id_string)s'.") %
{
'export_type': export_type.upper(),
'id_string': xform.id_string,
}, audit, request)
return HttpResponseRedirect(reverse(
export_list,
kwargs={
Expand Down Expand Up @@ -171,20 +159,6 @@ def export_download(request, username, id_string, export_type, filename):

ext, mime_type = export_def_from_filename(export.filename)

audit = {
"xform": xform.id_string,
"export_type": export.export_type
}
audit_log(
Actions.EXPORT_DOWNLOADED, request.user, owner,
t("Downloaded %(export_type)s export '%(filename)s' "
"on '%(id_string)s'.") %
{
'export_type': export.export_type.upper(),
'filename': export.filename,
'id_string': xform.id_string,
}, audit, request)

if not isinstance(default_storage, FileSystemStorage):
return HttpResponseRedirect(default_storage.url(export.filepath))

Expand Down Expand Up @@ -213,19 +187,6 @@ def delete_export(request, username, id_string, export_type):
export = get_object_or_404(Export, id=export_id)

export.delete()
audit = {
"xform": xform.id_string,
"export_type": export.export_type
}
audit_log(
Actions.EXPORT_DOWNLOADED, request.user, owner,
t("Deleted %(export_type)s export '%(filename)s'"
" on '%(id_string)s'.") %
{
'export_type': export.export_type.upper(),
'filename': export.filename,
'id_string': xform.id_string,
}, audit, request)
return HttpResponseRedirect(reverse(
export_list,
kwargs={
Expand Down
Loading

0 comments on commit ef010e7

Please sign in to comment.