c2cgeoportal-commons 2.5.0.100__py3-none-any.whl → 2.9rc44__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.
Potentially problematic release.
This version of c2cgeoportal-commons might be problematic. Click here for more details.
- c2cgeoportal_commons/__init__.py +2 -5
- c2cgeoportal_commons/alembic/env.py +52 -33
- c2cgeoportal_commons/alembic/main/028477929d13_add_technical_roles.py +10 -7
- c2cgeoportal_commons/alembic/main/04f05bfbb05e_remove_the_old_is_expanded_column.py +62 -0
- c2cgeoportal_commons/alembic/main/116b9b79fc4d_internal_and_external_layer_tables_.py +42 -43
- c2cgeoportal_commons/alembic/main/1418cb05921b_merge_1_6_and_master_branches.py +9 -8
- c2cgeoportal_commons/alembic/main/164ac0819a61_add_image_format_to_wmts_layer.py +9 -6
- c2cgeoportal_commons/alembic/main/166ff2dcc48d_create_database.py +22 -25
- c2cgeoportal_commons/alembic/main/16e43f8c0330_remove_old_metadata_column.py +9 -6
- c2cgeoportal_commons/alembic/main/1d5d4abfebd1_add_restricted_theme.py +14 -8
- c2cgeoportal_commons/alembic/main/1de20166b274_remove_v1_artifacts.py +9 -6
- c2cgeoportal_commons/alembic/main/20137477bd02_update_icons_url.py +9 -6
- c2cgeoportal_commons/alembic/main/21f11066f8ec_trigger_on_role_updates_user_in_static.py +21 -20
- c2cgeoportal_commons/alembic/main/22e6dfb556de_add_description_tree_.py +9 -6
- c2cgeoportal_commons/alembic/main/29f2a32859ec_merge_1_6_and_master_branches.py +9 -8
- c2cgeoportal_commons/alembic/main/2b8ed8c1df94_set_layergroup_treeitem_is_as_a_primary_.py +9 -6
- c2cgeoportal_commons/alembic/main/2e57710fecfe_update_the_ogc_server_for_ogc_api.py +71 -0
- c2cgeoportal_commons/alembic/main/32527659d57b_move_exclude_properties_from_layerv1_to_.py +15 -12
- c2cgeoportal_commons/alembic/main/32b21aa1d0ed_merge_e004f76e951a_and_e004f76e951a_.py +9 -8
- c2cgeoportal_commons/alembic/main/338b57593823_remove_trigger_on_role_name_change.py +25 -24
- c2cgeoportal_commons/alembic/main/415746eb9f6_changes_for_v2.py +45 -43
- c2cgeoportal_commons/alembic/main/44c91d82d419_add_table_log.py +72 -0
- c2cgeoportal_commons/alembic/main/5109242131ce_add_column_time_widget.py +11 -9
- c2cgeoportal_commons/alembic/main/52916d8fde8b_add_sql_fields_to_vector_tiles.py +60 -0
- c2cgeoportal_commons/alembic/main/53ba1a68d5fe_add_theme_to_fulltextsearch.py +9 -6
- c2cgeoportal_commons/alembic/main/54645a535ad6_add_ordering_in_relation.py +17 -14
- c2cgeoportal_commons/alembic/main/56dc90838d90_fix_removing_layerv1.py +10 -8
- c2cgeoportal_commons/alembic/main/596ba21e3833_separate_local_internal.py +13 -14
- c2cgeoportal_commons/alembic/main/678f88c7ad5e_add_vector_tiles_layers_table.py +9 -6
- c2cgeoportal_commons/alembic/main/6a412d9437b1_rename_serverogc_to_ogcserver.py +9 -6
- c2cgeoportal_commons/alembic/main/6d87fdad275a_convert_metadata_to_the_right_case.py +13 -20
- c2cgeoportal_commons/alembic/main/7530011a66a7_trigger_on_role_updates_user_in_static.py +21 -20
- c2cgeoportal_commons/alembic/main/78fd093c8393_add_api_s_intrfaces.py +36 -52
- c2cgeoportal_commons/alembic/main/7d271f4527cd_add_layer_column_in_layerv1_table.py +9 -6
- c2cgeoportal_commons/alembic/main/809650bd04c3_add_dimension_field.py +9 -6
- c2cgeoportal_commons/alembic/main/8117bb9bba16_use_dimension_on_all_the_layers.py +9 -6
- c2cgeoportal_commons/alembic/main/87f8330ed64e_add_missing_delete_cascades.py +305 -0
- c2cgeoportal_commons/alembic/main/9268a1dffac0_add_trigger_to_be_able_to_correctly_.py +11 -8
- c2cgeoportal_commons/alembic/main/94db7e7e5b21_merge_2_2_and_master_branches.py +9 -8
- c2cgeoportal_commons/alembic/main/951ff84bd8ec_be_able_to_delete_a_wms_layer_in_sql.py +9 -6
- c2cgeoportal_commons/alembic/main/a00109812f89_add_field_layer_wms_valid.py +60 -0
- c2cgeoportal_commons/alembic/main/a4558f032d7d_add_support_of_cog_layers.py +74 -0
- c2cgeoportal_commons/alembic/main/a4f1aac9bda_merge_1_6_and_master_branches.py +9 -8
- c2cgeoportal_commons/alembic/main/b60f2a505f42_remame_uimetadata_to_metadata.py +9 -6
- c2cgeoportal_commons/alembic/main/b6b09f414fe8_sync_model_database.py +165 -0
- c2cgeoportal_commons/alembic/main/c75124553bf3_remove_deprecated_columns.py +9 -6
- c2cgeoportal_commons/alembic/main/d48a63b348f1_change_mapserver_url_for_docker.py +13 -14
- c2cgeoportal_commons/alembic/main/d8ef99bc227e_be_able_to_delete_a_linked_functionality.py +16 -13
- c2cgeoportal_commons/alembic/main/daf738d5bae4_merge_2_0_and_master_branches.py +9 -8
- c2cgeoportal_commons/alembic/main/dba87f2647f9_merge_2_2_on_2_3.py +9 -8
- c2cgeoportal_commons/alembic/main/e004f76e951a_add_missing_not_null.py +15 -32
- c2cgeoportal_commons/alembic/main/e7e03dedade3_put_the_default_wms_server_in_the_.py +13 -14
- c2cgeoportal_commons/alembic/main/e85afd327ab3_cascade_deletes_to_tsearch.py +9 -6
- c2cgeoportal_commons/alembic/main/ec82a8906649_add_missing_on_delete_cascade_on_layer_.py +13 -10
- c2cgeoportal_commons/alembic/main/ee25d267bf46_main_interface_desktop.py +11 -14
- c2cgeoportal_commons/alembic/main/eeb345672454_merge_2_4_and_master_branches.py +9 -8
- c2cgeoportal_commons/alembic/static/0c640a58a09a_add_opt_key_column.py +9 -6
- c2cgeoportal_commons/alembic/static/107b81f5b9fe_add_missing_delete_cascades.py +78 -0
- c2cgeoportal_commons/alembic/static/1857owc78a07_add_last_login_and_expiration_date.py +7 -6
- c2cgeoportal_commons/alembic/static/1da396a88908_move_user_table_to_static_schema.py +19 -20
- c2cgeoportal_commons/alembic/static/267b4c1bde2e_add_display_name_in_the_user_for_better_.py +62 -0
- c2cgeoportal_commons/alembic/static/3f89a7d71a5e_alter_column_url_to_remove_limitation.py +8 -7
- c2cgeoportal_commons/alembic/static/44c91d82d419_add_table_log.py +72 -0
- c2cgeoportal_commons/alembic/static/53d671b17b20_add_timezone_on_datetime_fields.py +9 -6
- c2cgeoportal_commons/alembic/static/5472fbc19f39_add_temp_password_column.py +9 -6
- c2cgeoportal_commons/alembic/static/76d72fb3fcb9_add_oauth2_pkce.py +70 -0
- c2cgeoportal_commons/alembic/static/7ef947f30f20_add_oauth2_tables.py +115 -0
- c2cgeoportal_commons/alembic/static/910b4ca53b68_sync_model_database.py +186 -0
- c2cgeoportal_commons/alembic/static/aa41e9613256_wip_add_openid_connect_support.py +64 -0
- c2cgeoportal_commons/alembic/static/ae5e88f35669_add_table_user_role.py +15 -18
- c2cgeoportal_commons/alembic/static/bd029dbfc11a_fill_tech_data_column.py +10 -8
- c2cgeoportal_commons/lib/email_.py +16 -18
- c2cgeoportal_commons/lib/literal.py +44 -0
- c2cgeoportal_commons/lib/url.py +221 -0
- c2cgeoportal_commons/lib/validators.py +2 -4
- c2cgeoportal_commons/models/__init__.py +19 -15
- c2cgeoportal_commons/models/main.py +1268 -266
- c2cgeoportal_commons/models/sqlalchemy.py +15 -19
- c2cgeoportal_commons/models/static.py +338 -63
- c2cgeoportal_commons/py.typed +0 -0
- c2cgeoportal_commons/testing/__init__.py +18 -13
- c2cgeoportal_commons/testing/initializedb.py +15 -14
- {c2cgeoportal_commons-2.5.0.100.dist-info → c2cgeoportal_commons-2.9rc44.dist-info}/METADATA +18 -23
- c2cgeoportal_commons-2.9rc44.dist-info/RECORD +89 -0
- {c2cgeoportal_commons-2.5.0.100.dist-info → c2cgeoportal_commons-2.9rc44.dist-info}/WHEEL +1 -1
- tests/conftest.py +4 -6
- c2cgeoportal_commons-2.5.0.100.dist-info/RECORD +0 -75
- tests/test_interface.py +0 -27
- tests/test_roles.py +0 -63
- tests/test_users.py +0 -71
- tests/test_validators.py +0 -20
- {c2cgeoportal_commons-2.5.0.100.dist-info → c2cgeoportal_commons-2.9rc44.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2019, Camptocamp SA
|
|
1
|
+
# Copyright (c) 2018-2024, Camptocamp SA
|
|
4
2
|
# All rights reserved.
|
|
5
3
|
|
|
6
4
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -27,7 +25,10 @@
|
|
|
27
25
|
# of the authors and should not be interpreted as representing official policies,
|
|
28
26
|
# either expressed or implied, of the FreeBSD Project.
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
# pylint: disable=no-member,invalid-name
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
Add table user_role and rename user.role_name to settings_role_id.
|
|
31
32
|
|
|
32
33
|
Revision ID: ae5e88f35669
|
|
33
34
|
Revises: 53d671b17b20
|
|
@@ -46,7 +47,8 @@ branch_labels = None
|
|
|
46
47
|
depends_on = None
|
|
47
48
|
|
|
48
49
|
|
|
49
|
-
def upgrade():
|
|
50
|
+
def upgrade() -> None:
|
|
51
|
+
"""Upgrade."""
|
|
50
52
|
schema = config["schema"]
|
|
51
53
|
staticschema = config["schema_static"]
|
|
52
54
|
|
|
@@ -57,43 +59,38 @@ def upgrade():
|
|
|
57
59
|
schema=staticschema,
|
|
58
60
|
)
|
|
59
61
|
op.execute(
|
|
60
|
-
"""
|
|
62
|
+
f"""
|
|
61
63
|
INSERT INTO "{staticschema}"."user_role" ("user_id", "role_id")
|
|
62
64
|
SELECT "user"."id", "role"."id"
|
|
63
65
|
FROM "{staticschema}"."user"
|
|
64
|
-
JOIN "{schema}"."role" ON "role"."name" = "user"."role_name";"""
|
|
65
|
-
schema=schema, staticschema=staticschema
|
|
66
|
-
)
|
|
66
|
+
JOIN "{schema}"."role" ON "role"."name" = "user"."role_name";"""
|
|
67
67
|
)
|
|
68
68
|
|
|
69
69
|
op.add_column("user", Column("settings_role_id", Integer), schema=staticschema)
|
|
70
70
|
op.execute(
|
|
71
|
-
"""
|
|
71
|
+
f"""
|
|
72
72
|
UPDATE "{staticschema}"."user"
|
|
73
73
|
SET "settings_role_id" = "role"."id"
|
|
74
74
|
FROM "{schema}"."role"
|
|
75
|
-
WHERE "role"."name" = "user"."role_name";"""
|
|
76
|
-
schema=schema, staticschema=staticschema
|
|
77
|
-
)
|
|
75
|
+
WHERE "role"."name" = "user"."role_name";"""
|
|
78
76
|
)
|
|
79
77
|
|
|
80
78
|
op.drop_column("user", "role_name", schema=staticschema)
|
|
81
79
|
|
|
82
80
|
|
|
83
|
-
def downgrade():
|
|
81
|
+
def downgrade() -> None:
|
|
82
|
+
"""Downgrade."""
|
|
84
83
|
schema = config["schema"]
|
|
85
84
|
staticschema = config["schema_static"]
|
|
86
85
|
|
|
87
86
|
op.add_column("user", Column("role_name", Unicode), schema=staticschema)
|
|
88
87
|
|
|
89
88
|
op.execute(
|
|
90
|
-
"""
|
|
89
|
+
f"""
|
|
91
90
|
UPDATE "{staticschema}"."user"
|
|
92
91
|
SET "role_name" = "role"."name"
|
|
93
92
|
FROM "{schema}"."role"
|
|
94
|
-
WHERE "role"."id" = "user"."settings_role_id";"""
|
|
95
|
-
schema=schema, staticschema=staticschema
|
|
96
|
-
)
|
|
93
|
+
WHERE "role"."id" = "user"."settings_role_id";"""
|
|
97
94
|
)
|
|
98
95
|
|
|
99
96
|
op.drop_column("user", "settings_role_id", schema=staticschema)
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019, Camptocamp SA
|
|
1
|
+
# Copyright (c) 2019-2024, Camptocamp SA
|
|
4
2
|
# All rights reserved.
|
|
5
3
|
|
|
6
4
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -27,7 +25,10 @@
|
|
|
27
25
|
# of the authors and should not be interpreted as representing official policies,
|
|
28
26
|
# either expressed or implied, of the FreeBSD Project.
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
# pylint: disable=no-member,invalid-name
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
Fill tech_data column.
|
|
31
32
|
|
|
32
33
|
Revision ID: bd029dbfc11a
|
|
33
34
|
Revises: 0c640a58a09a
|
|
@@ -44,11 +45,12 @@ branch_labels = None
|
|
|
44
45
|
depends_on = None
|
|
45
46
|
|
|
46
47
|
|
|
47
|
-
def upgrade():
|
|
48
|
+
def upgrade() -> None:
|
|
49
|
+
"""Upgrade."""
|
|
48
50
|
staticschema = config["schema_static"]
|
|
49
51
|
|
|
50
|
-
op.execute("UPDATE {staticschema}.\"user\" SET tech_data = '';"
|
|
52
|
+
op.execute(f"UPDATE {staticschema}.\"user\" SET tech_data = '';")
|
|
51
53
|
|
|
52
54
|
|
|
53
|
-
def downgrade():
|
|
54
|
-
|
|
55
|
+
def downgrade() -> None:
|
|
56
|
+
"""Downgrade."""
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2013-2020, Camptocamp SA
|
|
1
|
+
# Copyright (c) 2013-2024, Camptocamp SA
|
|
4
2
|
# All rights reserved.
|
|
5
3
|
|
|
6
4
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -28,30 +26,29 @@
|
|
|
28
26
|
# either expressed or implied, of the FreeBSD Project.
|
|
29
27
|
|
|
30
28
|
|
|
29
|
+
import logging
|
|
30
|
+
import smtplib
|
|
31
31
|
from email.mime.multipart import MIMEMultipart
|
|
32
32
|
from email.mime.text import MIMEText
|
|
33
33
|
from email.utils import formatdate
|
|
34
|
-
import logging
|
|
35
|
-
import smtplib
|
|
36
34
|
from socket import gaierror
|
|
37
|
-
from typing import Any,
|
|
35
|
+
from typing import Any, cast
|
|
38
36
|
|
|
39
37
|
try:
|
|
40
38
|
from pyramid.httpexceptions import HTTPInternalServerError
|
|
41
39
|
except ModuleNotFoundError:
|
|
42
40
|
|
|
43
41
|
class HTTPInternalServerError(BaseException): # type: ignore
|
|
44
|
-
|
|
42
|
+
"""Fallback class."""
|
|
45
43
|
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
_LOG = logging.getLogger(__name__)
|
|
48
46
|
|
|
49
47
|
|
|
50
|
-
def send_email_config(
|
|
51
|
-
|
|
52
|
-
) -> None: # pragma: no cover
|
|
48
|
+
def send_email_config(settings: dict[str, Any], email_config_name: str, email: str, **kwargs: Any) -> None:
|
|
49
|
+
"""Send an email from the config information."""
|
|
53
50
|
smtp_config = settings["smtp"]
|
|
54
|
-
email_config = cast(
|
|
51
|
+
email_config = cast(dict[str, str], settings[email_config_name])
|
|
55
52
|
|
|
56
53
|
try:
|
|
57
54
|
send_email(
|
|
@@ -62,16 +59,17 @@ def send_email_config(
|
|
|
62
59
|
smtp_config,
|
|
63
60
|
)
|
|
64
61
|
except gaierror:
|
|
65
|
-
|
|
66
|
-
raise HTTPInternalServerError("See server logs for details")
|
|
62
|
+
_LOG.exception("Unable to send the email.")
|
|
63
|
+
raise HTTPInternalServerError("See server logs for details") # pylint: disable=raise-missing-from
|
|
67
64
|
|
|
68
65
|
|
|
69
66
|
def send_email(
|
|
70
|
-
from_addr: str,
|
|
71
|
-
) -> None:
|
|
67
|
+
from_addr: str, to_address: list[str], body: str, subject: str, smtp_config: dict[str, str]
|
|
68
|
+
) -> None:
|
|
69
|
+
"""Send an email."""
|
|
72
70
|
msg = MIMEMultipart()
|
|
73
71
|
msg["From"] = from_addr
|
|
74
|
-
msg["To"] = ", ".join(
|
|
72
|
+
msg["To"] = ", ".join(to_address)
|
|
75
73
|
msg["Date"] = formatdate(localtime=True)
|
|
76
74
|
msg["Subject"] = subject
|
|
77
75
|
msg.attach(MIMEText(body, "plain", "utf-8"))
|
|
@@ -86,5 +84,5 @@ def send_email(
|
|
|
86
84
|
if smtp_config.get("user", False):
|
|
87
85
|
smtp.login(smtp_config["user"], smtp_config["password"])
|
|
88
86
|
|
|
89
|
-
smtp.sendmail(from_addr,
|
|
87
|
+
smtp.sendmail(from_addr, to_address, msg.as_string())
|
|
90
88
|
smtp.close()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright (c) 2021-2024, Camptocamp SA
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
|
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
# list of conditions and the following disclaimer.
|
|
9
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
# and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
14
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
15
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
16
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
17
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
18
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
19
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
20
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
21
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
22
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
23
|
+
|
|
24
|
+
# The views and conclusions contained in the software and documentation are those
|
|
25
|
+
# of the authors and should not be interpreted as representing official policies,
|
|
26
|
+
# either expressed or implied, of the FreeBSD Project.
|
|
27
|
+
|
|
28
|
+
from typing import cast
|
|
29
|
+
|
|
30
|
+
from pyramid.i18n import TranslationString
|
|
31
|
+
from pyramid.threadlocal import get_current_request
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Literal:
|
|
35
|
+
"""For use in templates to mark a string as safe and avoid HTML escaping."""
|
|
36
|
+
|
|
37
|
+
def __init__(self, s: str | TranslationString) -> None:
|
|
38
|
+
self.s = s
|
|
39
|
+
|
|
40
|
+
def __html__(self) -> str:
|
|
41
|
+
return cast(str, get_current_request().translate(self.s))
|
|
42
|
+
|
|
43
|
+
def __bool__(self) -> bool:
|
|
44
|
+
return len(self.s) > 0
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Copyright (c) 2013-2024, Camptocamp SA
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
|
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
# list of conditions and the following disclaimer.
|
|
9
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
# and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
14
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
15
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
16
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
17
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
18
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
19
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
20
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
21
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
22
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
23
|
+
|
|
24
|
+
# The views and conclusions contained in the software and documentation are those
|
|
25
|
+
# of the authors and should not be interpreted as representing official policies,
|
|
26
|
+
# either expressed or implied, of the FreeBSD Project.
|
|
27
|
+
|
|
28
|
+
import logging
|
|
29
|
+
import re
|
|
30
|
+
import urllib.parse
|
|
31
|
+
|
|
32
|
+
from pyramid.request import Request
|
|
33
|
+
|
|
34
|
+
_LOG = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Url:
|
|
38
|
+
"""Object representation of an URI."""
|
|
39
|
+
|
|
40
|
+
scheme = ""
|
|
41
|
+
_netloc = ""
|
|
42
|
+
_hostname: str | None = None
|
|
43
|
+
_port: int | None = None
|
|
44
|
+
path = ""
|
|
45
|
+
query: dict[str, str] = {}
|
|
46
|
+
fragment = ""
|
|
47
|
+
|
|
48
|
+
def __init__(self, url: str | None = None):
|
|
49
|
+
if url:
|
|
50
|
+
url_split = urllib.parse.urlsplit(url)
|
|
51
|
+
self.scheme = url_split.scheme
|
|
52
|
+
self._netloc = url_split.netloc
|
|
53
|
+
self._hostname = url_split.hostname
|
|
54
|
+
try:
|
|
55
|
+
self._port = url_split.port
|
|
56
|
+
except ValueError as error:
|
|
57
|
+
_LOG.debug(error)
|
|
58
|
+
self.path = url_split.path
|
|
59
|
+
self.query = dict(urllib.parse.parse_qsl(url_split.query))
|
|
60
|
+
self.fragment = url_split.fragment
|
|
61
|
+
|
|
62
|
+
def clone(self) -> "Url":
|
|
63
|
+
result = Url()
|
|
64
|
+
result.scheme = self.scheme
|
|
65
|
+
result._netloc = self._netloc # pylint: disable=protected-access
|
|
66
|
+
result._hostname = self._hostname # pylint: disable=protected-access
|
|
67
|
+
result._port = self._port # pylint: disable=protected-access
|
|
68
|
+
result.path = self.path
|
|
69
|
+
result.query = dict(self.query)
|
|
70
|
+
result.fragment = self.fragment
|
|
71
|
+
return result
|
|
72
|
+
|
|
73
|
+
@staticmethod
|
|
74
|
+
def _is_valid_hostname(hostname: str) -> bool:
|
|
75
|
+
if len(hostname) > 255:
|
|
76
|
+
return False
|
|
77
|
+
if hostname[-1] == ".":
|
|
78
|
+
hostname = hostname[:-1] # strip exactly one dot from the right, if present
|
|
79
|
+
allowed = re.compile(r"(?!-)[a-z\d-]{1,63}(?<!-)$", re.IGNORECASE)
|
|
80
|
+
return all(allowed.match(x) for x in hostname.split("."))
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def netloc(self) -> str:
|
|
84
|
+
return self._netloc
|
|
85
|
+
|
|
86
|
+
@netloc.setter
|
|
87
|
+
def netloc(self, netloc: str) -> None:
|
|
88
|
+
netloc_split = netloc.split(":")
|
|
89
|
+
if len(netloc_split) > 2:
|
|
90
|
+
raise RuntimeError(f"The netloc '{netloc}' in invalid")
|
|
91
|
+
if not self._is_valid_hostname(netloc_split[0]):
|
|
92
|
+
raise RuntimeError(f"The netloc '{netloc}' in invalid")
|
|
93
|
+
if len(netloc_split) == 2:
|
|
94
|
+
allowed = re.compile(r"^[0-9]+$")
|
|
95
|
+
if not allowed.match(netloc_split[1]):
|
|
96
|
+
_LOG.debug("The netloc '%s' contains invalid port", netloc)
|
|
97
|
+
self._port = None
|
|
98
|
+
else:
|
|
99
|
+
self._port = int(netloc_split[1])
|
|
100
|
+
else:
|
|
101
|
+
self._port = None
|
|
102
|
+
self._netloc = netloc
|
|
103
|
+
self._hostname = netloc_split[0]
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def hostname(self) -> str | None:
|
|
107
|
+
return self._hostname
|
|
108
|
+
|
|
109
|
+
@hostname.setter
|
|
110
|
+
def hostname(self, hostname: str) -> None:
|
|
111
|
+
if not self._is_valid_hostname(hostname):
|
|
112
|
+
raise RuntimeError(f"The hostname '{hostname}' in invalid")
|
|
113
|
+
self._hostname = hostname
|
|
114
|
+
self.netloc = hostname if self._port is None else f"{hostname}:{self._port}"
|
|
115
|
+
|
|
116
|
+
@property
|
|
117
|
+
def port(self) -> int | None:
|
|
118
|
+
return self._port
|
|
119
|
+
|
|
120
|
+
@port.setter
|
|
121
|
+
def port(self, port: int | None) -> None:
|
|
122
|
+
self._port = port
|
|
123
|
+
self.netloc = (self._hostname or "") if port is None else f"{self._hostname}:{port}"
|
|
124
|
+
|
|
125
|
+
def add_query(self, query: dict[str, str], force: bool = False) -> "Url":
|
|
126
|
+
if query:
|
|
127
|
+
for key, value in query.items():
|
|
128
|
+
if force or key not in self.query:
|
|
129
|
+
self.query[key] = value
|
|
130
|
+
return self
|
|
131
|
+
|
|
132
|
+
@property
|
|
133
|
+
def query_lower(self) -> dict[str, str]:
|
|
134
|
+
return {k.lower(): v for k, v in self.query.items()}
|
|
135
|
+
|
|
136
|
+
def url(self) -> str:
|
|
137
|
+
return urllib.parse.urlunsplit(
|
|
138
|
+
(
|
|
139
|
+
self.scheme,
|
|
140
|
+
self._netloc,
|
|
141
|
+
self.path,
|
|
142
|
+
urllib.parse.urlencode(self.query),
|
|
143
|
+
self.fragment,
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def __str__(self) -> str:
|
|
148
|
+
return self.url()
|
|
149
|
+
|
|
150
|
+
def __repr__(self) -> str:
|
|
151
|
+
return self.url()
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def get_url2(
|
|
155
|
+
name: str, url: str, request: Request, errors: set[str], servers: dict[str, str] | None = None
|
|
156
|
+
) -> Url | None:
|
|
157
|
+
"""
|
|
158
|
+
Get the real URL from the URI of the administration interface.
|
|
159
|
+
|
|
160
|
+
Manage the schema: static and config.
|
|
161
|
+
"""
|
|
162
|
+
if servers is None:
|
|
163
|
+
servers = request.registry.settings.get("servers", {})
|
|
164
|
+
|
|
165
|
+
url_obj = Url(url)
|
|
166
|
+
url_split = urllib.parse.urlsplit(url)
|
|
167
|
+
if url_obj.scheme == "":
|
|
168
|
+
if url_obj.netloc == "" and url_obj.path not in ("", "/"):
|
|
169
|
+
# Relative URL like: /dummy/static/url or dummy/static/url
|
|
170
|
+
return url_obj
|
|
171
|
+
errors.add(f"{name}='{url}' is not an URL.")
|
|
172
|
+
return None
|
|
173
|
+
if url_obj.scheme in ("http", "https"):
|
|
174
|
+
if url_obj.netloc == "":
|
|
175
|
+
errors.add(f"{name}='{url}' is not a valid URL.")
|
|
176
|
+
return None
|
|
177
|
+
return url_obj
|
|
178
|
+
if url_obj.scheme == "static":
|
|
179
|
+
if request is None:
|
|
180
|
+
errors.add(f"{name}='{url}' The request is required for static URL.")
|
|
181
|
+
if url_obj.path in ("", "/"):
|
|
182
|
+
errors.add(f"{name}='{url}' cannot have an empty path.")
|
|
183
|
+
return None
|
|
184
|
+
proj = url_obj.netloc
|
|
185
|
+
package = request.registry.settings["package"]
|
|
186
|
+
if proj in ("", "static"):
|
|
187
|
+
proj = "/etc/geomapfish/static"
|
|
188
|
+
elif ":" not in proj:
|
|
189
|
+
if proj == "static-ngeo":
|
|
190
|
+
errors.add(
|
|
191
|
+
f"{name}='{url}' static-ngeo shouldn't be used out of webpack because it don't has "
|
|
192
|
+
"cache bustering."
|
|
193
|
+
)
|
|
194
|
+
proj = f"{package}_geoportal:{proj}"
|
|
195
|
+
return Url(request.static_url(f"{proj}{url_split.path}"))
|
|
196
|
+
if url_obj.scheme == "config":
|
|
197
|
+
if url_obj.netloc == "":
|
|
198
|
+
errors.add(f"{name}='{url}' cannot have an empty netloc.")
|
|
199
|
+
return None
|
|
200
|
+
server = servers.get(url_obj.netloc)
|
|
201
|
+
if server is None:
|
|
202
|
+
errors.add(
|
|
203
|
+
f"{name}: The server '{url_obj.netloc}' ({url}) is not found in the config: "
|
|
204
|
+
f"[{', '.join(servers.keys())}]"
|
|
205
|
+
)
|
|
206
|
+
return None
|
|
207
|
+
|
|
208
|
+
if isinstance(server, dict):
|
|
209
|
+
url_obj_server = Url(server["url"])
|
|
210
|
+
url_obj_server.add_query(server.get("params", {}))
|
|
211
|
+
else:
|
|
212
|
+
url_obj_server = Url(server)
|
|
213
|
+
|
|
214
|
+
if url_obj.path != "":
|
|
215
|
+
if url_obj_server.path == "" or url_obj_server.path[-1] != "/":
|
|
216
|
+
url_obj_server.path += "/"
|
|
217
|
+
url_obj_server.path = urllib.parse.urljoin(url_obj_server.path, url_obj.path[1:])
|
|
218
|
+
url_obj_server.add_query(url_obj.query, force=True)
|
|
219
|
+
url_obj_server.fragment = url_obj.fragment
|
|
220
|
+
return url_obj_server
|
|
221
|
+
return None
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2020, Camptocamp SA
|
|
1
|
+
# Copyright (c) 2019-2023, Camptocamp SA
|
|
4
2
|
# All rights reserved.
|
|
5
3
|
|
|
6
4
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -33,5 +31,5 @@ import re
|
|
|
33
31
|
import colander
|
|
34
32
|
|
|
35
33
|
# Custom url validator that allow c2cgeoportal static urls.
|
|
36
|
-
URL_REGEX =
|
|
34
|
+
URL_REGEX = rf"(?:{colander.URL_REGEX}|^(:?static|config)://\S+$)"
|
|
37
35
|
url = colander.Regex(URL_REGEX, msg=colander._("Must be a URL"), flags=re.IGNORECASE)
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2011-2020, Camptocamp SA
|
|
1
|
+
# Copyright (c) 2011-2024, Camptocamp SA
|
|
4
2
|
# All rights reserved.
|
|
5
3
|
|
|
6
4
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -29,11 +27,11 @@
|
|
|
29
27
|
|
|
30
28
|
|
|
31
29
|
import logging
|
|
32
|
-
from typing import Any
|
|
30
|
+
from typing import Any
|
|
33
31
|
|
|
34
32
|
import sqlalchemy.ext.declarative
|
|
35
|
-
import sqlalchemy.
|
|
36
|
-
import sqlalchemy.orm
|
|
33
|
+
import sqlalchemy.orm
|
|
34
|
+
import sqlalchemy.orm.scoping
|
|
37
35
|
import zope.event
|
|
38
36
|
|
|
39
37
|
try:
|
|
@@ -44,20 +42,27 @@ except ModuleNotFoundError:
|
|
|
44
42
|
pass
|
|
45
43
|
|
|
46
44
|
|
|
47
|
-
# Should be filed on application
|
|
48
|
-
DBSession: sqlalchemy.orm.Session = None
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
# Should be filed on application initialization
|
|
46
|
+
DBSession: sqlalchemy.orm.scoping.scoped_session[sqlalchemy.orm.Session] | None = None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class BaseType(sqlalchemy.ext.declarative.DeclarativeMeta, type):
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
Base: BaseType = sqlalchemy.orm.declarative_base()
|
|
54
|
+
DBSessions: dict[str, sqlalchemy.orm.scoping.scoped_session[sqlalchemy.orm.Session]] = {}
|
|
51
55
|
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
_LOG = logging.getLogger(__name__)
|
|
54
58
|
|
|
55
59
|
|
|
56
60
|
class InvalidateCacheEvent:
|
|
57
|
-
|
|
61
|
+
"""Event to be broadcast."""
|
|
58
62
|
|
|
59
63
|
|
|
60
|
-
def cache_invalidate_cb(*args:
|
|
64
|
+
def cache_invalidate_cb(*args: list[Any]) -> None:
|
|
65
|
+
"""Invalidate the cache on a broadcast event."""
|
|
61
66
|
_cache_invalidate_cb()
|
|
62
67
|
|
|
63
68
|
|
|
@@ -68,6 +73,5 @@ try:
|
|
|
68
73
|
def _cache_invalidate_cb() -> None:
|
|
69
74
|
zope.event.notify(InvalidateCacheEvent())
|
|
70
75
|
|
|
71
|
-
|
|
72
76
|
except ModuleNotFoundError:
|
|
73
|
-
|
|
77
|
+
_LOG.error("c2cwsgiutils broadcast not found")
|