-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1886 from dandi/audit-backend
Add audit backend
- Loading branch information
Showing
18 changed files
with
869 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Generated by Django 4.1.13 on 2024-07-24 01:30 | ||
from __future__ import annotations | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('api', '0009_remove_embargoedassetblob_dandiset_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='AuditRecord', | ||
fields=[ | ||
( | ||
'id', | ||
models.BigAutoField( | ||
auto_created=True, primary_key=True, serialize=False, verbose_name='ID' | ||
), | ||
), | ||
('timestamp', models.DateTimeField(auto_now_add=True)), | ||
('dandiset_id', models.IntegerField()), | ||
('username', models.CharField(max_length=39)), | ||
('user_email', models.CharField(max_length=254)), | ||
('user_fullname', models.CharField(max_length=301)), | ||
( | ||
'record_type', | ||
models.CharField( | ||
choices=[ | ||
('create_dandiset', 'create_dandiset'), | ||
('change_owners', 'change_owners'), | ||
('update_metadata', 'update_metadata'), | ||
('add_asset', 'add_asset'), | ||
('update_asset', 'update_asset'), | ||
('remove_asset', 'remove_asset'), | ||
('create_zarr', 'create_zarr'), | ||
('upload_zarr_chunks', 'upload_zarr_chunks'), | ||
('delete_zarr_chunks', 'delete_zarr_chunks'), | ||
('finalize_zarr', 'finalize_zarr'), | ||
('unembargo_dandiset', 'unembargo_dandiset'), | ||
('publish_dandiset', 'publish_dandiset'), | ||
('delete_dandiset', 'delete_dandiset'), | ||
], | ||
max_length=32, | ||
), | ||
), | ||
('details', models.JSONField(blank=True)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal, get_args | ||
|
||
from django.db import models | ||
|
||
AuditRecordType = Literal[ | ||
'create_dandiset', | ||
'change_owners', | ||
'update_metadata', | ||
'add_asset', | ||
'update_asset', | ||
'remove_asset', | ||
'create_zarr', | ||
'upload_zarr_chunks', | ||
'delete_zarr_chunks', | ||
'finalize_zarr', | ||
'unembargo_dandiset', | ||
'publish_dandiset', | ||
'delete_dandiset', | ||
] | ||
AUDIT_RECORD_CHOICES = [(t, t) for t in get_args(AuditRecordType)] | ||
|
||
|
||
class AuditRecord(models.Model): | ||
timestamp = models.DateTimeField(auto_now_add=True) | ||
dandiset_id = models.IntegerField() | ||
|
||
# GitHub enforces a 39 character limit on usernames (see, e.g., | ||
# https://docs.github.com/en/enterprise-cloud@latest/admin/managing-iam/iam-configuration-reference/username-considerations-for-external-authentication). | ||
username = models.CharField(max_length=39) | ||
|
||
# According to RFC 5321 (https://www.rfc-editor.org/rfc/rfc5321.txt), | ||
# section 4.5.3.1.3, an email address "path" is limited to 256 octets, | ||
# including the surrounding angle brackets. Without the brackets, that | ||
# leaves 254 characters for the email address itself. | ||
user_email = models.CharField(max_length=254) | ||
|
||
# The signup questionnaire imposes a 150 character limit on both first and | ||
# last names; together with a space to separate them, that makes a 301 | ||
# character limit on the full name. | ||
user_fullname = models.CharField(max_length=301) | ||
record_type = models.CharField(max_length=32, choices=AUDIT_RECORD_CHOICES) | ||
details = models.JSONField(blank=True) | ||
|
||
def __str__(self): | ||
return f'{self.record_type}/{self.dandiset_id:06}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.