Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/folders/serializers/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,13 @@ def edit(self, instance):
and current_node.parent_id != parent_id
):
source_type = self.data.get("source")
if has_target_permission(
current_node.workspace_id, source_type, self.data.get("user_id"), parent_id
) or is_workspace_manage(self.data.get("user_id"), current_node.workspace_id):
if (
parent_id == current_node.workspace_id
or has_target_permission(
current_node.workspace_id, source_type, self.data.get("user_id"), parent_id
)
or is_workspace_manage(self.data.get("user_id"), current_node.workspace_id)
):
current_depth = get_max_depth(current_node)
check_depth(self.data.get("source"), parent_id, current_node.workspace_id, current_depth)
parent = Folder.objects.get(id=parent_id)
Expand Down
12 changes: 12 additions & 0 deletions apps/folders/tests/test_mptt_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ def test_serializer_moves_a_subtree_without_losing_descendants(self, _permission
self.assertEqual(list(leaf.get_ancestors().values_list("id", flat=True)), [root.id, right.id, left.id])
self.assert_valid_tree(model, root.workspace_id)

@patch("folders.serializers.folder.is_workspace_manage", return_value=False)
@patch("folders.serializers.folder.has_target_permission", return_value=False)
def test_regular_user_can_move_subfolder_to_workspace_root(self, _target_permission, _workspace_manage):
for source, model in self.folder_types:
with self.subTest(source=source):
root, _, _, leaf = self.make_tree(model)
result = self.operation(source, leaf).edit({"parent_id": root.id})
self.assertEqual(result["parent_id"], root.id)
leaf.refresh_from_db()
self.assertEqual(leaf.parent_id, root.id)
self.assert_valid_tree(model, root.workspace_id)

def test_move_to_refreshes_instances_loaded_before_another_move(self):
for source, model in self.folder_types:
with self.subTest(source=source):
Expand Down
Loading