-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Categorize audit logs by log type #5063
Conversation
0e92ebb
to
8846b48
Compare
8846b48
to
efd0593
Compare
USER_MANAGEMENT = 'user-management' | ||
ASSET_MANAGEMENT = 'asset-management' | ||
SUBMISSION_MANAGEMENT = 'submission-management' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP-8: 2 blank lines between classes ;-)
kobo/apps/audit_log/models.py
Outdated
@@ -48,6 +57,7 @@ class AuditLog(models.Model): | |||
db_index=True | |||
) | |||
user_uid = models.CharField(db_index=True, max_length=UUID_LENGTH + 1) # 1 is prefix length | |||
log_type = models.CharField(choices=AuditType.choices) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it a criteria we are going to (often) use to narrow down query? I think I would use db_index=True
?
What do you think?
@@ -31,7 +31,7 @@ def test_delete_user(self): | |||
|
|||
# Create dummy logs for someuser | |||
audit_log = AuditLog.objects.create( | |||
app_label='foo', model_name='bar', object_id=1, user=someuser | |||
app_label='foo', model_name='bar', object_id=1, user=someuser, log_type=AuditType.ACCESS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be over the 80 characters per line limit?
kobo/apps/trash_bin/utils.py
Outdated
@@ -138,6 +139,7 @@ def move_to_trash( | |||
**{fk_field_name: obj_dict['pk']}, | |||
) | |||
) | |||
log_type = AuditType.USER_MANAGEMENT if related_model._meta.model_name == 'user' else AuditType.ASSET_MANAGEMENT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reformat to keep 80-ish characters per line ;-)
kobo/apps/trash_bin/utils.py
Outdated
@@ -217,6 +220,7 @@ def put_back( | |||
|
|||
if del_pto_count != len(obj_ids): | |||
raise TrashTaskInProgressError | |||
log_type = AuditType.USER_MANAGEMENT if related_model._meta.model_name == 'user' else AuditType.ASSET_MANAGEMENT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reformat to keep 80-ish characters per line ;-)
@@ -789,7 +789,7 @@ def test_audit_log_on_delete(self): | |||
model_name, | |||
) = self.asset.deployment.submission_model.get_app_label_and_model_name() | |||
audit_log_count = AuditLog.objects.filter( | |||
user=self.someuser, app_label=app_label, model_name=model_name | |||
user=self.someuser, app_label=app_label, model_name=model_name, log_type=AuditType.SUBMISSION_MANAGEMENT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reformat to keep 80-ish characters per line ;-)
@@ -799,7 +799,8 @@ def test_audit_log_on_delete(self): | |||
# All submissions have been deleted and should be logged | |||
deleted_submission_ids = AuditLog.objects.values_list( | |||
'pk', flat=True | |||
).filter(user=self.someuser, app_label=app_label, model_name=model_name) | |||
).filter(user=self.someuser, app_label=app_label, model_name=model_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not seem to be black-formatted?
adadc56
to
643bbc6
Compare
), | ||
preserve_default=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💪
Checklist
Description
Distinguish audit logs pertaining to different categories (access, user management, submission management, project history, data editing, and asset management).
Notes
Adds a new log_type field to the AuditLog model (and a sql query to backfill any existing audit logs). This will allow us to better filter the endpoints to get only access logs, only project history logs, etc. No change is made to the endpoint, that will be done in other PRs, but the model change will make that easier down the road.
The categories to backfill the existing audit logs for everything but access logs may end up being changed in the future but are good enough approximations for now. Since we are currently only logging deletes/put-back for assets, submissions, and users, the categories in the runsql should cover all existing audit logs and allow us to make the field not-nullable.