You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.8 KiB

  1. # maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
  2. # Copyright (C) 2020 Tulir Asokan
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. from typing import NamedTuple
  17. from mautrix.util.config import BaseFileConfig, ConfigUpdateHelper
  18. from mautrix.types import UserID
  19. from mautrix.client import Client
  20. class Permissions(NamedTuple):
  21. access: bool = False
  22. create_packs: bool = False
  23. telegram_import: bool = False
  24. class Config(BaseFileConfig):
  25. def do_update(self, helper: ConfigUpdateHelper) -> None:
  26. copy = helper.copy
  27. copy("database")
  28. copy("server.host")
  29. copy("server.port")
  30. copy("server.public_url")
  31. copy("server.override_resource_path")
  32. copy("server.trust_forward_headers")
  33. copy("telegram_import.bot_token")
  34. copy("telegram_import.homeserver.address")
  35. copy("telegram_import.homeserver.access_token")
  36. copy("permissions")
  37. copy("logging")
  38. def get_permissions(self, mxid: UserID) -> Permissions:
  39. _, homeserver = Client.parse_user_id(mxid)
  40. return Permissions(**{
  41. **self["permissions"].get("*", {}),
  42. **self["permissions"].get(homeserver, {}),
  43. **self["permissions"].get(mxid, {}),
  44. })