__init__.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2012-2017 Guillaume Ayoub
  3. # Copyright © 2017-2018 Unrud <unrud@outlook.com>
  4. #
  5. # This library is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  17. """
  18. The rights module used to determine if a user can read and/or write
  19. collections and entries.
  20. Permissions:
  21. - R: read a collection (excluding address book or calendar collections)
  22. - r: read an address book or calendar collection
  23. - W: write a collection (excluding address book or calendar collections)
  24. - w: write an address book or calendar collection
  25. Take a look at the class ``BaseRights`` if you want to implement your own.
  26. """
  27. from radicale import utils
  28. INTERNAL_TYPES = ("authenticated", "owner_write", "owner_only", "from_file")
  29. def load(configuration):
  30. """Load the rights module chosen in configuration."""
  31. return utils.load_plugin(INTERNAL_TYPES, "rights", "Rights", configuration)
  32. def intersect(a, b):
  33. """Intersect two lists of rights.
  34. Returns all rights that are both in ``a`` and ``b``.
  35. """
  36. return "".join(set(a).intersection(set(b)))
  37. class BaseRights:
  38. def __init__(self, configuration):
  39. """Initialize BaseRights.
  40. ``configuration`` see ``radicale.config`` module.
  41. The ``configuration`` must not change during the lifetime of
  42. this object, it is kept as an internal reference.
  43. """
  44. self.configuration = configuration
  45. def authorization(self, user, path):
  46. """Get granted rights of ``user`` for the collection ``path``.
  47. If ``user`` is empty, check for anonymous rights.
  48. ``path`` is sanitized.
  49. Returns granted rights (e.g. ``"RW"``).
  50. """
  51. raise NotImplementedError