summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-03-19 19:46:34 -0400
committerThomas Bruederli <bruederli@kolabsys.com>2014-03-19 19:46:34 -0400
commit3d3b77f78c11151e174184335dfc1c6bd05bfa29 (patch)
treef9b6cbd6f3543d39eb6ef0d64353be640af1fc12
parent53e46b7870e48d0a76a997737d4c7df53dee3bd8 (diff)
downloadpykolab-3d3b77f78c11151e174184335dfc1c6bd05bfa29.tar.gz
Get resource owner information from parent collection if not set directly
-rw-r--r--tests/functional/test_wallace/test_005_resource_invitation.py12
-rw-r--r--tests/unit/test-011-wallace_resources.py10
-rw-r--r--wallace/module_resources.py30
3 files changed, 44 insertions, 8 deletions
diff --git a/tests/functional/test_wallace/test_005_resource_invitation.py b/tests/functional/test_wallace/test_005_resource_invitation.py
index 8a1d844..aad5fd5 100644
--- a/tests/functional/test_wallace/test_005_resource_invitation.py
+++ b/tests/functional/test_wallace/test_005_resource_invitation.py
@@ -550,6 +550,18 @@ class TestResourceInvitation(unittest.TestCase):
self.assertIn(self.jane['displayname'], respose_text)
+ def test_011_owner_info_from_collection(self):
+ self.purge_mailbox(self.john['mailbox'])
+
+ self.send_itip_invitation(self.room2['mail'], datetime.datetime(2014,6,19, 16,0,0))
+
+ accept = self.check_message_received("Reservation Request for test was ACCEPTED", self.room2['mail'])
+ self.assertIsInstance(accept, email.message.Message)
+ respose_text = str(accept.get_payload(0))
+ self.assertIn(self.jane['mail'], respose_text)
+ self.assertIn(self.jane['displayname'], respose_text)
+
+
def TODO_test_012_owner_notification(self):
self.purge_mailbox(self.john['mailbox'])
self.purge_mailbox(self.jane['mailbox'])
diff --git a/tests/unit/test-011-wallace_resources.py b/tests/unit/test-011-wallace_resources.py
index 8b01874..62bfd27 100644
--- a/tests/unit/test-011-wallace_resources.py
+++ b/tests/unit/test-011-wallace_resources.py
@@ -247,6 +247,7 @@ class TestWallaceResources(unittest.TestCase):
self.patch(pykolab.auth.Auth, "disconnect", self._mock_nop)
self.patch(pykolab.auth.Auth, "find_resource", self._mock_find_resource)
self.patch(pykolab.auth.Auth, "get_entry_attributes", self._mock_get_entry_attributes)
+ self.patch(pykolab.auth.Auth, "search_entry_by_attribute", self._mock_search_entry_by_attribute)
# intercept calls to smtplib.SMTP.sendmail()
import smtplib
@@ -268,6 +269,12 @@ class TestWallaceResources(unittest.TestCase):
(_, uid) = entry.split(',')[0].split('=')
return { 'cn': uid, 'mail': uid + "@example.org", '_attrib': attributes }
+ def _mock_search_entry_by_attribute(self, attr, value, **kw):
+ results = []
+ if value == "cn=Room 101,ou=Resources,dc=example,dc=org":
+ results.append({ 'dn': 'cn=Rooms,ou=Resources,dc=example,dc=org', attr: value, 'owner': 'uid=doe,ou=People,dc=example,dc=org' })
+ return results
+
def _mock_smtp_init(self, host=None, port=None, local_hostname=None, timeout=0):
pass
@@ -353,6 +360,9 @@ class TestWallaceResources(unittest.TestCase):
owner3 = module_resources.get_resource_owner({ 'dn': "uid=cars,ou=Resources,cd=example,dc=org" })
self.assertEqual(owner3, None)
+ owner4 = module_resources.get_resource_owner({ 'dn': "cn=Room 101,ou=Resources,dc=example,dc=org" })
+ self.assertEqual("doe@example.org", owner4['mail'])
+
def test_005_send_response_accept(self):
itip_event = module_resources.itip_events_from_message(message_from_string(itip_non_multipart))
diff --git a/wallace/module_resources.py b/wallace/module_resources.py
index d861614..ede976e 100644
--- a/wallace/module_resources.py
+++ b/wallace/module_resources.py
@@ -221,6 +221,7 @@ def execute(*args, **kw):
# If it is, expand to individual resources
# If it is not, ...
resource_attrs = auth.get_entry_attributes(None, resource_dn, ['*'])
+ resource_attrs['dn'] = resource_dn
if not 'kolabsharedfolder' in [x.lower() for x in resource_attrs['objectclass']]:
if resource_attrs.has_key('uniquemember'):
resources[resource_dn] = resource_attrs
@@ -232,6 +233,7 @@ def execute(*args, **kw):
)
if 'kolabsharedfolder' in [x.lower() for x in resource_attrs['objectclass']]:
+ resource_attrs['dn'] = uniquemember
resources[uniquemember] = resource_attrs
resources[uniquemember]['memberof'] = resource_dn
if not resource_attrs.has_key('owner') and resources[resource_dn].has_key('owner'):
@@ -872,18 +874,30 @@ def get_resource_owner(resource):
auth = Auth()
auth.connect()
+ owners = []
+
if resource.has_key('owner'):
if not isinstance(resource['owner'], list):
- resource['owner'] = [ resource['owner'] ]
-
- for dn in resource['owner']:
- owner = auth.get_entry_attributes(None, dn, ['cn','mail','telephoneNumber'])
- if owner is not None:
- return owner
+ owners = [ resource['owner'] ]
+ else:
+ owners = resource['owner']
else:
- # TODO: get owner attribute from collection
- pass
+ # get owner attribute from collection
+ collections = auth.search_entry_by_attribute('uniquemember', resource['dn'])
+ if not isinstance(collections, list):
+ collections = [ collections ]
+
+ for dn,collection in collections:
+ if collection.has_key('owner') and isinstance(collection['owner'], list):
+ owners += collection['owner']
+ elif collection.has_key('owner'):
+ owners.append(collection['owner'])
+
+ for dn in owners:
+ owner = auth.get_entry_attributes(None, dn, ['cn','mail','telephoneNumber'])
+ if owner is not None:
+ return owner
return None