Skip to content

Commit 26e6424

Browse files
ewdurbinnnjachrysledi
authored
issue purge when projects are transferred to/between orgs (#13532)
* issue purge when projects are transferred to/between orgs Co-authored-by: Nina Zakharenko <[email protected]> * Update warehouse/organizations/services.py Co-authored-by: chrysle <[email protected]> * Autoformatting * Move bin/flushes check to later in linting check * fix translations --------- Co-authored-by: Nina Zakharenko <[email protected]> Co-authored-by: chrysle <[email protected]> Co-authored-by: Dustin Ingram <[email protected]>
1 parent e5db5ab commit 26e6424

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

bin/lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ set -x
1212

1313
# Actually run our tests.
1414
find . -name '*.py' -exec python -m pyupgrade --py311-plus {} +
15-
./bin/flushes
1615
python -m flake8 .
1716
python -m black --check *.py warehouse/ tests/
1817
python -m isort --check *.py warehouse/ tests/
1918
python -m doc8 --allow-long-titles README.rst CONTRIBUTING.rst docs/ --ignore-path "docs/**/_build/"
2019
python -m curlylint ./warehouse/templates ./docs/blog
2120
python -m mypy -p warehouse
21+
./bin/flushes

tests/unit/packaging/test_init.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@ def key_factory(keystring, iterate_on=None, if_attr_exists=None):
140140
),
141141
],
142142
),
143-
pretend.call(Organization, cache_keys=["org/{obj.normalized_name}"]),
143+
pretend.call(
144+
Organization,
145+
cache_keys=["org/{obj.normalized_name}"],
146+
purge_keys=[
147+
key_factory("org/{obj.normalized_name}"),
148+
],
149+
),
144150
pretend.call(
145151
Organization.name,
146152
purge_keys=[

warehouse/locale/messages.pot

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,12 @@ msgid ""
463463
msgstr ""
464464

465465
#: warehouse/manage/views/__init__.py:2278
466-
#: warehouse/manage/views/organizations.py:881
466+
#: warehouse/manage/views/organizations.py:882
467467
msgid "User '${username}' already has an active invite. Please try again later."
468468
msgstr ""
469469

470470
#: warehouse/manage/views/__init__.py:2344
471-
#: warehouse/manage/views/organizations.py:946
471+
#: warehouse/manage/views/organizations.py:947
472472
msgid "Invitation sent to '${username}'"
473473
msgstr ""
474474

@@ -481,30 +481,30 @@ msgid "Invitation already expired."
481481
msgstr ""
482482

483483
#: warehouse/manage/views/__init__.py:2421
484-
#: warehouse/manage/views/organizations.py:1133
484+
#: warehouse/manage/views/organizations.py:1134
485485
msgid "Invitation revoked from '${username}'."
486486
msgstr ""
487487

488-
#: warehouse/manage/views/organizations.py:857
488+
#: warehouse/manage/views/organizations.py:858
489489
msgid "User '${username}' already has ${role_name} role for organization"
490490
msgstr ""
491491

492-
#: warehouse/manage/views/organizations.py:868
492+
#: warehouse/manage/views/organizations.py:869
493493
msgid ""
494494
"User '${username}' does not have a verified primary email address and "
495495
"cannot be added as a ${role_name} for organization"
496496
msgstr ""
497497

498-
#: warehouse/manage/views/organizations.py:1029
499-
#: warehouse/manage/views/organizations.py:1071
498+
#: warehouse/manage/views/organizations.py:1030
499+
#: warehouse/manage/views/organizations.py:1072
500500
msgid "Could not find organization invitation."
501501
msgstr ""
502502

503-
#: warehouse/manage/views/organizations.py:1039
503+
#: warehouse/manage/views/organizations.py:1040
504504
msgid "Organization invitation could not be re-sent."
505505
msgstr ""
506506

507-
#: warehouse/manage/views/organizations.py:1086
507+
#: warehouse/manage/views/organizations.py:1087
508508
msgid "Expired invitation for '${username}' deleted."
509509
msgstr ""
510510

warehouse/manage/views/organizations.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
HTTPSeeOther,
2020
)
2121
from pyramid.view import view_config, view_defaults
22+
from sqlalchemy import orm
2223

2324
from warehouse.accounts.interfaces import ITokenService, IUserService, TokenExpired
2425
from warehouse.accounts.models import User
@@ -1572,6 +1573,9 @@ def transfer_organization_project(project, request):
15721573
project_name=project.name,
15731574
)
15741575

1576+
# Mark Organization as dirty, so purges will happen
1577+
orm.attributes.flag_dirty(organization)
1578+
15751579
# Add project to selected organization.
15761580
organization = organization_service.get_organization_by_name(form.organization.data)
15771581
organization_service.add_organization_project(organization.id, project.id)
@@ -1592,6 +1596,9 @@ def transfer_organization_project(project, request):
15921596
},
15931597
)
15941598

1599+
# Mark Organization as dirty, so purges will happen
1600+
orm.attributes.flag_dirty(organization)
1601+
15951602
# Send notification emails.
15961603
owner_users = set(
15971604
organization_owners(request, organization) + project_owners(request, project)

warehouse/organizations/services.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import datetime
1414

15-
from sqlalchemy import delete, func, select
15+
from sqlalchemy import delete, func, orm, select
1616
from sqlalchemy.exc import NoResultFound
1717
from zope.interface import implementer
1818

@@ -396,6 +396,10 @@ def add_organization_project(self, organization_id, project_id):
396396
)
397397

398398
self.db.add(organization_project)
399+
self.db.flush() # Flush db so we can address the organization related object
400+
401+
# Mark Organization as dirty, so purges will happen
402+
orm.attributes.flag_dirty(organization_project.organization)
399403

400404
return organization_project
401405

warehouse/packaging/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ def includeme(config):
156156
],
157157
)
158158
config.register_origin_cache_keys(
159-
Organization, cache_keys=["org/{obj.normalized_name}"]
159+
Organization,
160+
cache_keys=["org/{obj.normalized_name}"],
161+
purge_keys=[
162+
key_factory("org/{obj.normalized_name}"),
163+
],
160164
)
161165
config.register_origin_cache_keys(
162166
Organization.name,

0 commit comments

Comments
 (0)