feat(trash): exclude trashed rows from events/projects/milestones/rulebooks/embeddings reads + filtering tests
This commit is contained in:
@@ -39,7 +39,7 @@ async def list_rulebooks(user_id: int) -> list[Rulebook]:
|
||||
async with async_session() as session:
|
||||
result = await session.execute(
|
||||
select(Rulebook)
|
||||
.where(Rulebook.owner_user_id == user_id)
|
||||
.where(Rulebook.owner_user_id == user_id, Rulebook.deleted_at.is_(None))
|
||||
.order_by(Rulebook.title)
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
@@ -52,6 +52,7 @@ async def get_rulebook(rulebook_id: int, user_id: int) -> Optional[Rulebook]:
|
||||
select(Rulebook).where(
|
||||
Rulebook.id == rulebook_id,
|
||||
Rulebook.owner_user_id == user_id,
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
@@ -105,6 +106,7 @@ async def find_rulebook_by_title(
|
||||
select(Rulebook).where(
|
||||
Rulebook.owner_user_id == user_id,
|
||||
Rulebook.title == title,
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
@@ -123,6 +125,7 @@ async def _assert_rulebook_owned(session, rulebook_id: int, user_id: int) -> Non
|
||||
select(Rulebook).where(
|
||||
Rulebook.id == rulebook_id,
|
||||
Rulebook.owner_user_id == user_id,
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
if result.scalar_one_or_none() is None:
|
||||
@@ -152,7 +155,10 @@ async def list_topics(rulebook_id: int, user_id: int) -> list[RulebookTopic]:
|
||||
await _assert_rulebook_owned(session, rulebook_id, user_id)
|
||||
result = await session.execute(
|
||||
select(RulebookTopic)
|
||||
.where(RulebookTopic.rulebook_id == rulebook_id)
|
||||
.where(
|
||||
RulebookTopic.rulebook_id == rulebook_id,
|
||||
RulebookTopic.deleted_at.is_(None),
|
||||
)
|
||||
.order_by(RulebookTopic.order_index, RulebookTopic.title)
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
@@ -167,6 +173,8 @@ async def get_topic(topic_id: int, user_id: int) -> Optional[RulebookTopic]:
|
||||
.where(
|
||||
RulebookTopic.id == topic_id,
|
||||
Rulebook.owner_user_id == user_id,
|
||||
RulebookTopic.deleted_at.is_(None),
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
@@ -226,6 +234,8 @@ async def _assert_topic_owned(session, topic_id: int, user_id: int) -> None:
|
||||
.where(
|
||||
RulebookTopic.id == topic_id,
|
||||
Rulebook.owner_user_id == user_id,
|
||||
RulebookTopic.deleted_at.is_(None),
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
if result.scalar_one_or_none() is None:
|
||||
@@ -269,7 +279,12 @@ async def list_rules(
|
||||
select(Rule)
|
||||
.join(RulebookTopic, Rule.topic_id == RulebookTopic.id)
|
||||
.join(Rulebook, RulebookTopic.rulebook_id == Rulebook.id)
|
||||
.where(Rulebook.owner_user_id == user_id)
|
||||
.where(
|
||||
Rulebook.owner_user_id == user_id,
|
||||
Rule.deleted_at.is_(None),
|
||||
RulebookTopic.deleted_at.is_(None),
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
if topic_id:
|
||||
stmt = stmt.where(Rule.topic_id == topic_id)
|
||||
@@ -299,6 +314,9 @@ async def get_rule(rule_id: int, user_id: int) -> Optional[Rule]:
|
||||
.where(
|
||||
Rule.id == rule_id,
|
||||
Rulebook.owner_user_id == user_id,
|
||||
Rule.deleted_at.is_(None),
|
||||
RulebookTopic.deleted_at.is_(None),
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
@@ -411,6 +429,7 @@ async def get_applicable_rules(
|
||||
.where(
|
||||
project_rulebook_subscriptions.c.project_id == project_id,
|
||||
Rulebook.owner_user_id == user_id,
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
.order_by(Rulebook.title)
|
||||
)
|
||||
@@ -435,6 +454,9 @@ async def get_applicable_rules(
|
||||
.where(
|
||||
project_rulebook_subscriptions.c.project_id == project_id,
|
||||
Rulebook.owner_user_id == user_id,
|
||||
Rule.deleted_at.is_(None),
|
||||
RulebookTopic.deleted_at.is_(None),
|
||||
Rulebook.deleted_at.is_(None),
|
||||
)
|
||||
.order_by(
|
||||
Rulebook.id, RulebookTopic.order_index, Rule.order_index, Rule.title,
|
||||
|
||||
Reference in New Issue
Block a user