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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user