kopano-archiver-aclsync 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. import logging
  3. import sys
  4. import kopano
  5. """
  6. synchronize permissions to archive stores
  7. """
  8. ROLE_REVIEWER = ['folder_visible', 'read_items']
  9. def logger(options):
  10. logging.basicConfig(stream=sys.stdout, level=options.loglevel)
  11. return logging.getLogger('aclset')
  12. def main():
  13. parser = kopano.parser('spkul')
  14. options, args = parser.parse_args()
  15. log = logger(options)
  16. stats = {'users': 0, 'errors': 0}
  17. server = kopano.Server(options=options)
  18. for user in server.users():
  19. with kopano.log_exc(log, stats):
  20. log.info('processing user %s', user.name)
  21. stats['users'] += 1
  22. archive_store, archive_folder = user.archive_store, user.archive_folder
  23. if archive_store:
  24. log.debug('syncing permissions')
  25. # for the user store, copy rights (masked to ROLE_REVIEWER)
  26. for p in user.store.permissions():
  27. rights = [r for r in p.rights if r in ROLE_REVIEWER]
  28. archive_folder.permission(p.member, create=True).rights = rights
  29. archive_folder.permission(kopano.Group('Everyone'), create=True).rights = []
  30. # if archiving to subfolder, copy store rights to subtree, adding 'folder_visible'
  31. if archive_folder is not archive_store.subtree:
  32. for p in user.store.permissions():
  33. pa = archive_store.subtree.permission(p.member, create=True)
  34. pa.rights = [r for r in pa.rights if r != 'folder_visible'] + ['folder_visible']
  35. # for each folder, copy rights (masked to ROLE_REVIEWER)
  36. for folder in user.folders():
  37. archive_folder = folder.archive_folder
  38. if archive_folder:
  39. for p in folder.permissions():
  40. rights = [r for r in p.rights if r in ROLE_REVIEWER]
  41. archive_folder.permission(p.member, create=True).rights = rights
  42. else:
  43. log.debug('user has no archive store')
  44. if __name__ == '__main__':
  45. main()