Fixed CLI cmd upgrade_attachment_schema
It didn't add the {'coerce': 'markdown'}, which caused the upgrade_attachment_usage CLI command to skip 'upgraded' nodes.
This commit is contained in:
@@ -624,7 +624,6 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False, go=False):
|
|||||||
from pillar.api.node_types.asset import node_type_asset
|
from pillar.api.node_types.asset import node_type_asset
|
||||||
from pillar.api.node_types.page import node_type_page
|
from pillar.api.node_types.page import node_type_page
|
||||||
from pillar.api.node_types.post import node_type_post
|
from pillar.api.node_types.post import node_type_post
|
||||||
from pillar.api.node_types import attachments_embedded_schema
|
|
||||||
from pillar.api.utils import remove_private_keys, doc_diff
|
from pillar.api.utils import remove_private_keys, doc_diff
|
||||||
|
|
||||||
# Node types that support attachments
|
# Node types that support attachments
|
||||||
@@ -643,22 +642,15 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False, go=False):
|
|||||||
if nt_name not in nts_by_name:
|
if nt_name not in nts_by_name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if proj_nt['dyn_schema']['attachments'] == attachments_embedded_schema:
|
pillar_nt = nts_by_name[nt_name]
|
||||||
|
pillar_dyn_schema = pillar_nt['dyn_schema']
|
||||||
|
if proj_nt['dyn_schema'] == pillar_dyn_schema:
|
||||||
# Schema already up to date.
|
# Schema already up to date.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
log_proj()
|
log_proj()
|
||||||
log.info(' - replacing attachment schema on node type "%s"', nt_name)
|
log.info(' - replacing dyn_schema on node type "%s"', nt_name)
|
||||||
pillar_nt = nts_by_name[nt_name]
|
proj_nt['dyn_schema'] = copy.deepcopy(pillar_dyn_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
|
|
||||||
|
|
||||||
seen_changes = False
|
seen_changes = False
|
||||||
for key, val1, val2 in doc_diff(orig_proj, project):
|
for key, val1, val2 in doc_diff(orig_proj, project):
|
||||||
|
@@ -328,6 +328,8 @@ class UpgradeAttachmentSchemaTest(AbstractNodeReplacementTest):
|
|||||||
|
|
||||||
group_perms = self.add_group_permission_to_asset_node_type()
|
group_perms = self.add_group_permission_to_asset_node_type()
|
||||||
|
|
||||||
|
orig_nt_asset = get_node_type(self.proj, 'asset')
|
||||||
|
|
||||||
with self.app.test_request_context():
|
with self.app.test_request_context():
|
||||||
upgrade_attachment_schema(self.proj['url'], go=True)
|
upgrade_attachment_schema(self.proj['url'], go=True)
|
||||||
|
|
||||||
@@ -337,7 +339,9 @@ 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'])
|
|
||||||
|
# The form schema should be untouched.
|
||||||
|
self.assertEqual(orig_nt_asset['form_schema'], 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'])
|
||||||
|
@@ -36,6 +36,81 @@ class PurgeHomeProjectsTest(AbstractPillarTest):
|
|||||||
self.assertEqual(True, proj_coll.find_one({'_id': ObjectId(home_b['_id'])})['_deleted'])
|
self.assertEqual(True, proj_coll.find_one({'_id': ObjectId(home_b['_id'])})['_deleted'])
|
||||||
|
|
||||||
|
|
||||||
|
class UpgradeAttachmentSchemaTest(AbstractPillarTest):
|
||||||
|
def test_blog_post(self):
|
||||||
|
from pillar.api.node_types import PILLAR_NAMED_NODE_TYPES
|
||||||
|
from pillar.cli.maintenance import upgrade_attachment_schema
|
||||||
|
|
||||||
|
old_blog_post_nt = {
|
||||||
|
"name": "post",
|
||||||
|
"description": "A blog post, for any project",
|
||||||
|
"dyn_schema": {
|
||||||
|
"content": {
|
||||||
|
"type": "string",
|
||||||
|
"minlength": 5,
|
||||||
|
"maxlength": 90000,
|
||||||
|
"required": True
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"allowed": ["published", "pending"],
|
||||||
|
"default": "pending"
|
||||||
|
},
|
||||||
|
"category": {"type": "string"},
|
||||||
|
"url": {"type": "string"},
|
||||||
|
"attachments": {
|
||||||
|
"type": "dict",
|
||||||
|
"propertyschema": {"type": "string", "regex": "^[a-zA-Z0-9_ ]+$"},
|
||||||
|
"valueschema": {
|
||||||
|
"type": "dict",
|
||||||
|
"schema": {
|
||||||
|
"oid": {"type": "objectid", "required": True},
|
||||||
|
"link": {
|
||||||
|
"type": "string",
|
||||||
|
"allowed": ["self", "none", "custom"],
|
||||||
|
"default": "self"
|
||||||
|
},
|
||||||
|
"link_custom": {"type": "string"},
|
||||||
|
"collection": {
|
||||||
|
"type": "string",
|
||||||
|
"allowed": ["files"],
|
||||||
|
"default": "files"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"form_schema": {},
|
||||||
|
"parent": ["blog"]
|
||||||
|
}
|
||||||
|
|
||||||
|
pid, project = self.ensure_project_exists(
|
||||||
|
project_overrides={
|
||||||
|
'picture_header': None,
|
||||||
|
'picture_square': None,
|
||||||
|
'node_types': [
|
||||||
|
PILLAR_NAMED_NODE_TYPES['group_texture'],
|
||||||
|
PILLAR_NAMED_NODE_TYPES['group'],
|
||||||
|
PILLAR_NAMED_NODE_TYPES['asset'],
|
||||||
|
PILLAR_NAMED_NODE_TYPES['storage'],
|
||||||
|
PILLAR_NAMED_NODE_TYPES['comment'],
|
||||||
|
PILLAR_NAMED_NODE_TYPES['blog'],
|
||||||
|
old_blog_post_nt,
|
||||||
|
]})
|
||||||
|
|
||||||
|
with self.app.app_context():
|
||||||
|
upgrade_attachment_schema(proj_url=project['url'], go=True)
|
||||||
|
|
||||||
|
db_proj = self.app.db('projects').find_one({'_id': pid})
|
||||||
|
db_node_type = db_proj['node_types'][-1]
|
||||||
|
self.assertEqual('post', db_node_type['name'])
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
PILLAR_NAMED_NODE_TYPES['post']['dyn_schema'],
|
||||||
|
db_node_type['dyn_schema'])
|
||||||
|
self.assertEqual({}, db_node_type['form_schema'])
|
||||||
|
|
||||||
|
|
||||||
class UpgradeAttachmentUsageTest(AbstractPillarTest):
|
class UpgradeAttachmentUsageTest(AbstractPillarTest):
|
||||||
def setUp(self, **kwargs):
|
def setUp(self, **kwargs):
|
||||||
super().setUp(**kwargs)
|
super().setUp(**kwargs)
|
||||||
|
Reference in New Issue
Block a user