Skip to content

Commit

Permalink
emit a matching ProjectEvent anywhere we are removing a JournalEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
di committed Apr 17, 2024
1 parent dca05fa commit 308ba3a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions warehouse/admin/views/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 308ba3a

Please sign in to comment.