__init__.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. #
  3. # This file is part of Radicale Server - Calendar Server
  4. # Copyright © 2008-2012 Guillaume Ayoub
  5. # Copyright © 2008 Nicolas Kandel
  6. # Copyright © 2008 Pascal Halter
  7. #
  8. # This library is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This library is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  20. """
  21. Users and rights management.
  22. This module loads a list of users with access rights, according to the acl
  23. configuration.
  24. """
  25. from radicale import config, log
  26. AUTHORIZATION_PREFIX = "authorization"
  27. PUBLIC_USERS = []
  28. PRIVATE_USERS = []
  29. def _config_users(name):
  30. """Get an iterable of strings from the configuraton string [acl] ``name``.
  31. The values must be separated by a comma. The whitespace characters are
  32. stripped at the beginning and at the end of the values.
  33. """
  34. for user in config.get(AUTHORIZATION_PREFIX, name).split(","):
  35. user = user.strip()
  36. yield None if user == "None" else user
  37. def load():
  38. """Load list of available ACL managers."""
  39. PUBLIC_USERS.extend(_config_users("public_users"))
  40. PRIVATE_USERS.extend(_config_users("private_users"))
  41. authorization_type = config.get(AUTHORIZATION_PREFIX, "type")
  42. log.LOGGER.debug("auth type = " + authorization_type)
  43. if authorization_type == "None":
  44. return None
  45. else:
  46. module = __import__("authorization.%s" % authorization_type, globals=globals(), level=2)
  47. return getattr(module, authorization_type)
  48. def may_read(user, collection):
  49. if (collection.owner not in PRIVATE_USERS and user != collection.owner):
  50. # owner is not private and is not user, forbidden
  51. return False
  52. return read_authorized(user, collection)
  53. def may_write(user, collection):
  54. return write_authorized(user, collection)