Changeset View
Changeset View
Standalone View
Standalone View
pykolab/imap/__init__.py
Show First 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | def set_acl(self, folder, identifier, acl): | ||||
if char == '+': | if char == '+': | ||||
mode = 'add' | mode = 'add' | ||||
continue | continue | ||||
acl_map[mode] += char | acl_map[mode] += char | ||||
current_acls = self.imap.lam(self.folder_utf7(folder)) | current_acls = self.imap.lam(self.folder_utf7(folder)) | ||||
for current_acl in current_acls.keys(): | for current_acl in current_acls.keys(): | ||||
if current_acl == identifier: | if current_acl == identifier.lower(): | ||||
machniak: I would move lowercasing before `for`, so it's not done on every iteration. | |||||
_acl = current_acls[current_acl] | _acl = current_acls[current_acl] | ||||
break | break | ||||
_acl = _acl + acl_map['set'] + acl_map['add'] | _acl = _acl + acl_map['set'] + acl_map['add'] | ||||
_acl = [x for x in _acl.split() if x not in acl_map['subtract'].split()] | _acl = [x for x in _acl.split() if x not in acl_map['subtract'].split()] | ||||
acl = ''.join(list(set(_acl))) | acl = ''.join(list(set(_acl))) | ||||
try: | try: | ||||
self.imap.sam(self.folder_utf7(folder), identifier, acl) | _folder = self.folder_utf7(folder) | ||||
log.debug( | |||||
_("IMAP SAM command with calculated ACL rights %s for %s on folder %s") % \ | |||||
(acl, identifier, _folder), level=8 | |||||
) | |||||
self.imap.sam(_folder, identifier, acl) | |||||
except Exception as errmsg: | except Exception as errmsg: | ||||
log.error( | log.error( | ||||
_("Could not set ACL for %s on folder %s: %r") % ( | _("Could not set ACL for %s on folder %s: %r") % ( | ||||
identifier, | identifier, | ||||
folder, | _folder, | ||||
machniakUnsubmitted Not Done Inline ActionsI would move _folder initialization before try. Otherwise if that fails _folder might be unset. Probably not very likely scenario, but still. machniak: I would move `_folder` initialization before `try`. Otherwise if that fails `_folder` might be… | |||||
errmsg | errmsg | ||||
) | ) | ||||
) | ) | ||||
def set_metadata(self, folder, metadata_path, metadata_value, shared=True): | def set_metadata(self, folder, metadata_path, metadata_value, shared=True): | ||||
""" | """ | ||||
Set a metadata entry on a folder | Set a metadata entry on a folder | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 452 Lines • ▼ Show 20 Lines | def _set_socket_keepalive(self, sock): | ||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, (int)(f.read())) | sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, (int)(f.read())) | ||||
def _set_kolab_mailfolder_acls(self, acls, folder=None, update=False): | def _set_kolab_mailfolder_acls(self, acls, folder=None, update=False): | ||||
# special case, folder has no ACLs assigned and update was requested, | # special case, folder has no ACLs assigned and update was requested, | ||||
# remove all existing ACL entries | # remove all existing ACL entries | ||||
if update is True and isinstance(acls, list) and len(acls) == 0: | if update is True and isinstance(acls, list) and len(acls) == 0: | ||||
acls = self.list_acls(folder) | acls = self.list_acls(folder) | ||||
for subject in acls: | for subject in acls: | ||||
subject = subject.lower() | |||||
machniakUnsubmitted Not Done Inline ActionsSomething's wrong with indentation here. machniak: Something's wrong with indentation here. | |||||
log.debug( | log.debug( | ||||
_("Removing ACL rights %s for subject %s on folder " + \ | _("Special case: Update with ACLs %s " + \ | ||||
"%s") % (acls[subject], subject, folder), level=8) | "for subject %s on folder %s") % \ | ||||
(acls[subject], subject, folder), level=6) | |||||
self.set_acl(folder, subject, '') | self.set_acl(folder, subject, '') | ||||
return | return | ||||
if isinstance(acls, basestring): | if isinstance(acls, basestring): | ||||
acls = [ acls ] | acls = [ acls ] | ||||
old_acls = None | old_acls = None | ||||
for acl in acls: | for acl in acls: | ||||
exec("acl = %s" % (acl)) | exec("acl = %s" % (acl)) | ||||
subject = acl[0] | subject = acl[0].lower() | ||||
rights = acl[1] | rights = acl[1] | ||||
if len(acl) == 3: | if len(acl) == 3: | ||||
epoch = acl[2] | epoch = acl[2] | ||||
else: | else: | ||||
epoch = (int)(time.time()) + 3600 | epoch = (int)(time.time()) + 3600 | ||||
# update mode, check existing entries | # update mode, check existing entries | ||||
if update is True: | if update is True: | ||||
if old_acls is None: | if old_acls is None: | ||||
old_acls = self.list_acls(folder) | old_acls = self.list_acls(folder) | ||||
for old_subject in old_acls: | # Removing, does not make sense | ||||
old_acls[old_subject] = old_acls[old_subject] | # for old_subject in old_acls: | ||||
# old_acls[old_subject] = old_acls[old_subject] | |||||
if subject in old_acls: | if subject in old_acls: | ||||
old_acls[subject] = None | old_acls[subject] = None | ||||
if epoch > (int)(time.time()): | if epoch > (int)(time.time()): | ||||
log.debug( | log.debug( | ||||
_("Setting ACL rights %s for subject %s on folder " + \ | _("Setting ACL rights %s for subject %s on folder " + \ | ||||
"%s") % (rights, subject, folder), level=8) | "%s") % (rights, subject, folder), level=6) | ||||
self.set_acl( | self.set_acl( | ||||
folder, | folder, | ||||
"%s" % (subject), | "%s" % (subject), | ||||
"%s" % (rights) | "%s" % (rights) | ||||
) | ) | ||||
else: | else: | ||||
log.debug( | log.debug( | ||||
_("Removing ACL rights %s for subject %s on folder " + \ | _("Removing %s ACL rights for subject %s on folder " + \ | ||||
"%s") % (rights, subject, folder), level=8) | "%s") % (rights, subject, folder), level=6) | ||||
self.set_acl( | self.set_acl( | ||||
folder, | folder, | ||||
"%s" % (subject), | "%s" % (subject), | ||||
"" | "" | ||||
) | ) | ||||
# update mode, unset removed ACL entries | # update mode, unset removed ACL entries | ||||
if old_acls is not None: | if old_acls is not None: | ||||
for subject in old_acls: | for subject in old_acls: | ||||
if old_acls[subject] is not None: | if old_acls[subject] is not None: | ||||
log.debug( | log.debug( | ||||
_("Removing ACL rights %s for subject %s on folder " + \ | _("Update mode: Unset %s ACLs for subject %s on folder " + \ | ||||
"%s") % (old_acls[subject], subject, folder), level=8) | "%s") % (old_acls[subject], subject, folder), level=6) | ||||
self.set_acl(folder, subject, '') | self.set_acl(folder, subject, '') | ||||
pass | pass | ||||
""" Blah functions """ | """ Blah functions """ | ||||
def move_user_folders(self, users=[], domain=None): | def move_user_folders(self, users=[], domain=None): | ||||
for user in users: | for user in users: | ||||
▲ Show 20 Lines • Show All 292 Lines • Show Last 20 Lines |
I would move lowercasing before for, so it's not done on every iteration.