Skip to content

Commit a15d0a2

Browse files
authored
fix: use event tags and collect user ID (#18897)
Convert to use tags from enum, and record the admin user ID for displaying in security history template. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
1 parent 51773fd commit a15d0a2

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

tests/unit/admin/views/test_organizations.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from tests.common.db.subscriptions import StripeCustomerFactory
2121
from warehouse.admin.views import organizations as views
22+
from warehouse.events.tags import EventTag
2223
from warehouse.organizations.models import (
2324
OIDCIssuerType,
2425
OrganizationManualActivation,
@@ -1788,10 +1789,11 @@ def test_add_oidc_issuer_success(self, db_request, monkeypatch):
17881789
assert record_event.calls == [
17891790
pretend.call(
17901791
request=db_request,
1791-
tag="admin:organization:oidc_issuer:add",
1792+
tag=EventTag.Organization.OIDCPublisherAdded,
17921793
additional={
17931794
"issuer_type": "gitlab",
17941795
"issuer_url": "https://gitlab.company.com",
1796+
"submitted_by_user_id": str(admin_user.id),
17951797
},
17961798
)
17971799
]
@@ -1949,10 +1951,11 @@ def test_delete_oidc_issuer_success(self, db_request, monkeypatch):
19491951
assert record_event.calls == [
19501952
pretend.call(
19511953
request=db_request,
1952-
tag="admin:organization:oidc_issuer:delete",
1954+
tag=EventTag.Organization.OIDCPublisherRemoved,
19531955
additional={
19541956
"issuer_type": "gitlab",
19551957
"issuer_url": "https://gitlab.company.com",
1958+
"deleted_by_user_id": str(admin_user.id),
19561959
},
19571960
)
19581961
]

warehouse/admin/views/organizations.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ONE_MIB,
2424
UPLOAD_LIMIT_CAP,
2525
)
26+
from warehouse.events.tags import EventTag
2627
from warehouse.manage.forms import OrganizationNameMixin, SaveOrganizationForm
2728
from warehouse.organizations.interfaces import IOrganizationService
2829
from warehouse.organizations.models import (
@@ -1287,6 +1288,7 @@ class OrganizationOIDCIssuerForm(wtforms.Form):
12871288
)
12881289
def add_oidc_issuer(request):
12891290
organization_service = request.find_service(IOrganizationService, context=None)
1291+
user_service = request.find_service(IUserService)
12901292

12911293
organization_id = request.matchdict["organization_id"]
12921294
organization = organization_service.get_organization(organization_id)
@@ -1339,10 +1341,11 @@ def add_oidc_issuer(request):
13391341
# Record the event
13401342
organization.record_event(
13411343
request=request,
1342-
tag="admin:organization:oidc_issuer:add",
1344+
tag=EventTag.Organization.OIDCPublisherAdded,
13431345
additional={
13441346
"issuer_type": form.issuer_type.data.value,
13451347
"issuer_url": form.issuer_url.data,
1348+
"submitted_by_user_id": str(user_service.get_admin_user().id),
13461349
},
13471350
)
13481351

@@ -1367,6 +1370,7 @@ def add_oidc_issuer(request):
13671370
)
13681371
def delete_oidc_issuer(request):
13691372
organization_service = request.find_service(IOrganizationService, context=None)
1373+
user_service = request.find_service(IUserService)
13701374

13711375
organization_id = request.matchdict["organization_id"]
13721376
organization = organization_service.get_organization(organization_id)
@@ -1395,10 +1399,11 @@ def delete_oidc_issuer(request):
13951399
# Record the event before deleting
13961400
organization.record_event(
13971401
request=request,
1398-
tag="admin:organization:oidc_issuer:delete",
1402+
tag=EventTag.Organization.OIDCPublisherRemoved,
13991403
additional={
14001404
"issuer_type": issuer.issuer_type.value,
14011405
"issuer_url": issuer.issuer_url,
1406+
"deleted_by_user_id": str(user_service.get_admin_user().id),
14021407
},
14031408
)
14041409

warehouse/events/tags.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ class Organization(EventTagEnum):
181181
TeamRoleAdd = "organization:team_role:add"
182182
TeamRoleRemove = "organization:team_role:remove"
183183

184+
OIDCPublisherAdded = "organization:oidc:publisher-added"
185+
OIDCPublisherRemoved = "organization:oidc:publisher-removed"
186+
PendingOIDCPublisherAdded = "organization:oidc:pending-publisher-added"
187+
PendingOIDCPublisherRemoved = "organization:oidc:pending-publisher-removed"
188+
184189
class Team(EventTagEnum):
185190
"""Tags for Organization events.
186191

0 commit comments

Comments
 (0)