Skip to content

Commit

Permalink
Update project role journal entries and events
Browse files Browse the repository at this point in the history
- Standardize journal entry action to be "add {role_name} {username}"
- Standardize project event tag to be "project:role:create"
- Standardize user event tag to be "account:role:create"
- Relates to pypi#7119.

Cherry-picked commit 1b0ff20 from pypi#11779.
  • Loading branch information
divbzero committed Oct 12, 2022
1 parent ff61833 commit 127feaf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/unit/malware/checks/package_turnover/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_user_turnover_verdicts(db_session):
RoleFactory.create(user=user, project=project, role_name="Owner")

project.record_event(
tag="project:role:add",
tag="project:role:create",
ip_address="0.0.0.0",
additional={"target_user": user.username},
)
Expand Down
6 changes: 3 additions & 3 deletions warehouse/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,13 +1067,13 @@ def _error(message):
request.db.add(
JournalEntry(
name=project.name,
action=f"accepted {desired_role} {user.username}",
action=f"add {desired_role} {user.username}",
submitted_by=request.user,
submitted_from=request.remote_addr,
)
)
project.record_event(
tag="project:role:accepted",
tag="project:role:create",
ip_address=request.remote_addr,
additional={
"submitted_by": request.user.username,
Expand All @@ -1082,7 +1082,7 @@ def _error(message):
},
)
user.record_event(
tag="account:role:accepted",
tag="account:role:create",
ip_address=request.remote_addr,
additional={
"submitted_by": request.user.username,
Expand Down
2 changes: 1 addition & 1 deletion warehouse/forklift/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def file_upload(request):
)
)
project.record_event(
tag="project:role:add",
tag="project:role:create",
ip_address=request.remote_addr,
additional={
"submitted_by": request.user.username,
Expand Down
6 changes: 5 additions & 1 deletion warehouse/malware/checks/package_turnover/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def user_turnover_verdicts(self, project):
self.db.query(Project.Event.additional)
.filter(Project.Event.source_id == project.id)
.filter(Project.Event.time >= self._scan_interval)
.filter(Project.Event.tag == "project:role:add")
.filter(
(Project.Event.tag == "project:role:accepted")
| (Project.Event.tag == "project:role:add")
| (Project.Event.tag == "project:role:create")
)
.all()
)

Expand Down
2 changes: 1 addition & 1 deletion warehouse/templates/manage/project/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h2>{% trans %}Security history{% endtrans %}</h2>
<small>
{% trans %}Removed by:{% endtrans %} <a href="{{ request.route_path('accounts.profile', username=event.additional.submitted_by) }}">{{ event.additional.submitted_by }}</a>
</small>
{% elif event.tag == "project:role:add" %}
{% elif event.tag in ["project:role:accepted", "project:role:add", "project:role:create"] %}
<strong>{% trans href=request.route_path('accounts.profile', username=event.additional.target_user), username=event.additional.target_user, role_name=event.additional.role_name|lower %}<a href="{{ href }}">{{ username }}</a> added as project {{ role_name }}{% endtrans %}</strong><br>
<small>
{% trans %}Added by:{% endtrans %} <a href="{{ request.route_path('accounts.profile', username=event.additional.submitted_by) }}">{{ event.additional.submitted_by }}</a>
Expand Down

0 comments on commit 127feaf

Please sign in to comment.