Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e6ff518
feat(extensions): add new blueprint and tests for extension imports
MaxNumerique Dec 8, 2025
7090cc1
frontend_file as read
MaxNumerique Dec 8, 2025
56b7696
Apply prepare changes
MaxNumerique Dec 8, 2025
35ead1d
EXTENSION_FOLDER_PATH in config
MaxNumerique Dec 9, 2025
069cc6a
fix test with EXTENSION_FOLDER_PATH
MaxNumerique Dec 9, 2025
5c99282
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
JulienChampagnol Dec 31, 2025
3b7f777
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/…
JulienChampagnol Dec 31, 2025
1c9bb68
Feat(App): create_app, register_ogw_back_blueprints, run_server
JulienChampagnol Jan 7, 2026
1043160
Apply prepare changes
JulienChampagnol Jan 7, 2026
24d80c8
wip unit tests [skip ci]
JulienChampagnol Jan 7, 2026
9b7b95b
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/…
JulienChampagnol Jan 7, 2026
1f433c8
Apply prepare changes
JulienChampagnol Jan 7, 2026
fd574bd
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
JulienChampagnol Jan 7, 2026
4d7e303
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/…
JulienChampagnol Jan 7, 2026
d068a01
test trigger tests
JulienChampagnol Jan 7, 2026
f91d8e6
Apply prepare changes
JulienChampagnol Jan 7, 2026
c9ba3e7
fix tests
JulienChampagnol Jan 7, 2026
3c9d07a
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/…
JulienChampagnol Jan 7, 2026
dd71a91
Apply prepare changes
JulienChampagnol Jan 7, 2026
9b70f2d
feat(App): create_app, register_ogw_back_blueprints, run_server
JulienChampagnol Jan 7, 2026
52979c4
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/…
JulienChampagnol Jan 7, 2026
4105e00
main run opengeodeweb_back
JulienChampagnol Jan 8, 2026
82af674
Apply prepare changes
JulienChampagnol Jan 8, 2026
0992929
wrapper function
JulienChampagnol Jan 8, 2026
4703ee9
Merge branch 'feat/extensions' of https://github.com/Geode-solutions/…
JulienChampagnol Jan 8, 2026
f75fd67
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
JulienChampagnol Jan 9, 2026
ed2eca6
Apply prepare changes
JulienChampagnol Jan 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions opengeodeweb_back_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,17 @@
"required": [],
"additionalProperties": false
},
"import_extension": {
"$id": "opengeodeweb_back/import_extension",
"route": "/import_extension",
"methods": [
"POST"
],
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
},
"geographic_coordinate_systems": {
"$id": "opengeodeweb_back/geographic_coordinate_systems",
"route": "/geographic_coordinate_systems",
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ werkzeug==3.1.2
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.0.10rc1
80 changes: 80 additions & 0 deletions src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,83 @@ def import_project() -> flask.Response:
except KeyError:
snapshot = {}
return flask.make_response({"snapshot": snapshot}, 200)


@routes.route(
schemas_dict["import_extension"]["route"],
methods=schemas_dict["import_extension"]["methods"],
)
def import_extension() -> flask.Response:
Comment thread
JulienChampagnol marked this conversation as resolved.
"""Import a .vext extension file and extract its contents."""
utils_functions.validate_request(flask.request, schemas_dict["import_extension"])

if "file" not in flask.request.files:
flask.abort(400, "No .vext file provided under 'file'")

vext_file = flask.request.files["file"]
assert vext_file.filename is not None
filename = werkzeug.utils.secure_filename(os.path.basename(vext_file.filename))

if not filename.lower().endswith(".vext"):
flask.abort(400, "Uploaded file must be a .vext")

# Create extensions directory in the data folder
data_folder_path: str = flask.current_app.config.get("DATA_FOLDER_PATH", "")
extensions_folder = os.path.join(data_folder_path, "extensions")
Comment thread
MaxNumerique marked this conversation as resolved.
Outdated
os.makedirs(extensions_folder, exist_ok=True)

# Extract extension name from filename (e.g., "vease-modeling-0.0.0.vext" -> "vease-modeling")
extension_name = (
filename.rsplit("-", 1)[0] if "-" in filename else filename.replace(".vext", "")
)
extension_path = os.path.join(extensions_folder, extension_name)

# Remove existing extension if present
if os.path.exists(extension_path):
shutil.rmtree(extension_path)

os.makedirs(extension_path, exist_ok=True)

# Extract the .vext file
vext_file.stream.seek(0)
with zipfile.ZipFile(vext_file.stream) as zip_archive:
zip_archive.extractall(extension_path)

# Find the extracted files
dist_path = os.path.join(extension_path, "dist")
if not os.path.exists(dist_path):
flask.abort(400, "Invalid .vext file: missing dist folder")

# Look for the backend executable and frontend JS
backend_executable = None
frontend_file = None

for file in os.listdir(dist_path):
file_path = os.path.join(dist_path, file)
if os.path.isfile(file_path):
if file.endswith(".es.js"):
frontend_file = file_path
elif not file.endswith(".js") and not file.endswith(".css"):
# Assume it's the backend executable
backend_executable = file_path
# Make it executable
os.chmod(backend_executable, 0o755)

if not frontend_file:
flask.abort(400, "Invalid .vext file: missing frontend JavaScript")
if not backend_executable:
flask.abort(400, "Invalid .vext file: missing backend executable")

# Read the frontend JS content
assert frontend_file is not None
with open(frontend_file, "r", encoding="utf-8") as f:
frontend_content = f.read()

return flask.make_response(
{
"extension_name": extension_name,
"frontend_content": frontend_content,
"backend_path": backend_executable,
},
200,
)
1 change: 1 addition & 0 deletions src/opengeodeweb_back/routes/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .kill import *
from .inspect_file import *
from .import_project import *
from .import_extension import *
from .geographic_coordinate_systems import *
from .geode_objects_and_output_extensions import *
from .export_project import *
Expand Down
10 changes: 10 additions & 0 deletions src/opengeodeweb_back/routes/schemas/import_extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"route": "/import_extension",
"methods": [
"POST"
],
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
10 changes: 10 additions & 0 deletions src/opengeodeweb_back/routes/schemas/import_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dataclasses_json import DataClassJsonMixin
from dataclasses import dataclass


@dataclass
class ImportExtension(DataClassJsonMixin):
def __post_init__(self) -> None:
print(self, flush=True)

pass
82 changes: 82 additions & 0 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,85 @@ def test_save_viewable_workflow_from_object(client: FlaskClient) -> None:
assert isinstance(data_id, str) and len(data_id) > 0
assert response.get_json()["geode_object_type"] == "EdgedCurve3D"
assert response.get_json()["viewable_file"].endswith(".vtp")


def test_import_extension_route(client: FlaskClient, tmp_path: Path) -> None:
"""Test importing a .vext extension file."""
route = "/opengeodeweb_back/import_extension"
original_data_folder = client.application.config["DATA_FOLDER_PATH"]
client.application.config["DATA_FOLDER_PATH"] = os.path.join(
str(tmp_path), "extension_test_data"
)
vext_path = tmp_path / "test-extension-1.0.0.vext"
with zipfile.ZipFile(vext_path, "w", compression=zipfile.ZIP_DEFLATED) as zipf:
zipf.writestr(
"dist/test-extension-extension.es.js",
"export const metadata = { id: 'test-extension', name: 'Test Extension' };",
)
zipf.writestr("dist/test-extension-back", "#!/bin/bash\necho 'mock backend'")
zipf.writestr("dist/test-extension.css", ".test { color: red; }")
with open(vext_path, "rb") as f:
response = client.post(
route,
data={"file": (f, "test-extension-1.0.0.vext")},
content_type="multipart/form-data",
)
assert response.status_code == 200
json_data = response.get_json()
assert "extension_name" in json_data
assert "frontend_content" in json_data
assert "backend_path" in json_data
assert json_data["extension_name"] == "test-extension"
extensions_folder = os.path.join(
client.application.config["DATA_FOLDER_PATH"], "extensions"
)
extension_path = os.path.join(extensions_folder, "test-extension")
assert os.path.exists(extension_path)
dist_path = os.path.join(extension_path, "dist")
assert os.path.exists(dist_path)

# Verify frontend content is returned
frontend_content = json_data["frontend_content"]
assert isinstance(frontend_content, str)
assert len(frontend_content) > 0
assert "export const metadata" in frontend_content

backend_exec = json_data["backend_path"]
assert os.path.exists(backend_exec)
assert os.access(backend_exec, os.X_OK)
client.application.config["DATA_FOLDER_PATH"] = original_data_folder


def test_import_extension_invalid_file(client: FlaskClient, tmp_path: Path) -> None:
"""Test importing an invalid .vext file (missing dist folder)."""
route = "/opengeodeweb_back/import_extension"
original_data_folder = client.application.config["DATA_FOLDER_PATH"]
client.application.config["DATA_FOLDER_PATH"] = os.path.join(
str(tmp_path), "extension_invalid_test"
)
vext_path = tmp_path / "invalid-extension.vext"
with zipfile.ZipFile(vext_path, "w") as zipf:
zipf.writestr("README.md", "This is invalid")
with open(vext_path, "rb") as f:
response = client.post(
route,
data={"file": (f, "invalid-extension.vext")},
content_type="multipart/form-data",
)
assert response.status_code == 400
client.application.config["DATA_FOLDER_PATH"] = original_data_folder


def test_import_extension_wrong_extension(client: FlaskClient, tmp_path: Path) -> None:
"""Test uploading a file with wrong extension."""
route = "/opengeodeweb_back/import_extension"
wrong_file = tmp_path / "not-an-extension.zip"
with open(wrong_file, "wb") as f:
f.write(b"test content")
with open(wrong_file, "rb") as f:
response = client.post(
route,
data={"file": (f, "not-an-extension.zip")},
content_type="multipart/form-data",
)
assert response.status_code == 400