@@ -436,6 +436,52 @@ def test_delete_project(self):
436436 clean_project_resources .call_args [0 ][0 ].slug , self .project .slug
437437 )
438438
439+ def test_delete_project_creates_audit_log_for_all_admins (self ):
440+ from readthedocs .audit .models import AuditLog
441+
442+ other_admin = get (User )
443+ self .project .users .add (other_admin )
444+
445+ with mock .patch (
446+ "readthedocs.projects.tasks.utils.clean_project_resources"
447+ ):
448+ response = self .client .post ("/dashboard/pip/delete/" )
449+ self .assertEqual (response .status_code , 302 )
450+
451+ # An audit log entry is created for each project admin.
452+ logs = AuditLog .objects .filter (action = AuditLog .PROJECT_DELETE )
453+ self .assertEqual (logs .count (), 2 )
454+ self .assertEqual (
455+ set (logs .values_list ("log_user_username" , flat = True )),
456+ {self .user .username , other_admin .username },
457+ )
458+
459+ # All entries preserve the project slug after deletion.
460+ for log in logs :
461+ self .assertEqual (log .log_project_slug , "pip" )
462+ self .assertIsNone (log .project )
463+ self .assertEqual (log .data , {"deleted_by" : self .user .username })
464+
465+ def test_delete_project_captures_ip_and_browser_in_history (self ):
466+ with mock .patch (
467+ "readthedocs.projects.tasks.utils.clean_project_resources"
468+ ):
469+ response = self .client .post (
470+ "/dashboard/pip/delete/" ,
471+ headers = {"user-agent" : "TestBrowser/1.0" },
472+ )
473+ self .assertEqual (response .status_code , 302 )
474+
475+ HistoricalProject = Project .history .model
476+ history = HistoricalProject .objects .filter (
477+ slug = "pip" ,
478+ history_type = "-" ,
479+ ).first ()
480+ self .assertIsNotNone (history )
481+ self .assertEqual (history .extra_history_ip , "127.0.0.1" )
482+ self .assertEqual (history .extra_history_browser , "TestBrowser/1.0" )
483+ self .assertEqual (history .history_user , self .user )
484+
439485 def test_delete_superproject (self ):
440486 sub_proj = get (Project , slug = "test-sub-project" , users = [self .user ])
441487
0 commit comments