geovisio 2.5.0__py3-none-any.whl → 2.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. geovisio/__init__.py +38 -8
  2. geovisio/admin_cli/__init__.py +2 -2
  3. geovisio/admin_cli/db.py +8 -0
  4. geovisio/config_app.py +64 -0
  5. geovisio/db_migrations.py +24 -3
  6. geovisio/templates/main.html +14 -14
  7. geovisio/templates/viewer.html +3 -3
  8. geovisio/translations/de/LC_MESSAGES/messages.mo +0 -0
  9. geovisio/translations/de/LC_MESSAGES/messages.po +667 -0
  10. geovisio/translations/en/LC_MESSAGES/messages.mo +0 -0
  11. geovisio/translations/en/LC_MESSAGES/messages.po +730 -0
  12. geovisio/translations/es/LC_MESSAGES/messages.mo +0 -0
  13. geovisio/translations/es/LC_MESSAGES/messages.po +778 -0
  14. geovisio/translations/fi/LC_MESSAGES/messages.mo +0 -0
  15. geovisio/translations/fi/LC_MESSAGES/messages.po +589 -0
  16. geovisio/translations/fr/LC_MESSAGES/messages.mo +0 -0
  17. geovisio/translations/fr/LC_MESSAGES/messages.po +814 -0
  18. geovisio/translations/ko/LC_MESSAGES/messages.mo +0 -0
  19. geovisio/translations/ko/LC_MESSAGES/messages.po +685 -0
  20. geovisio/translations/messages.pot +686 -0
  21. geovisio/translations/nl/LC_MESSAGES/messages.mo +0 -0
  22. geovisio/translations/nl/LC_MESSAGES/messages.po +594 -0
  23. geovisio/utils/__init__.py +1 -1
  24. geovisio/utils/auth.py +50 -11
  25. geovisio/utils/db.py +65 -0
  26. geovisio/utils/excluded_areas.py +83 -0
  27. geovisio/utils/extent.py +30 -0
  28. geovisio/utils/fields.py +1 -1
  29. geovisio/utils/filesystems.py +0 -1
  30. geovisio/utils/link.py +14 -0
  31. geovisio/utils/params.py +20 -0
  32. geovisio/utils/pictures.py +94 -69
  33. geovisio/utils/reports.py +171 -0
  34. geovisio/utils/sequences.py +288 -126
  35. geovisio/utils/tokens.py +37 -42
  36. geovisio/utils/upload_set.py +654 -0
  37. geovisio/web/auth.py +50 -37
  38. geovisio/web/collections.py +305 -319
  39. geovisio/web/configuration.py +14 -0
  40. geovisio/web/docs.py +288 -12
  41. geovisio/web/excluded_areas.py +377 -0
  42. geovisio/web/items.py +203 -151
  43. geovisio/web/map.py +322 -106
  44. geovisio/web/params.py +69 -26
  45. geovisio/web/pictures.py +14 -31
  46. geovisio/web/reports.py +399 -0
  47. geovisio/web/rss.py +13 -7
  48. geovisio/web/stac.py +129 -121
  49. geovisio/web/tokens.py +105 -112
  50. geovisio/web/upload_set.py +768 -0
  51. geovisio/web/users.py +100 -73
  52. geovisio/web/utils.py +38 -9
  53. geovisio/workers/runner_pictures.py +278 -183
  54. geovisio-2.7.0.dist-info/METADATA +95 -0
  55. geovisio-2.7.0.dist-info/RECORD +66 -0
  56. geovisio-2.5.0.dist-info/METADATA +0 -115
  57. geovisio-2.5.0.dist-info/RECORD +0 -41
  58. {geovisio-2.5.0.dist-info → geovisio-2.7.0.dist-info}/LICENSE +0 -0
  59. {geovisio-2.5.0.dist-info → geovisio-2.7.0.dist-info}/WHEEL +0 -0
geovisio/utils/tokens.py CHANGED
@@ -1,11 +1,9 @@
1
1
  from geovisio import errors
2
- from geovisio.utils import auth
2
+ from geovisio.utils import auth, db
3
3
  from geovisio.web.tokens import _decode_jwt_token, _generate_jwt_token
4
-
5
-
6
- import psycopg
7
4
  from authlib.jose.errors import BadSignatureError
8
5
  from flask import current_app
6
+ from flask_babel import gettext as _
9
7
  from psycopg.rows import dict_row
10
8
 
11
9
 
@@ -14,7 +12,7 @@ import logging
14
12
 
15
13
  class InvalidTokenException(errors.InvalidAPIUsage):
16
14
  def __init__(self, details, status_code=401):
17
- msg = f"Token not valid"
15
+ msg = "Token not valid"
18
16
  super().__init__(msg, status_code=status_code, payload={"details": {"error": details}})
19
17
 
20
18
 
@@ -39,39 +37,37 @@ def get_account_from_jwt_token(jwt_token: str) -> auth.Account:
39
37
  """
40
38
  try:
41
39
  decoded = _decode_jwt_token(jwt_token)
42
- except BadSignatureError as e:
40
+ except BadSignatureError:
43
41
  logging.exception("invalid signature of jwt token")
44
- raise InvalidTokenException("JWT token signature does not match")
42
+ raise InvalidTokenException(_("JWT token signature does not match"))
45
43
  token_id = decoded["sub"]
46
44
 
47
- with psycopg.connect(current_app.config["DB_URL"], row_factory=dict_row) as conn:
48
- with conn.cursor() as cursor:
49
- # check token existence
50
- records = cursor.execute(
51
- """
52
- SELECT
53
- t.account_id AS id, a.name, a.oauth_provider, a.oauth_id
54
- FROM tokens t
55
- LEFT OUTER JOIN accounts a ON t.account_id = a.id
56
- WHERE t.id = %(token)s
57
- """,
58
- {"token": token_id},
59
- ).fetchone()
60
- if not records:
61
- raise InvalidTokenException("Token does not exist anymore", status_code=403)
62
-
63
- if not records["id"]:
64
- raise InvalidTokenException(
65
- "Token not yet claimed, this token cannot be used yet. Either claim this token or generate a new one", status_code=403
66
- )
67
-
68
- return auth.Account(
69
- id=str(records["id"]),
70
- name=records["name"],
71
- oauth_provider=records["oauth_provider"],
72
- oauth_id=records["oauth_id"],
45
+ with db.cursor(current_app, row_factory=dict_row) as cursor:
46
+ # check token existence
47
+ records = cursor.execute(
48
+ """SELECT
49
+ t.account_id AS id, a.name, a.oauth_provider, a.oauth_id, a.role
50
+ FROM tokens t
51
+ LEFT OUTER JOIN accounts a ON t.account_id = a.id
52
+ WHERE t.id = %(token)s""",
53
+ {"token": token_id},
54
+ ).fetchone()
55
+ if not records:
56
+ raise InvalidTokenException(_("Token does not exist anymore"), status_code=403)
57
+
58
+ if not records["id"]:
59
+ raise InvalidTokenException(
60
+ _("Token not yet claimed, this token cannot be used yet. Either claim this token or generate a new one"), status_code=403
73
61
  )
74
62
 
63
+ return auth.Account(
64
+ id=str(records["id"]),
65
+ name=records["name"],
66
+ oauth_provider=records["oauth_provider"],
67
+ oauth_id=records["oauth_id"],
68
+ role=auth.AccountRole[records["role"]],
69
+ )
70
+
75
71
 
76
72
  def get_default_account_jwt_token() -> str:
77
73
  """
@@ -80,18 +76,17 @@ def get_default_account_jwt_token() -> str:
80
76
  Note: do not expose this method externally, only an instance administrator should be able to get the default account JWT token!
81
77
  """
82
78
 
83
- with psycopg.connect(current_app.config["DB_URL"], row_factory=dict_row) as conn:
84
- with conn.cursor() as cursor:
85
- # check token existence
86
- records = cursor.execute(
87
- """
79
+ with db.cursor(current_app, row_factory=dict_row) as cursor:
80
+ # check token existence
81
+ records = cursor.execute(
82
+ """
88
83
  SELECT t.id AS id
89
84
  FROM tokens t
90
85
  JOIN accounts a ON t.account_id = a.id
91
86
  WHERE a.is_default
92
87
  """
93
- ).fetchone()
94
- if not records:
95
- raise Exception("Default account has no associated token")
88
+ ).fetchone()
89
+ if not records:
90
+ raise Exception("Default account has no associated token")
96
91
 
97
- return _generate_jwt_token(records["id"])
92
+ return _generate_jwt_token(records["id"])