Skip to content

Commit 0d64f52

Browse files
committed
feat: connect pending publishers to organizations
First step to allowing an Organization to create a Pending Trusted Publisher is to create a link between the models, so that when reify-ing to a real publisher, the ownership relationship can be maintained. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
1 parent a220ded commit 0d64f52

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
"""
3+
Add Org ID to pending_oidc_publishers
4+
5+
Revision ID: 6c0f7fea7b1b
6+
Revises: daf71d83673f
7+
Create Date: 2025-11-04 23:29:08.395688
8+
"""
9+
10+
import sqlalchemy as sa
11+
12+
from alembic import op
13+
14+
revision = "6c0f7fea7b1b"
15+
down_revision = "daf71d83673f"
16+
17+
18+
def upgrade():
19+
op.add_column(
20+
"pending_oidc_publishers",
21+
sa.Column("organization_id", sa.UUID(), nullable=True),
22+
)
23+
op.create_index(
24+
op.f("ix_pending_oidc_publishers_organization_id"),
25+
"pending_oidc_publishers",
26+
["organization_id"],
27+
unique=False,
28+
)
29+
op.create_foreign_key(
30+
None, "pending_oidc_publishers", "organizations", ["organization_id"], ["id"]
31+
)
32+
33+
34+
def downgrade():
35+
op.drop_constraint(None, "pending_oidc_publishers", type_="foreignkey")
36+
op.drop_index(
37+
op.f("ix_pending_oidc_publishers_organization_id"),
38+
table_name="pending_oidc_publishers",
39+
)
40+
op.drop_column("pending_oidc_publishers", "organization_id")

warehouse/oidc/models/_core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from warehouse.accounts.models import User
2626
from warehouse.macaroons.models import Macaroon
2727
from warehouse.oidc.services import OIDCPublisherService
28+
from warehouse.organizations.models import Organization
2829
from warehouse.packaging.models import Project
2930

3031

@@ -387,6 +388,15 @@ class PendingOIDCPublisher(OIDCPublisherMixin, db.Model):
387388
PG_UUID(as_uuid=True), ForeignKey("users.id"), nullable=False, index=True
388389
)
389390
added_by: Mapped[User] = orm.relationship(back_populates="pending_oidc_publishers")
391+
organization_id: Mapped[UUID | None] = mapped_column(
392+
PG_UUID(as_uuid=True),
393+
ForeignKey("organizations.id"),
394+
nullable=True,
395+
index=True,
396+
)
397+
pypi_organization: Mapped[Organization | None] = orm.relationship(
398+
back_populates="pending_oidc_publishers"
399+
)
390400

391401
__table_args__ = (
392402
Index(

warehouse/organizations/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
if typing.TYPE_CHECKING:
4545
from pyramid.request import Request
4646

47+
from warehouse.oidc.models import PendingOIDCPublisher
4748
from warehouse.packaging.models import Project
4849
from warehouse.subscriptions.models import StripeCustomer, StripeSubscription
4950

@@ -402,6 +403,9 @@ class Organization(OrganizationMixin, HasEvents, db.Model):
402403
oidc_issuers: Mapped[list[OrganizationOIDCIssuer]] = relationship(
403404
back_populates="organization",
404405
)
406+
pending_oidc_publishers: Mapped[list[PendingOIDCPublisher]] = relationship(
407+
back_populates="pypi_organization",
408+
)
405409

406410
@property
407411
def owners(self):

0 commit comments

Comments
 (0)