fix: keep is_public and visibility in sync on updates
When visibility changes to 'public', is_public=True. When it changes away from 'public', is_public=False. When is_public is set via TreeUpdate, visibility column is updated to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -629,6 +629,13 @@ async def update_tree(
|
|||||||
for field, value in update_data.items():
|
for field, value in update_data.items():
|
||||||
setattr(tree, field, value)
|
setattr(tree, field, value)
|
||||||
|
|
||||||
|
# Keep visibility and is_public in sync
|
||||||
|
if tree_data.is_public is not None:
|
||||||
|
if tree_data.is_public and tree.visibility not in ('public',):
|
||||||
|
tree.visibility = 'public'
|
||||||
|
elif not tree_data.is_public and tree.visibility == 'public':
|
||||||
|
tree.visibility = 'team' # downgrade from public to team
|
||||||
|
|
||||||
# Increment version if tree structure changed
|
# Increment version if tree structure changed
|
||||||
if "tree_structure" in update_data:
|
if "tree_structure" in update_data:
|
||||||
tree.version += 1
|
tree.version += 1
|
||||||
@@ -1074,6 +1081,7 @@ async def update_tree_visibility(
|
|||||||
# Update visibility
|
# Update visibility
|
||||||
old_visibility = tree.visibility
|
old_visibility = tree.visibility
|
||||||
tree.visibility = visibility_data.visibility
|
tree.visibility = visibility_data.visibility
|
||||||
|
tree.is_public = (visibility_data.visibility == 'public')
|
||||||
|
|
||||||
await log_audit(db, current_user.id, "tree.visibility.update", "tree", tree.id,
|
await log_audit(db, current_user.id, "tree.visibility.update", "tree", tree.id,
|
||||||
{"tree_name": tree.name, "old_visibility": old_visibility,
|
{"tree_name": tree.name, "old_visibility": old_visibility,
|
||||||
|
|||||||
Reference in New Issue
Block a user