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/web/auth.py CHANGED
@@ -1,10 +1,11 @@
1
1
  import flask
2
2
  from flask import current_app, url_for, session, redirect, request, jsonify
3
- import psycopg
4
- from typing import Any
3
+ from flask_babel import gettext as _
5
4
  from urllib.parse import quote
6
- from geovisio import utils
5
+ from geovisio import utils, errors
6
+ from geovisio.utils import db
7
7
  from geovisio.utils.auth import Account, ACCOUNT_KEY
8
+ from authlib.integrations.base_client.errors import MismatchingStateError
8
9
 
9
10
  bp = flask.Blueprint("auth", __name__, url_prefix="/api/auth")
10
11
 
@@ -52,42 +53,54 @@ def auth():
52
53
  schema:
53
54
  type: string
54
55
  """
55
- tokenResponse = utils.auth.oauth_provider.client.authorize_access_token()
56
+ try:
57
+ tokenResponse = utils.auth.oauth_provider.client.authorize_access_token()
58
+ except MismatchingStateError as e:
59
+ raise errors.InternalError(
60
+ _("Impossible to finish authentication flow"),
61
+ payload={
62
+ "details": {
63
+ "error": str(e),
64
+ "tips": _("You can try to clear your cookies and retry. If the problem persists, contact your instance administrator."),
65
+ }
66
+ },
67
+ status_code=403,
68
+ )
56
69
 
57
70
  oauth_info = utils.auth.oauth_provider.get_user_oauth_info(tokenResponse)
58
- with psycopg.connect(current_app.config["DB_URL"]) as conn:
59
- with conn.cursor() as cursor:
60
- res = cursor.execute(
61
- "INSERT INTO accounts (name, oauth_provider, oauth_id) VALUES (%(name)s, %(provider)s, %(id)s) ON CONFLICT (oauth_provider, oauth_id) DO UPDATE SET name = %(name)s RETURNING id, name",
62
- {
63
- "provider": utils.auth.oauth_provider.name,
64
- "id": oauth_info.id,
65
- "name": oauth_info.name,
66
- },
67
- ).fetchone()
68
- if res is None:
69
- raise Exception("Impossible to insert user in database")
70
- id, name = res
71
- account = Account(
72
- id=str(id), # convert uuid to string for serialization
73
- name=name,
74
- oauth_provider=utils.auth.oauth_provider.name,
75
- oauth_id=oauth_info.id,
76
- )
77
- session[ACCOUNT_KEY] = account.__dict__
78
-
79
- next_url = session.pop(NEXT_URL_KEY, None)
80
- if next_url:
81
- response = flask.make_response(redirect(next_url))
82
- else:
83
- response = flask.make_response(redirect("/"))
84
-
85
- # also store id/name in cookies for the front end to use those
86
- max_age = current_app.config["PERMANENT_SESSION_LIFETIME"]
87
- _set_cookie(response, "user_id", str(id), max_age=max_age)
88
- _set_cookie(response, "user_name", quote(name), max_age=max_age)
89
-
90
- return response
71
+ with db.cursor(current_app) as cursor:
72
+ res = cursor.execute(
73
+ "INSERT INTO accounts (name, oauth_provider, oauth_id) VALUES (%(name)s, %(provider)s, %(id)s) ON CONFLICT (oauth_provider, oauth_id) DO UPDATE SET name = %(name)s RETURNING id, name",
74
+ {
75
+ "provider": utils.auth.oauth_provider.name,
76
+ "id": oauth_info.id,
77
+ "name": oauth_info.name,
78
+ },
79
+ ).fetchone()
80
+ if res is None:
81
+ raise Exception("Impossible to insert user in database")
82
+ id, name = res
83
+ account = Account(
84
+ id=str(id), # convert uuid to string for serialization
85
+ name=name,
86
+ oauth_provider=utils.auth.oauth_provider.name,
87
+ oauth_id=oauth_info.id,
88
+ )
89
+ session[ACCOUNT_KEY] = account.model_dump(exclude_none=True)
90
+ session.permanent = True
91
+
92
+ next_url = session.pop(NEXT_URL_KEY, None)
93
+ if next_url:
94
+ response = flask.make_response(redirect(next_url))
95
+ else:
96
+ response = flask.make_response(redirect("/"))
97
+
98
+ # also store id/name in cookies for the front end to use those
99
+ max_age = current_app.config["PERMANENT_SESSION_LIFETIME"]
100
+ _set_cookie(response, "user_id", str(id), max_age=max_age)
101
+ _set_cookie(response, "user_name", quote(name), max_age=max_age)
102
+
103
+ return response
91
104
 
92
105
 
93
106
  @bp.route("/logout")