Skip to content

Commit

Permalink
Merge pull request #12 from Muster-Suchen-und-Erkennen/update-depende…
Browse files Browse the repository at this point in the history
…ncies

Update dependencies
  • Loading branch information
pilotfritz98 authored Jul 30, 2024
2 parents c25f582 + 476abf5 commit 34f98f6
Show file tree
Hide file tree
Showing 37 changed files with 1,146 additions and 850 deletions.
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
autosectionlabel_prefix_document = False
autosectionlabel_maxdepth = None

intersphinx_mapping: Optional[
Dict[str, Tuple[str, Union[Optional[str], Tuple[str]]]]
] = None
intersphinx_mapping: Optional[Dict[str, Tuple[str, Union[Optional[str], Tuple[str]]]]] = (
None
)
intersphinx_timeout = 30

source_suffix = {
Expand Down
15 changes: 8 additions & 7 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import logging
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context
from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -23,9 +21,8 @@
# target_metadata = mymodel.Base.metadata
from flask import current_app

current_app.config[
"SQLITE_FOREIGN_KEYS"
] = False # do NOT use foreign key checking when updating DB
# do NOT use foreign key checking when updating DB
current_app.config["SQLITE_FOREIGN_KEYS"] = False
config.set_main_option(
"sqlalchemy.url",
str(current_app.extensions["migrate"].db.engine.url).replace("%", "%%"),
Expand Down Expand Up @@ -84,13 +81,17 @@ def process_revision_directives(context, revision, directives):
)

with connectable.connect() as connection:
extra_kwargs = dict(current_app.extensions["migrate"].configure_args)
# remove duplicate args from extra config
extra_kwargs.pop("compare_type", None)
extra_kwargs.pop("render_as_batch", None)
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
render_as_batch=True,
compare_type=True,
**current_app.extensions["migrate"].configure_args
**extra_kwargs,
)

with context.begin_transaction():
Expand Down
1 change: 1 addition & 0 deletions migrations/versions/a18bebd2bb1a_initial_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Revision ID: a18bebd2bb1a
Create Date: 2021-09-19 20:16:31.258752
"""

from alembic import op
import sqlalchemy as sa

Expand Down
1 change: 1 addition & 0 deletions muse_for_anything/api/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing utilities for flask smorest APIs."""

from typing import Any, Dict
from flask import url_for
from flask_smorest import Blueprint
Expand Down
4 changes: 3 additions & 1 deletion muse_for_anything/api/v1_api/generators/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ def generate_api_object(
return

return NamespaceData(
self=LinkGenerator.get_link_of(resource, query_params=query_params, ignore_deleted=True),
self=LinkGenerator.get_link_of(
resource, query_params=query_params, ignore_deleted=True
),
name=resource.name,
description=resource.description,
created_on=resource.created_on,
Expand Down
4 changes: 3 additions & 1 deletion muse_for_anything/api/v1_api/generators/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ def generate_api_object(
return

return ObjectData(
self=LinkGenerator.get_link_of(resource, query_params=query_params, ignore_deleted=True),
self=LinkGenerator.get_link_of(
resource, query_params=query_params, ignore_deleted=True
),
name=resource.name,
description=resource.description,
created_on=resource.created_on,
Expand Down
8 changes: 4 additions & 4 deletions muse_for_anything/api/v1_api/generators/object_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ def update_key(
return key


class ObjectVersionSelfLinkGenerator(
LinkGenerator, resource_type=OntologyObjectVersion
):
class ObjectVersionSelfLinkGenerator(LinkGenerator, resource_type=OntologyObjectVersion):
def generate_link(
self,
resource: OntologyObjectVersion,
Expand Down Expand Up @@ -199,7 +197,9 @@ def generate_api_object(
return

return ObjectData(
self=LinkGenerator.get_link_of(resource, query_params=query_params, ignore_deleted=True),
self=LinkGenerator.get_link_of(
resource, query_params=query_params, ignore_deleted=True
),
name=resource.name,
description=resource.description,
created_on=resource.created_on,
Expand Down
4 changes: 3 additions & 1 deletion muse_for_anything/api/v1_api/generators/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ def generate_api_object(
return

return TaxonomyData(
self=LinkGenerator.get_link_of(resource, query_params=query_params, ignore_deleted=True),
self=LinkGenerator.get_link_of(
resource, query_params=query_params, ignore_deleted=True
),
name=resource.name,
description=resource.description,
created_on=resource.created_on,
Expand Down
4 changes: 3 additions & 1 deletion muse_for_anything/api/v1_api/generators/taxonomy_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ def generate_api_object(
]

return TaxonomyItemData(
self=LinkGenerator.get_link_of(resource, query_params=query_params, ignore_deleted=True),
self=LinkGenerator.get_link_of(
resource, query_params=query_params, ignore_deleted=True
),
name=resource.name,
description=resource.description,
sort_key=resource.sort_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def generate_api_object(
return

return TaxonomyItemRelationData(
self=LinkGenerator.get_link_of(resource, query_params=query_params, ignore_deleted=True),
self=LinkGenerator.get_link_of(
resource, query_params=query_params, ignore_deleted=True
),
source_item=LinkGenerator.get_link_of(resource.taxonomy_item_source),
target_item=LinkGenerator.get_link_of(resource.taxonomy_item_target),
created_on=resource.created_on,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ def generate_api_object(
]

return TaxonomyItemData(
self=LinkGenerator.get_link_of(resource, query_params=query_params, ignore_deleted=True),
self=LinkGenerator.get_link_of(
resource, query_params=query_params, ignore_deleted=True
),
name=resource.name,
description=resource.description,
sort_key=resource.sort_key,
Expand Down
8 changes: 6 additions & 2 deletions muse_for_anything/api/v1_api/generators/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ def generate_link(
return
link = LinkGenerator.get_link_of(CollectionResource(UserRole, resource=resource))
link.rel = (CREATE_REL, POST_REL, REQUIRES_FRESH_LOGIN_REL)
link.schema = url_for(SCHEMA_RESOURCE, schema_id=USER_ROLE_POST_SCHEMA, _external=True)
link.schema = url_for(
SCHEMA_RESOURCE, schema_id=USER_ROLE_POST_SCHEMA, _external=True
)
return link


Expand All @@ -271,7 +273,9 @@ def generate_api_object(
return

return UserData(
self=LinkGenerator.get_link_of(resource, query_params=query_params, ignore_deleted=True),
self=LinkGenerator.get_link_of(
resource, query_params=query_params, ignore_deleted=True
),
username=resource.username,
e_mail=resource.e_mail,
)
Expand Down
32 changes: 24 additions & 8 deletions muse_for_anything/api/v1_api/models/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class DeletedPageSchemaMixin:
deleted = ma.fields.Boolean(required=False, allow_none=True, missing=False)


class NamespacePageParamsSchema(SearchPageSchemaMixin, DeletedPageSchemaMixin, CursorPageArgumentsSchema):
class NamespacePageParamsSchema(
SearchPageSchemaMixin, DeletedPageSchemaMixin, CursorPageArgumentsSchema
):
pass


Expand Down Expand Up @@ -128,11 +130,15 @@ class FileExportData(BaseApiObject):
content_type: str = "application/xml"


class ObjectTypePageParamsSchema(CursorPageArgumentsSchema, SearchPageSchemaMixin, DeletedPageSchemaMixin):
class ObjectTypePageParamsSchema(
CursorPageArgumentsSchema, SearchPageSchemaMixin, DeletedPageSchemaMixin
):
pass


class ObjectTypeVersionsPageParamsSchema(CursorPageArgumentsSchema, DeletedPageSchemaMixin):
class ObjectTypeVersionsPageParamsSchema(
CursorPageArgumentsSchema, DeletedPageSchemaMixin
):
pass


Expand Down Expand Up @@ -171,15 +177,21 @@ class ObjectData(BaseApiObject, ChangesDataMixin, NameDescriptionMixin):
data: Any


class ObjectsCursorPageArgumentsSchema(CursorPageArgumentsSchema, DeletedPageSchemaMixin, SearchPageSchemaMixin):
class ObjectsCursorPageArgumentsSchema(
CursorPageArgumentsSchema, DeletedPageSchemaMixin, SearchPageSchemaMixin
):
type_id = ma.fields.String(data_key="type-id", allow_none=True, load_only=True)


class ObjectVersionsCursorPageArgumentsSchema(CursorPageArgumentsSchema, DeletedPageSchemaMixin):
class ObjectVersionsCursorPageArgumentsSchema(
CursorPageArgumentsSchema, DeletedPageSchemaMixin
):
pass


class TaxonomyPageParamsSchema(CursorPageArgumentsSchema, SearchPageSchemaMixin, DeletedPageSchemaMixin):
class TaxonomyPageParamsSchema(
CursorPageArgumentsSchema, SearchPageSchemaMixin, DeletedPageSchemaMixin
):
pass


Expand All @@ -200,11 +212,15 @@ class TaxonomyData(BaseApiObject, ChangesDataMixin, NameDescriptionMixin):
items: Sequence[ApiLink] = tuple()


class TaxonomyItemPageParamsSchema(CursorPageArgumentsSchema, SearchPageSchemaMixin, DeletedPageSchemaMixin):
class TaxonomyItemPageParamsSchema(
CursorPageArgumentsSchema, SearchPageSchemaMixin, DeletedPageSchemaMixin
):
pass


class TaxonomyItemVersionsPageParamsSchema(CursorPageArgumentsSchema, DeletedPageSchemaMixin):
class TaxonomyItemVersionsPageParamsSchema(
CursorPageArgumentsSchema, DeletedPageSchemaMixin
):
pass


Expand Down
4 changes: 2 additions & 2 deletions muse_for_anything/api/v1_api/namespace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module containing the namespace API endpoints of the v1 API."""

from datetime import datetime
from datetime import datetime, timezone
from http import HTTPStatus
from typing import Any, List, Optional

Expand Down Expand Up @@ -396,7 +396,7 @@ def delete(self, namespace: str):
# only actually delete when not already deleted
if found_namespace.deleted_on is None:
# soft delete namespace
found_namespace.deleted_on = datetime.utcnow()
found_namespace.deleted_on = datetime.now(timezone.utc)
DB.session.add(found_namespace)
DB.session.commit()

Expand Down
31 changes: 19 additions & 12 deletions muse_for_anything/api/v1_api/ontology_object_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from dataclasses import dataclass

from urllib.parse import urlparse

from muse_for_anything.db.models.taxonomies import TaxonomyItem
from flask.globals import _request_ctx_stack
from werkzeug.urls import url_parse
from flask.globals import request_ctx
from werkzeug.routing import MapAdapter

from http import HTTPStatus
Expand Down Expand Up @@ -36,12 +37,18 @@ class ObjectMetadata:
def resolve_type_version_schema_url(url_string: str):
"""Resolver url references without creating any http request by directly querying the database."""
# TODO use url cache
url = url_parse(url_string)
url = urlparse(url_string)
# url should already be from a validated type!
ctx = _request_ctx_stack.top
if ctx is None:
try:
ctx = request_ctx._get_current_object()
except RuntimeError:
raise DataVisitorException("No request context to check schema url against!")
url_adapter: MapAdapter = ctx.url_adapter
url_adapter: Optional[MapAdapter] = ctx.url_adapter
if url_adapter is None:
raise DataVisitorException(
"No url adapter found in request context! Unable to check URL."
f"URL: '{url}'"
)
if url.netloc != url_adapter.get_host(None):
raise DataVisitorException(
"Only references to schemas on the same MUSE4Anything instance allowed! "
Expand All @@ -62,12 +69,12 @@ def resolve_type_version_schema_url(url_string: str):
version: str = params.get("version")
if endpoint == "api-v1.TypeVersionView":

found_type_version: Optional[
OntologyObjectTypeVersion
] = OntologyObjectTypeVersion.query.filter(
OntologyObjectTypeVersion.version == int(version),
OntologyObjectTypeVersion.object_type_id == int(object_type),
).first()
found_type_version: Optional[OntologyObjectTypeVersion] = (
OntologyObjectTypeVersion.query.filter(
OntologyObjectTypeVersion.version == int(version),
OntologyObjectTypeVersion.object_type_id == int(object_type),
).first()
)

if found_type_version is None:
raise DataVisitorException(f"Invalid schema ref! Schema '{url}' not found!")
Expand Down
4 changes: 2 additions & 2 deletions muse_for_anything/api/v1_api/ontology_objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module containing the object API endpoints of the v1 API."""

from datetime import datetime
from datetime import datetime, timezone
from http import HTTPStatus
from typing import Any, List, Optional

Expand Down Expand Up @@ -651,7 +651,7 @@ def delete(self, namespace: str, object_id: str):
# only actually delete when not already deleted
if found_object.deleted_on is None:
# soft delete object
found_object.deleted_on = datetime.utcnow()
found_object.deleted_on = datetime.now(timezone.utc)
# TODO soft delete komposition objects (also implement undelete…)
DB.session.add(found_object)
DB.session.commit()
Expand Down
Loading

0 comments on commit 34f98f6

Please sign in to comment.