Allow any sub-items to be moved from a folder

Since you can now see them when searching you should also be able to
select and move them. Which means that they needed to be included in
the `Form`’s list of possible choices of things to move.
This commit is contained in:
Chris Hill-Scott
2018-11-23 16:29:21 +00:00
parent cdb03d1eeb
commit ee991d0142
5 changed files with 54 additions and 17 deletions

View File

@@ -1143,8 +1143,8 @@ class TemplateAndFoldersSelectionForm(Form):
def __init__( def __init__(
self, self,
service, all_template_folders,
template_type, template_list,
current_folder_id, current_folder_id,
*args, *args,
**kwargs **kwargs
@@ -1152,20 +1152,12 @@ class TemplateAndFoldersSelectionForm(Form):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.templates_and_folders.choices = self.ids_and_names( self.templates_and_folders.choices = template_list.as_id_and_name
service.get_template_folders_and_templates(template_type, current_folder_id)
)
self.move_to.choices = self.ids_and_names( self.move_to.choices = [
[self.ALL_TEMPLATES_FOLDER] + service.all_template_folders, (item['id'], item['name'])
exclude=current_folder_id, for item in ([self.ALL_TEMPLATES_FOLDER] + all_template_folders)
) if item['id'] != str(current_folder_id)
@staticmethod
def ids_and_names(items, exclude=None):
return [
(item['id'], item['name']) for item in items
if item['id'] != str(exclude)
] ]
templates_and_folders = MultiCheckboxField('Choose templates or folders') templates_and_folders = MultiCheckboxField('Choose templates or folders')

View File

@@ -109,8 +109,11 @@ def start_tour(service_id, template_id):
@user_has_permissions() @user_has_permissions()
def choose_template(service_id, template_type='all', template_folder_id=None): def choose_template(service_id, template_type='all', template_folder_id=None):
template_list = TemplateList(current_service, template_type, template_folder_id)
templates_and_folders_form = TemplateAndFoldersSelectionForm( templates_and_folders_form = TemplateAndFoldersSelectionForm(
service=current_service, all_template_folders=current_service.all_template_folders,
template_list=template_list,
template_type=template_type, template_type=template_type,
current_folder_id=template_folder_id, current_folder_id=template_folder_id,
) )
@@ -127,7 +130,7 @@ def choose_template(service_id, template_type='all', template_folder_id=None):
current_template_folder_id=template_folder_id, current_template_folder_id=template_folder_id,
can_manage_folders=can_manage_folders(), can_manage_folders=can_manage_folders(),
template_folder_path=current_service.get_template_folder_path(template_folder_id), template_folder_path=current_service.get_template_folder_path(template_folder_id),
template_list=TemplateList(current_service, template_type, template_folder_id), template_list=template_list,
show_search_box=current_service.count_of_templates_and_folders > 7, show_search_box=current_service.count_of_templates_and_folders > 7,
show_template_nav=( show_template_nav=(
current_service.has_multiple_template_types current_service.has_multiple_template_types

View File

@@ -44,6 +44,10 @@ class TemplateList():
ancestors=ancestors, ancestors=ancestors,
) )
@property
def as_id_and_name(self):
return [(item.id, item.name) for item in self]
@property @property
def templates_to_show(self): def templates_to_show(self):
return any(self) return any(self)

View File

@@ -378,7 +378,11 @@ def test_should_show_templates_folder_page(
assert links_in_page[index].text.strip() == expected_link assert links_in_page[index].text.strip() == expected_link
all_page_items = page.select('.template-list-item') all_page_items = page.select('.template-list-item')
checkboxes = page.select('input[name=templates_and_folders]')
unique_checkbox_values = set(item['value'] for item in checkboxes)
assert len(all_page_items) == len(expected_items) assert len(all_page_items) == len(expected_items)
assert len(checkboxes) == len(expected_items)
assert len(unique_checkbox_values) == len(expected_items)
for index, expected_item in enumerate(expected_items): for index, expected_item in enumerate(expected_items):
assert normalize_spaces(all_page_items[index].text) == expected_item assert normalize_spaces(all_page_items[index].text) == expected_item

View File

@@ -365,6 +365,40 @@ def test_should_post_move_to_api(
) )
def test_should_be_able_to_move_a_sub_item(
client_request,
service_one,
fake_uuid,
mock_get_service_templates,
mock_get_template_folders,
mock_move_to_template_folder,
):
service_one['permissions'] += ['edit_folders']
GRANDCHILD_FOLDER_ID = str(uuid.uuid4())
mock_get_template_folders.return_value = [
{'id': PARENT_FOLDER_ID, 'name': 'folder_one', 'parent_id': None},
{'id': CHILD_FOLDER_ID, 'name': 'folder_one_one', 'parent_id': PARENT_FOLDER_ID},
{'id': GRANDCHILD_FOLDER_ID, 'name': 'folder_one_one_one', 'parent_id': CHILD_FOLDER_ID},
]
client_request.post(
'main.choose_template',
service_id=SERVICE_ONE_ID,
template_folder_id=PARENT_FOLDER_ID,
_data={
'operation': 'move',
'move_to': 'None',
'templates_and_folders': [GRANDCHILD_FOLDER_ID],
},
_expected_status=302,
)
mock_move_to_template_folder.assert_called_once_with(
service_id=SERVICE_ONE_ID,
folder_id=None,
folder_ids={GRANDCHILD_FOLDER_ID},
template_ids=set(),
)
@pytest.mark.parametrize('thing_to_move', [ @pytest.mark.parametrize('thing_to_move', [
PARENT_FOLDER_ID, # Cant move a folder inside itself PARENT_FOLDER_ID, # Cant move a folder inside itself
CHILD_FOLDER_ID, # Cant move a folder which doesnt belong to the service CHILD_FOLDER_ID, # Cant move a folder which doesnt belong to the service