Skip to content

Commit dd11bf0

Browse files
committed
add tests for _unsafe_metadata
1 parent 6c23c61 commit dd11bf0

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

plone/app/content/browser/vocabulary.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
MAX_BATCH_SIZE = 500 # prevent overloading server
3232

3333
DEFAULT_PERMISSION = 'View'
34+
DEFAULT_PERMISSION_SECURE = 'Modify portal content'
3435
PERMISSIONS = {
3536
'plone.app.vocabularies.Catalog': 'View',
3637
'plone.app.vocabularies.Keywords': 'Modify portal content',
@@ -193,7 +194,7 @@ def __call__(self):
193194
if attributes:
194195
base_path = getNavigationRoot(context)
195196
sm = getSecurityManager()
196-
can_edit = sm.checkPermission('Modify portal content', context)
197+
can_edit = sm.checkPermission(DEFAULT_PERMISSION_SECURE, context)
197198
for vocab_item in results:
198199
if not results_are_brains:
199200
vocab_item = vocab_item.value

plone/app/content/tests/test_widgets.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,69 @@ def testVocabularyCatalogResults(self):
146146
})
147147
data = json.loads(view())
148148
self.assertEquals(len(data['results']), 1)
149-
self.portal.manage_delObjects(['page'])
149+
150+
def testVocabularyCatalogUnsafeMetadataAllowed(self):
151+
"""Users with permission "Modify portal content" are allowed to see
152+
``_unsafe_metadata``.
153+
"""
154+
self.portal.invokeFactory('Document', id="page", title="page")
155+
self.portal.page.reindexObject()
156+
view = VocabularyView(self.portal, self.request)
157+
query = {
158+
'criteria': [
159+
{
160+
'i': 'path',
161+
'o': 'plone.app.querystring.operation.string.path',
162+
'v': '/plone/page'
163+
}
164+
]
165+
}
166+
self.request.form.update({
167+
'name': 'plone.app.vocabularies.Catalog',
168+
'query': json.dumps(query),
169+
'attributes': [
170+
'id',
171+
'commentors',
172+
'Creator',
173+
'listCreators',
174+
]
175+
})
176+
data = json.loads(view())
177+
self.assertEquals(len(data['results'][0].keys()), 4)
178+
179+
def testVocabularyCatalogUnsafeMetadataDisallowed(self):
180+
"""Users without permission "Modify portal content" are not allowed to
181+
see ``_unsafe_metadata``.
182+
"""
183+
self.portal.invokeFactory('Document', id="page", title="page")
184+
self.portal.page.reindexObject()
185+
# Downgrade permissions
186+
setRoles(self.portal, TEST_USER_ID, [])
187+
view = VocabularyView(self.portal, self.request)
188+
query = {
189+
'criteria': [
190+
{
191+
'i': 'path',
192+
'o': 'plone.app.querystring.operation.string.path',
193+
'v': '/plone/page'
194+
}
195+
]
196+
}
197+
self.request.form.update({
198+
'name': 'plone.app.vocabularies.Catalog',
199+
'query': json.dumps(query),
200+
'attributes': [
201+
'id',
202+
'commentors',
203+
'Creator',
204+
'listCreators',
205+
]
206+
})
207+
data = json.loads(view())
208+
# Only one result key should be returned, as ``commentors``,
209+
# ``Creator`` and ``listCreators`` is considered unsafe and thus
210+
# skipped.
211+
self.assertEquals(len(data['results'][0].keys()), 1)
150212

151213
def testVocabularyBatching(self):
152214
amount = 30

0 commit comments

Comments
 (0)