From 308ba3ada7f49287becbfbcf35ce017f46203c7a Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Wed, 17 Apr 2024 15:12:19 +0000 Subject: [PATCH] emit a matching ProjectEvent anywhere we are removing a JournalEntry --- warehouse/admin/views/projects.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/warehouse/admin/views/projects.py b/warehouse/admin/views/projects.py index c4e0cc02fda6..d88ec2244714 100644 --- a/warehouse/admin/views/projects.py +++ b/warehouse/admin/views/projects.py @@ -19,7 +19,9 @@ from sqlalchemy.exc import NoResultFound from sqlalchemy.orm import joinedload +from warehouse.accounts.interfaces import IUserService from warehouse.accounts.models import User +from warehouse.events.tags import EventTag from warehouse.authnz import Permissions from warehouse.forklift.legacy import MAX_FILESIZE, MAX_PROJECT_SIZE from warehouse.observations.models import OBSERVATION_KIND_MAP, ObservationKind @@ -595,6 +597,27 @@ def add_role(project, request): request.db.add(Role(role_name=role_name, user=user, project=project)) + user_service = request.find_service(IUserService, context=None) + + project.record_event( + tag=EventTag.Project.RoleAdd, + request=request, + additional={ + "submitted_by": user_service.get_admin_user(), + "role_name": role_name, + "target_user": user.username, + }, + ) + user.record_event( + tag=EventTag.Account.RoleAdd, + request=request, + additional={ + "submitted_by": user_service.get_admin_user(), + "project_name": project.name, + "role_name": role_name, + }, + ) + request.session.flash( f"Added '{user.username}' as '{role_name}' on '{project.name}'", queue="success" ) @@ -636,6 +659,18 @@ def delete_role(project, request): queue="success", ) + user_service = request.find_service(IUserService, context=None) + + project.record_event( + tag=EventTag.Project.RoleRemove, + request=request, + additional={ + "submitted_by": user_service.get_admin_user(), + "role_name": role.role_name, + "target_user": role.user.username, + }, + ) + request.db.delete(role) return HTTPSeeOther(