soft deletes available for applications and environments
- parent relation will not include applications or environments marked as deleted - domain classes will exclude deleted objects from selections - changed some test factories to use domain_word for resource names, because they were using person names and it bugged me
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, ForeignKey, String
|
||||
from sqlalchemy import Column, ForeignKey, String, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
@@ -15,9 +15,15 @@ class Application(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
||||
|
||||
portfolio_id = Column(ForeignKey("portfolios.id"), nullable=False)
|
||||
portfolio = relationship("Portfolio")
|
||||
environments = relationship("Environment", back_populates="application")
|
||||
environments = relationship(
|
||||
"Environment",
|
||||
back_populates="application",
|
||||
primaryjoin="and_(Environment.application_id==Application.id, Environment.deleted==False)",
|
||||
)
|
||||
roles = relationship("ApplicationRole")
|
||||
|
||||
deleted = Column(Boolean, default=False)
|
||||
|
||||
@property
|
||||
def users(self):
|
||||
return set(role.user for role in self.roles)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, ForeignKey, String
|
||||
from sqlalchemy import Column, ForeignKey, String, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
@@ -17,6 +17,8 @@ class Environment(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
||||
|
||||
cloud_id = Column(String)
|
||||
|
||||
deleted = Column(Boolean, default=False)
|
||||
|
||||
@property
|
||||
def users(self):
|
||||
return [r.user for r in self.roles]
|
||||
|
@@ -16,7 +16,11 @@ class Portfolio(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
||||
name = Column(String)
|
||||
defense_component = Column(String) # Department of Defense Component
|
||||
|
||||
applications = relationship("Application", back_populates="portfolio")
|
||||
applications = relationship(
|
||||
"Application",
|
||||
back_populates="portfolio",
|
||||
primaryjoin="and_(Application.portfolio_id==Portfolio.id, Application.deleted==False)",
|
||||
)
|
||||
roles = relationship("PortfolioRole")
|
||||
|
||||
task_orders = relationship("TaskOrder")
|
||||
|
Reference in New Issue
Block a user