From 3df22816b482bf4f0a463aad100a800e46156026 Mon Sep 17 00:00:00 2001 From: Rebecca Graber Date: Thu, 5 Dec 2024 14:23:26 -0500 Subject: [PATCH] fix(projectHistoryLogs): rename incorrectly-formatted action TASK-944 (#5320) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### đŸ“Ŗ Summary Change the action `modify_sharing` to `modify-sharing` in project history logs for consistency. ### 👷 Description for instance maintainers Change the AuditAction `modify_sharing` to `modify-sharing`, including a migration to update existing logs. Also adds the migration for all the new audit action types, although this migration seems to be a no-op in SQL. ### 👀 Preview steps 1. ℹī¸ have an account and a project 2. Go to Project > Settings > Connect Projects and enable data sharing. Select a specific question to share. 3. 🔴 [on main] Go to `api/v2/assets//history`. Notice the action for the latest project history log is `modify_sharing` 4. đŸŸĸ [on PR] After running migrations, reload the history endpoint. Notice the action is now `modify-sharing` 5. [on PR] Select another question to share 6. đŸŸĸ [on PR] Reload the endpoint. The latest log should have action=`modify-sharing` ### 💭 Notes I didn't even realize this needed a migration until I ran `./manage makemigrations audit_log`. It seems to work fine without the migration but this way there will be no unexpected changes next time we have to make a real migration. The migration of existing logs should be pretty light since it's a fairly rare type of log. --- kobo/apps/audit_log/audit_actions.py | 2 +- .../migrations/0013_alter_auditlog_action.py | 68 +++++++++++++++++++ kobo/apps/audit_log/views.py | 4 +- 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 kobo/apps/audit_log/migrations/0013_alter_auditlog_action.py diff --git a/kobo/apps/audit_log/audit_actions.py b/kobo/apps/audit_log/audit_actions.py index f15b91c17e..bad134800c 100644 --- a/kobo/apps/audit_log/audit_actions.py +++ b/kobo/apps/audit_log/audit_actions.py @@ -21,7 +21,7 @@ class AuditAction(models.TextChoices): IN_TRASH = 'in-trash' MODIFY_IMPORTED_FIELDS = 'modify-imported-fields' MODIFY_SERVICE = 'modify-service' - MODIFY_SHARING = 'modify_sharing' + MODIFY_SHARING = 'modify-sharing' MODIFY_USER_PERMISSIONS = 'modify-user-permissions' PUT_BACK = 'put-back' REDEPLOY = 'redeploy' diff --git a/kobo/apps/audit_log/migrations/0013_alter_auditlog_action.py b/kobo/apps/audit_log/migrations/0013_alter_auditlog_action.py new file mode 100644 index 0000000000..eb4cf90ebc --- /dev/null +++ b/kobo/apps/audit_log/migrations/0013_alter_auditlog_action.py @@ -0,0 +1,68 @@ +# Generated by Django 4.2.15 on 2024-12-03 16:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('audit_log', '0012_alter_auditlog_action'), + ] + + operations = [ + migrations.RunSQL( + sql="UPDATE audit_log_auditlog SET action = 'modify-sharing' " + "WHERE action = 'modify_sharing';", + reverse_sql=migrations.RunSQL.noop, + ), + migrations.AlterField( + model_name='auditlog', + name='action', + field=models.CharField( + choices=[ + ('add-media', 'Add Media'), + ('allow-anonymous-submissions', 'Allow Anonymous Submissions'), + ('archive', 'Archive'), + ('auth', 'Auth'), + ('clone-permissions', 'Clone Permissions'), + ('connect-project', 'Connect Project'), + ('create', 'Create'), + ('delete', 'Delete'), + ('delete-media', 'Delete Media'), + ('delete-service', 'Delete Service'), + ('deploy', 'Deploy'), + ('disable-sharing', 'Disable Sharing'), + ( + 'disallow-anonymous-submissions', + 'Disallow Anonymous Submissions', + ), + ('disconnect-project', 'Disconnect Project'), + ('enable-sharing', 'Enable Sharing'), + ('export', 'Export'), + ('in-trash', 'In Trash'), + ('modify-imported-fields', 'Modify Imported Fields'), + ('modify-service', 'Modify Service'), + ('modify-sharing', 'Modify Sharing'), + ('modify-user-permissions', 'Modify User Permissions'), + ('put-back', 'Put Back'), + ('redeploy', 'Redeploy'), + ('register-service', 'Register Service'), + ('remove', 'Remove'), + ('replace-form', 'Replace Form'), + ('share-form-publicly', 'Share Form Publicly'), + ('share-data-publicly', 'Share Data Publicly'), + ('unarchive', 'Unarchive'), + ('unshare-form-publicly', 'Unshare Form Publicly'), + ('unshare-data-publicly', 'Unshare Data Publicly'), + ('update', 'Update'), + ('update-content', 'Update Content'), + ('update-name', 'Update Name'), + ('update-settings', 'Update Settings'), + ('update-qa', 'Update Qa'), + ], + db_index=True, + default='delete', + max_length=30, + ), + ), + ] diff --git a/kobo/apps/audit_log/views.py b/kobo/apps/audit_log/views.py index 27dc6a3d9d..b9bb1d6c90 100644 --- a/kobo/apps/audit_log/views.py +++ b/kobo/apps/audit_log/views.py @@ -437,7 +437,7 @@ class AllProjectHistoryLogViewSet(AuditLogViewSet): > export > modify-imported-fields > modify-service - > modify_sharing + > modify-sharing > modify-user-permissions > redeploy > register-service @@ -686,7 +686,7 @@ class ProjectHistoryLogViewSet( > export > modify-imported-fields > modify-service - > modify_sharing + > modify-sharing > modify-user-permissions > redeploy > register-service