Skip to content

Commit

Permalink
remove JournalEntry for role events
Browse files Browse the repository at this point in the history
  • Loading branch information
dstufft committed May 21, 2024
1 parent a5154a0 commit 37fd693
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 183 deletions.
2 changes: 0 additions & 2 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,6 @@ def test_upload_succeeds_custom_project_size_limit(
)
assert [(j.name, j.version, j.action, j.submitted_by) for j in journals] == [
("example", None, "create", user),
("example", None, f"add Owner {user.username}", user),
("example", "1.0", "new release", user),
("example", "1.0", "add source file example-1.0.tar.gz", user),
]
Expand Down Expand Up @@ -3690,7 +3689,6 @@ def test_upload_succeeds_creates_project(
)
assert [(j.name, j.version, j.action, j.submitted_by) for j in journals] == [
("example", None, "create", user),
("example", None, f"add Owner {user.username}", user),
("example", "1.0", "new release", user),
("example", "1.0", "add source file example-1.0.tar.gz", user),
]
Expand Down
30 changes: 0 additions & 30 deletions tests/unit/manage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5356,16 +5356,6 @@ def test_change_role(self, db_request, monkeypatch):
assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == project.name
assert entry.action == "change Owner testuser to Maintainer"
assert entry.submitted_by == db_request.user

def test_change_role_invalid_role_name(self, pyramid_request):
project = pretend.stub(name="foobar")

Expand Down Expand Up @@ -5475,16 +5465,6 @@ def test_delete_role(self, db_request, monkeypatch):
assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == project.name
assert entry.action == "remove Owner testuser"
assert entry.submitted_by == db_request.user

def test_delete_missing_role(self, db_request):
project = ProjectFactory.create(name="foobar")
missing_role_id = str(uuid.uuid4())
Expand Down Expand Up @@ -5572,16 +5552,6 @@ def test_delete_not_sole_owner_role(self, db_request, monkeypatch):
assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == project.name
assert entry.action == "remove Owner testuser"
assert entry.submitted_by == db_request.user

def test_delete_non_owner_role(self, db_request):
project = ProjectFactory.create(name="foobar")
user = UserFactory.create(username="testuser")
Expand Down
21 changes: 0 additions & 21 deletions tests/unit/manage/views/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
TeamProjectRoleType,
TeamRoleType,
)
from warehouse.packaging.models import JournalEntry
from warehouse.utils.paginate import paginate_url_factory


Expand Down Expand Up @@ -825,16 +824,6 @@ def test_change_role(
assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == organization_project.name
assert entry.action == f"change Owner {organization_team.name} to Maintainer"
assert entry.submitted_by == db_request.user

def test_change_role_invalid_role_name(self, pyramid_request, organization_project):
pyramid_request.method = "POST"
pyramid_request.POST = MultiDict(
Expand Down Expand Up @@ -1011,16 +1000,6 @@ def test_delete_role(
assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"

entry = (
db_request.db.query(JournalEntry)
.options(joinedload(JournalEntry.submitted_by))
.one()
)

assert entry.name == organization_project.name
assert entry.action == f"remove Owner {organization_team.name}"
assert entry.submitted_by == db_request.user

def test_delete_missing_role(self, db_request, organization_project):
missing_role_id = str(uuid.uuid4())

Expand Down
9 changes: 1 addition & 8 deletions warehouse/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,14 +1251,7 @@ def _error(message):

request.db.add(Role(user=user, project=project, role_name=desired_role))
request.db.delete(role_invite)
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"accepted {desired_role} {user.username}",
submitted_by=request.user,
)
)

project.record_event(
tag=EventTag.Project.RoleAdd,
request=request,
Expand Down
17 changes: 0 additions & 17 deletions warehouse/admin/views/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,6 @@ def add_role(project, request):
)
)

request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"add {role_name} {user.username}",
submitted_by=request.user,
)
)

request.db.add(Role(role_name=role_name, user=user, project=project))

request.session.flash(
Expand Down Expand Up @@ -642,14 +633,6 @@ def delete_role(project, request):
f"Removed '{role.user.username}' as '{role.role_name}' on '{project.name}'",
queue="success",
)
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"remove {role.role_name} {role.user.username}",
submitted_by=request.user,
)
)

request.db.delete(role)

Expand Down
55 changes: 1 addition & 54 deletions warehouse/manage/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2431,16 +2431,6 @@ def manage_project_roles(project, request, _form_class=CreateRoleForm):
# Add internal team.
organization_service.add_team_project_role(team.id, project.id, role_name)

# Add journal entry.
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"add {role_name.value} {team_name}",
submitted_by=request.user,
)
)

# Record events.
project.record_event(
tag=EventTag.Project.TeamProjectRoleAdd,
Expand Down Expand Up @@ -2542,16 +2532,6 @@ def manage_project_roles(project, request, _form_class=CreateRoleForm):
# Add internal member.
request.db.add(Role(user=user, project=project, role_name=role_name))

# Add journal entry.
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"add {role_name} {user.username}",
submitted_by=request.user,
)
)

# Record events.
project.record_event(
tag=EventTag.Project.RoleAdd,
Expand Down Expand Up @@ -2668,14 +2648,6 @@ def manage_project_roles(project, request, _form_class=CreateRoleForm):
)
)

request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"invite {role_name} {username}",
submitted_by=request.user,
)
)
send_project_role_verification_email(
request,
user,
Expand Down Expand Up @@ -2754,14 +2726,6 @@ def revoke_project_role_invitation(project, request, _form_class=ChangeRoleForm)
)
role_name = token_data.get("desired_role")

request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"revoke_invite {role_name} {user.username}",
submitted_by=request.user,
)
)
project.record_event(
tag=EventTag.Project.RoleRevokeInvite,
request=request,
Expand Down Expand Up @@ -2817,16 +2781,6 @@ def change_project_role(project, request, _form_class=ChangeRoleForm):
if role.role_name == "Owner" and role.user == request.user:
request.session.flash("Cannot remove yourself as Owner", queue="error")
else:
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action="change {} {} to {}".format(
role.role_name, role.user.username, form.role_name.data
),
submitted_by=request.user,
)
)
role.role_name = form.role_name.data
project.record_event(
tag=EventTag.Project.RoleChange,
Expand Down Expand Up @@ -2904,14 +2858,7 @@ def delete_project_role(project, request):
request.session.flash("Cannot remove yourself as Sole Owner", queue="error")
else:
request.db.delete(role)
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"remove {role.role_name} {role.user.username}",
submitted_by=request.user,
)
)

project.record_event(
tag=EventTag.Project.RoleRemove,
request=request,
Expand Down
17 changes: 1 addition & 16 deletions warehouse/manage/views/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,14 +744,7 @@ def add_organization_project(self):
)
if role:
self.request.db.delete(role)
self.request.db.add(
JournalEntry.create_with_lock(
self.request.db,
name=project.name,
action=f"remove {role.role_name} {role.user.username}",
submitted_by=self.request.user,
)
)

project.record_event(
tag=EventTag.Project.RoleRemove,
request=self.request,
Expand Down Expand Up @@ -1521,14 +1514,6 @@ def transfer_organization_project(project, request):
)
if role:
request.db.delete(role)
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"remove {role.role_name} {role.user.username}",
submitted_by=request.user,
)
)
project.record_event(
tag=EventTag.Project.RoleRemove,
request=request,
Expand Down
24 changes: 0 additions & 24 deletions warehouse/manage/views/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,20 +519,6 @@ def change_team_project_role(project, request, _form_class=ChangeTeamProjectRole
queue="error",
)
else:
# Add journal entry.
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action="change {} {} to {}".format(
role.role_name.value,
role.team.name,
form.team_project_role_name.data.value,
),
submitted_by=request.user,
)
)

# Change team project role.
role.role_name = form.team_project_role_name.data

Expand Down Expand Up @@ -629,16 +615,6 @@ def delete_team_project_role(project, request):
# Delete role.
request.db.delete(role)

# Add journal entry.
request.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"remove {role_name.value} {team.name}",
submitted_by=request.user,
)
)

# Record event.
project.record_event(
tag=EventTag.Project.TeamProjectRoleRemove,
Expand Down
12 changes: 1 addition & 11 deletions warehouse/packaging/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,17 +563,7 @@ def create_project(
# Mark the creator as the newly created project's owner, if configured.
if creator_is_owner:
self.db.add(Role(user=creator, project=project, role_name="Owner"))
# TODO: This should be handled by some sort of database trigger or a
# SQLAlchemy hook or the like instead of doing it inline in this
# service.
self.db.add(
JournalEntry.create_with_lock(
request.db,
name=project.name,
action=f"add Owner {creator.username}",
submitted_by=creator,
)
)

project.record_event(
tag=EventTag.Project.RoleAdd,
request=request,
Expand Down

0 comments on commit 37fd693

Please sign in to comment.