summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-09-12 09:43:42 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-09-12 09:43:42 +0100
commit8585a0ce21d87314d4ce762cd4e6cfe1d0b612c1 (patch)
tree95c2104416b82653e7adc59527f55058739b0544 /pykolab
parent4b173df3d98e90e79abe471970777bcaa7ea0457 (diff)
downloadpykolab-8585a0ce21d87314d4ce762cd4e6cfe1d0b612c1.tar.gz
Add function user_quota()
Call function user_quota() on changes add, delete and none for user entries
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/auth/ldap/__init__.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index d98dfa9..6144e5f 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -704,6 +704,72 @@ class LDAP(pykolab.base.Base):
callback=self._synchronize_callback,
)
+ def user_quota(self, entry_id, folder):
+ default_quota = self.config_get('default_quota')
+ quota_attribute = self.config_get('quota_attribute')
+
+ if quota_attribute == None:
+ return
+
+ if default_quota == None:
+ return
+
+ self._bind()
+
+ entry_dn = self.entry_dn(entry_id)
+
+ current_ldap_quota = self.get_entry_attribute(entry_dn, quota_attribute)
+ _imap_quota = self.imap.get_quota(folder)
+
+ if _imap_quota == None:
+ used = None
+ current_imap_quota = None
+ else:
+ (used, current_imap_quota) = _imap_quota
+
+ log.debug(
+ _("About to consider the user quota for %r (used: %r, " + \
+ "imap: %r, ldap: %r, default: %r") % (
+ entry_dn,
+ used,
+ current_imap_quota,
+ current_ldap_quota,
+ default_quota
+ ),
+ level=9
+ )
+
+ new_quota = conf.plugins.exec_hook("set_user_folder_quota", kw={
+ 'used': used,
+ 'imap_quota': current_imap_quota,
+ 'ldap_quota': current_ldap_quota,
+ 'default_quota': default_quota
+ }
+ )
+
+ if not current_ldap_quota == None:
+ if not new_quota == (int)(current_ldap_quota):
+ self.set_entry_attribute(
+ entry_dn,
+ quota_attribute,
+ "%s" % (new_quota)
+ )
+ else:
+ if not new_quota == None:
+ self.set_entry_attribute(
+ entry_dn,
+ quota_attribute,
+ "%s" % (new_quota)
+ )
+
+ if not current_imap_quota == None:
+ if not new_quota == current_imap_quota:
+ self.imap.set_quota(folder, new_quota)
+
+ else:
+ if not new_quota == None:
+ self.imap.set_quota(folder, new_quota)
+
###
### API depth level increasing!
###
@@ -771,6 +837,8 @@ class LDAP(pykolab.base.Base):
if not entry[mailserver_attribute] == server:
self.set_entry_attribute(entry, mailserver_attribute, server)
+ self.user_quota(entry, folder)
+
def _change_add_group(self, entry, change):
"""
An entry of type group was added.
@@ -996,6 +1064,8 @@ class LDAP(pykolab.base.Base):
self.imap.user_mailbox_rename(old_canon_attr, entry_changes[result_attribute])
conf.changelog[entry['id']] = entry_changes[result_attribute]
+ self.user_quota(entry, "user%s%s" % (self.imap.separator,entry[result_attribute]))
+
def _change_none_group(self, entry, change):
"""
A group entry as part of the initial search result set.
@@ -1089,6 +1159,15 @@ class LDAP(pykolab.base.Base):
if not self.imap.user_mailbox_exists(entry[result_attribute]):
folder = self.imap.user_mailbox_create(entry[result_attribute])
server = self.imap.user_mailbox_server(folder)
+ else:
+ folder = "user%s%s" % (
+ self.imap.separator,
+ entry[result_attribute]
+ )
+
+ server = self.imap.user_mailbox_server(folder)
+
+ self.user_quota(entry, folder)
else:
log.warning(