refactor: remove Vendor.owner_user_id column
- Remove owner_user_id column and owner relationship from Vendor model - Update User model ownership checks to use company relationship - Add migration to drop owner_user_id column from vendors table Ownership is now determined solely via vendor.company.owner_user_id 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,6 @@ class User(Base, TimestampMixin):
|
||||
"MarketplaceImportJob", back_populates="user"
|
||||
)
|
||||
owned_companies = relationship("Company", back_populates="owner")
|
||||
owned_vendors = relationship("Vendor", back_populates="owner")
|
||||
vendor_memberships = relationship(
|
||||
"VendorUser", foreign_keys="[VendorUser.user_id]", back_populates="user"
|
||||
)
|
||||
@@ -78,12 +77,20 @@ class User(Base, TimestampMixin):
|
||||
return self.role == UserRole.VENDOR.value
|
||||
|
||||
def is_owner_of(self, vendor_id: int) -> bool:
|
||||
"""Check if user is the owner of a specific vendor."""
|
||||
return any(v.id == vendor_id for v in self.owned_vendors)
|
||||
"""
|
||||
Check if user is the owner of a specific vendor.
|
||||
|
||||
Ownership is determined via company ownership:
|
||||
User owns Company → Company has Vendor → User owns Vendor
|
||||
"""
|
||||
for company in self.owned_companies:
|
||||
if any(v.id == vendor_id for v in company.vendors):
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_member_of(self, vendor_id: int) -> bool:
|
||||
"""Check if user is a member of a specific vendor (owner or team)."""
|
||||
# Check if owner
|
||||
# Check if owner (via company)
|
||||
if self.is_owner_of(vendor_id):
|
||||
return True
|
||||
# Check if team member
|
||||
@@ -93,7 +100,7 @@ class User(Base, TimestampMixin):
|
||||
|
||||
def get_vendor_role(self, vendor_id: int) -> str:
|
||||
"""Get user's role within a specific vendor."""
|
||||
# Check if owner
|
||||
# Check if owner (via company)
|
||||
if self.is_owner_of(vendor_id):
|
||||
return "owner"
|
||||
|
||||
|
||||
@@ -50,10 +50,6 @@ class Vendor(Base, TimestampMixin):
|
||||
name = Column(String, nullable=False) # Non-nullable name column for the vendor (brand name)
|
||||
description = Column(Text) # Optional text description column for the vendor
|
||||
|
||||
owner_user_id = Column(
|
||||
Integer, ForeignKey("users.id"), nullable=True
|
||||
) # Foreign key to user ID of the vendor's owner (DEPRECATED - use company.owner_user_id instead)
|
||||
|
||||
# Letzshop URLs - multi-language support (brand-specific marketplace feeds)
|
||||
letzshop_csv_url_fr = Column(String) # URL for French CSV in Letzshop
|
||||
letzshop_csv_url_en = Column(String) # URL for English CSV in Letzshop
|
||||
@@ -73,9 +69,6 @@ class Vendor(Base, TimestampMixin):
|
||||
company = relationship(
|
||||
"Company", back_populates="vendors"
|
||||
) # Relationship with Company model for the parent company
|
||||
owner = relationship(
|
||||
"User", back_populates="owned_vendors"
|
||||
) # Relationship with User model for the vendor's owner (legacy)
|
||||
vendor_users = relationship(
|
||||
"VendorUser", back_populates="vendor"
|
||||
) # Relationship with VendorUser model for users in this vendor
|
||||
|
||||
Reference in New Issue
Block a user