Skip to content

Commit

Permalink
Merge pull request #6 from IMIO/PM-1008_remove_field_useGroupsAsCateg…
Browse files Browse the repository at this point in the history
…ories

Adapted code regarding removal of `MeetingConfig.useGroupsAsCategories`.
  • Loading branch information
gbastien committed Feb 24, 2023
2 parents 9e3aeac + adf6c5b commit 188650b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Changelog
- Completed `test_ws_meetingAcceptingItems` to check that it works when using
`inTheNameOf` (was actually not working before `Products.PloneMeeting==4.2rc30`).
[gbastien]
- Adapted code regarding removal of `MeetingConfig.useGroupsAsCategories`.
[gbastien]

3.6 (2022-03-10)
----------------
Expand Down
47 changes: 21 additions & 26 deletions src/imio/pm/ws/soap/soapview.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,16 @@ def _getConfigInfos(self, showCategories=False, userToShowCategoriesFor=None):

# MeetingConfigs
config_infos = []
for config in tool.getActiveConfigs():
for cfg in tool.getActiveConfigs():
configInfo = ConfigInfo()
configInfo._UID = config.UID()
configInfo._id = config.getId()
configInfo._title = config.Title()
configInfo._description = config.Description()
configInfo._itemPositiveDecidedStates = config.getItemPositiveDecidedStates()
configInfo._UID = cfg.UID()
configInfo._id = cfg.getId()
configInfo._title = cfg.Title()
configInfo._description = cfg.Description()
configInfo._itemPositiveDecidedStates = cfg.getItemPositiveDecidedStates()
# only return categories if the meetingConfig uses it
if showCategories and not config.getUseGroupsAsCategories():
for category in config.getCategories(userId=userToShowCategoriesFor):
if showCategories and 'category' in cfg.getUsedItemAttributes():
for category in cfg.getCategories(userId=userToShowCategoriesFor):
basicInfo = BasicInfo()
basicInfo._UID = category.UID()
basicInfo._id = category.getId()
Expand Down Expand Up @@ -775,11 +775,11 @@ def _createItem(self,

# raise if we pass an optional attribute that is not activated in this MeetingConfig
optionalItemFields = cfg.listUsedItemAttributes()
activatedOptionalItemFields = cfg.getUsedItemAttributes()
usedItemAttrs = cfg.getUsedItemAttributes()
for field in data:
# if the field is an optional field that is not used and that has a value (contains data), we raise
if field in optionalItemFields and \
field not in activatedOptionalItemFields and \
field not in usedItemAttrs and \
data[field]:
raiseMsg("The optional field \"%s\" is not activated in this configuration!" % field)

Expand Down Expand Up @@ -901,22 +901,17 @@ def _createItem(self,
warnWrongHTML = True
data[htmlFieldId] = renderedSoupContents

# check that if category is mandatory (getUseGroupsAsCategories is False), it is given
# and that given category is available
# if we are not using categories, just ensure that we received an empty category
availableCategories = not cfg.getUseGroupsAsCategories() and \
[cat.getId() for cat in cfg.getCategories()] or ['', ]
if not data['category'] in availableCategories:
# special message if category mandatory and not given
if not cfg.getUseGroupsAsCategories() and not data['category']:
raiseMsg("In this config, category is mandatory!")
elif cfg.getUseGroupsAsCategories() and data['category']:
raiseMsg("This config does not use categories, the given '%s' "
"category can not be used!" % data['category'])
# we are using categories but the given one is not in availableCategories
elif not cfg.getUseGroupsAsCategories():
raiseMsg("'%s' is not available for the '%s' group!" % (
data['category'], proposingGroupId))
# check that if category is mandatory, it is given and that given category is available
if 'category' in usedItemAttrs:
availableCategories = [cat.getId() for cat in cfg.getCategories()] or ['', ]
if data['category'] not in availableCategories:
# special message if category used not given
if not data['category']:
raiseMsg("In this config, category is mandatory!")
# we are using categories but the given one is not in availableCategories
else:
raiseMsg("'%s' is not available for the '%s' group!" % (
data['category'], proposingGroupId))

# we create the item to be able to check the category here above...
itemId = destFolder.invokeFactory(type_name, **data)
Expand Down
8 changes: 4 additions & 4 deletions src/imio/pm/ws/tests/WS4PMTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ def setUp(self):
self.meetingConfig.setUsedItemAttributes(itemAttrs + ('detailedDescription', ))
itemAttrs = self.meetingConfig2.getUsedItemAttributes()
self.meetingConfig2.setUsedItemAttributes(itemAttrs + ('detailedDescription', ))
# use the 'plonegov-assembly' MeetingConfig that use real categories,
# not useGroupsAsCategories, even if it could be changed during a test
# use the 'plonegov-assembly' MeetingConfig that use category
self.meetingConfig = self.meetingConfig2
self.usedMeetingConfigId = 'plonegov-assembly'

def _prepareCreationData(self):
def _prepareCreationData(self, with_category=True):
"""
Helper method for creating an item using the SOAP method createItem
"""
Expand All @@ -52,7 +51,8 @@ def _prepareCreationData(self):
req._proposingGroupId = 'developers'
CreationData = GTD('http://ws4pm.imio.be', 'CreationData')('').pyclass()
CreationData._title = 'My new item title'
CreationData._category = 'development'
if with_category:
CreationData._category = 'development'
CreationData._description = '<p>Description</p>'
CreationData._detailedDescription = '<p>Detailed description</p>'
CreationData._decision = '<p>Décision</p>'
Expand Down
25 changes: 12 additions & 13 deletions src/imio/pm/ws/tests/test_createitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_ws_createItemRaisedZSIFaults(self):
"""
# by default no item exists
self.changeUser('pmCreator1')
req = self._prepareCreationData()
req = self._prepareCreationData(with_category=False)
responseHolder = createItemResponse()
# the title is mandatory
req._creationData._title = None
Expand All @@ -129,21 +129,20 @@ def test_ws_createItemRaisedZSIFaults(self):
# set back correct proposingGroup
req._proposingGroupId = 'developers'
# if category is mandatory and empty, it raises ZSI.Fault
self.meetingConfig.setUseGroupsAsCategories(False)
self._enableField('category')
req._creationData._category = None
with self.assertRaises(ZSI.Fault) as cm:
SOAPView(self.portal, req).createItemRequest(req, responseHolder)
self.assertEqual(cm.exception.string, "In this config, category is mandatory!")
# wrong category and useGroupsAsCategories, ZSI.Fault
self.meetingConfig.setUseGroupsAsCategories(True)
# wrong category and category not used, ZSI.Fault
self._enableField('category', enable=False)
req._creationData._category = 'wrong-category-id'
with self.assertRaises(ZSI.Fault) as cm:
SOAPView(self.portal, req).createItemRequest(req, responseHolder)
self.assertEqual(cm.exception.string,
"This config does not use categories, the given 'wrong-category-id' "
"category can not be used!")
# wrong category and actually accepting categories, aka useGroupsAsCategories to False
self.meetingConfig.setUseGroupsAsCategories(False)
'The optional field "category" is not activated in this configuration!')
# wrong category and using category
self._enableField('category')
with self.assertRaises(ZSI.Fault) as cm:
SOAPView(self.portal, req).createItemRequest(req, responseHolder)
self.assertEqual(cm.exception.string,
Expand Down Expand Up @@ -190,7 +189,7 @@ def test_ws_createItemToDiscuss(self):
req = self._prepareCreationData()
responseHolder = createItemResponse()
# we can not use an optional field that is not activated in the current MeetingConfig
cfg.setUsedItemAttributes(('description', 'detailedDescription',))
cfg.setUsedItemAttributes(('category', 'description', 'detailedDescription',))
self.assertFalse('toDiscuss' in cfg.getUsedItemAttributes())
# set toDiscuss to True
req._creationData._toDiscuss = True
Expand Down Expand Up @@ -493,7 +492,7 @@ def test_ws_createItemInTheNameOf(self):
- the calling user must be 'Manager' or 'MeetingManager'
- the created item is finally like if created by the inTheNameOf user
"""
self.meetingConfig.setUseGroupsAsCategories(False)
self._enableField('category')
# check first a working example the degrades it...
# and every related informations (creator, ownership, ...) are corretly linked to inTheNameOf user
self.changeUser('pmManager')
Expand Down Expand Up @@ -653,7 +652,7 @@ def test_ws_createItemGroupsInCharge(self):
Test when passing groupsInCharge while creating the item.
"""
cfg = self.meetingConfig
cfg.setUsedItemAttributes(['description', 'detailedDescription'])
cfg.setUsedItemAttributes(['category', 'description', 'detailedDescription'])
# by default no item exists
self.changeUser('pmCreator1')
req = self._prepareCreationData()
Expand Down Expand Up @@ -686,7 +685,7 @@ def test_ws_createItemAssociatedGroups(self):
Test when passing associatedGroups while creating the item.
"""
cfg = self.meetingConfig
cfg.setUsedItemAttributes(['description', 'detailedDescription'])
cfg.setUsedItemAttributes(['category', 'description', 'detailedDescription'])
# by default no item exists
self.changeUser('pmCreator1')
req = self._prepareCreationData()
Expand Down Expand Up @@ -718,7 +717,7 @@ def test_ws_createItemOptionalAdvisers(self):
Test when passing associatedGroups while creating the item.
"""
cfg = self.meetingConfig
cfg.setUsedItemAttributes(['description', 'detailedDescription'])
cfg.setUsedItemAttributes(['category', 'description', 'detailedDescription'])

# by default no item exists
self.changeUser('pmCreator1')
Expand Down
2 changes: 1 addition & 1 deletion src/imio/pm/ws/tests/test_getconfiginfos.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _getResultCategoriesForConfig(self, config):
Helper method for generating result displayed about categories of a MeetingConfig
"""
# if not using categories, return empty categories list
if not config.meta_type == 'MeetingConfig' or config.getUseGroupsAsCategories():
if not config.meta_type == 'MeetingConfig' or 'category' not in config.getUsedItemAttributes():
return ''

result = ""
Expand Down
5 changes: 2 additions & 3 deletions src/imio/pm/ws/tests/test_searchitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ def test_ws_searchItemsRequest(self):
self.assertEqual(expected, resp)
# if the item is in a meeting, the result is a bit different because
# we have valid informations about the meeting_date
# use the 'plonegov-assembly' MeetingConfig that use real categories,
# not useGroupsAsCategories
# use the 'plonegov-assembly' MeetingConfig that use category
self.changeUser('pmManager')
meeting = self._createMeetingWithItems()
itemInMeeting = meeting.get_items(ordered=True)[0]
Expand Down Expand Up @@ -201,7 +200,7 @@ def test_ws_searchItemsRequest(self):
# create an item for 'plonemeeting-assembly' with same data as one created for 'plonegov-assembly' here above
req = self._prepareCreationData()
req._meetingConfigId = 'plonemeeting-assembly'
# in 'plonemeeting-assembly', the category is not used, useGroupsAsCategories is True
# in 'plonemeeting-assembly', the category is not used
req._creationData._category = ''
newItem, response = self._createItem(req)
pmItem = self.portal.portal_catalog(UID=response._UID)[0].getObject()
Expand Down

0 comments on commit 188650b

Please sign in to comment.