Skip to content
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

Log when an admin deletes/undeletes a collection through the admin #23228

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

diox
Copy link
Member

@diox diox commented Mar 26, 2025

Also avoid showing deleted field if the collection isn't already deleted - that's pointless and confusing, admins should use the regular delete action if they want to delete something.

Fixes mozilla/addons#15394

Testing

  • As an admin (needs Collections:Edit permission + access to the admin, or just *:*) look at a non-deleted collection detail page in the admin
  • Deleted field should be absent
  • Delete that collection through the button
  • Collection should now be deleted - can't see it in frontend
  • An ActivityLog with COLLECTION_DELETED action and the collection as argument should have been recorded in the database
  • Go back to that collection admin detail page
  • Slug field should not have changed (it would if the user would have deleted the collection themselves through the frontend)
  • Deleted field should be present and ticked
  • Untick Deleted field and hit save
  • An ActivityLog with COLLECTION_UNDELETED action and the collection as argument should have been recorded in the database
  • Collection should now be undeleted - can see it in frontend

diox added 3 commits March 26, 2025 14:45
Also avoid showing `deleted` field if the collection isn't already
deleted - that's pointless and confusing, admins should use the
regular delete action if they want to delete something.
@diox diox requested review from a team and KevinMind and removed request for a team March 28, 2025 10:50
Copy link
Contributor

@KevinMind KevinMind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'll verify after you resolve my comments.

@@ -87,5 +96,14 @@ def has_add_permission(self, request):
request.user, amo.permissions.ADMIN_CURATION
) or super().has_add_permission(request)

def delete_model(self, request, obj):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we don't want a deleted log in all cases? Why only via admin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a strong reason, it's just something that never came up (where as deletion by moderators is something we need to keep track of for the transparency report - we already had the LogEntry django generates automatically for actions happening in the admin, but that's not as centralized as our ActivityLog).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW ratings behave in the same way, the only activity log we emit is for moderators/reviewers deletion

def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)
if change and 'deleted' in form.changed_data and not obj.deleted:
ActivityLog.objects.create(amo.LOG.COLLECTION_UNDELETED, obj)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question.

Copy link
Member Author

@diox diox Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undeletion is not a feature exposed outside of the admin (and Cinder, but we do log it there)

@diox diox requested a review from KevinMind March 31, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Add logging in django admin when deleting collections
2 participants