CLI upgrade_attachment_schema: also remove attachments form_schema

Previously they would have {'attachments': {'visible': False}}, but this
is no longer needed.
This commit is contained in:
2016-10-27 10:34:01 +02:00
parent 964e807721
commit fe4d70c0d1
2 changed files with 13 additions and 3 deletions

View File

@@ -656,7 +656,7 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False):
# Node types that support attachments # Node types that support attachments
node_types = (node_type_asset, node_type_page, node_type_post) node_types = (node_type_asset, node_type_page, node_type_post)
node_type_names = {nt['name'] for nt in node_types} nts_by_name = {nt['name']: nt for nt in node_types}
db = current_app.db() db = current_app.db()
projects_coll = db['projects'] projects_coll = db['projects']
@@ -671,13 +671,22 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False):
def replace_schemas(project): def replace_schemas(project):
for proj_nt in project['node_types']: for proj_nt in project['node_types']:
nt_name = proj_nt['name'] nt_name = proj_nt['name']
if nt_name not in node_type_names: if nt_name not in nts_by_name:
log.info(' - skipping node type "%s"', nt_name) log.info(' - skipping node type "%s"', nt_name)
continue continue
log.info(' - replacing attachment schema on node type "%s"', nt_name) log.info(' - replacing attachment schema on node type "%s"', nt_name)
pillar_nt = nts_by_name[nt_name]
proj_nt['dyn_schema']['attachments'] = copy.deepcopy(_attachments_embedded_schema) proj_nt['dyn_schema']['attachments'] = copy.deepcopy(_attachments_embedded_schema)
# Get the form schema the same as the official Pillar one, but only for attachments.
try:
pillar_form_schema = pillar_nt['form_schema']['attachments']
except KeyError:
proj_nt['form_schema'].pop('attachments', None)
else:
proj_nt['form_schema']['attachments'] = pillar_form_schema
# Use Eve to PUT, so we have schema checking. # Use Eve to PUT, so we have schema checking.
db_proj = remove_private_keys(project) db_proj = remove_private_keys(project)
r, _, _, status = put_internal('projects', db_proj, _id=project['_id']) r, _, _, status = put_internal('projects', db_proj, _id=project['_id'])
@@ -690,7 +699,7 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False):
log.info('Upgrading nodes for project %s', project['url']) log.info('Upgrading nodes for project %s', project['url'])
nodes = nodes_coll.find({ nodes = nodes_coll.find({
'project': project['_id'], 'project': project['_id'],
'node_type': {'$in': list(node_type_names)}, 'node_type': {'$in': list(nts_by_name)},
'properties.attachments': {'$exists': True}, 'properties.attachments': {'$exists': True},
}) })
for node in nodes: for node in nodes:

View File

@@ -337,6 +337,7 @@ class UpgradeAttachmentSchemaTest(AbstractNodeReplacementTest):
nt_asset = get_node_type(dbproj, 'asset') nt_asset = get_node_type(dbproj, 'asset')
self.assertEqual(node_type_asset['dyn_schema']['attachments'], self.assertEqual(node_type_asset['dyn_schema']['attachments'],
nt_asset['dyn_schema']['attachments']) nt_asset['dyn_schema']['attachments'])
self.assertNotIn('attachments', nt_asset['form_schema'])
# Test that the permissions set previously are still there. # Test that the permissions set previously are still there.
self.assertEqual([group_perms], nt_asset['permissions']['groups']) self.assertEqual([group_perms], nt_asset['permissions']['groups'])