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,3 +1,5 @@
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from atst.database import db
|
||||
from atst.domain.environments import Environments
|
||||
from atst.domain.exceptions import NotFoundError
|
||||
@@ -23,7 +25,9 @@ class Applications(object):
|
||||
def get(cls, application_id):
|
||||
try:
|
||||
application = (
|
||||
db.session.query(Application).filter_by(id=application_id).one()
|
||||
db.session.query(Application)
|
||||
.filter_by(id=application_id, deleted=False)
|
||||
.one()
|
||||
)
|
||||
except NoResultFound:
|
||||
raise NotFoundError("application")
|
||||
|
@@ -51,7 +51,11 @@ class Environments(object):
|
||||
@classmethod
|
||||
def get(cls, environment_id):
|
||||
try:
|
||||
env = db.session.query(Environment).filter_by(id=environment_id).one()
|
||||
env = (
|
||||
db.session.query(Environment)
|
||||
.filter_by(id=environment_id, deleted=False)
|
||||
.one()
|
||||
)
|
||||
except NoResultFound:
|
||||
raise NotFoundError("environment")
|
||||
|
||||
|
@@ -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