Skip to content

Commit

Permalink
Merge pull request #445 from uhh-lt/fix-mui-upgrade-issues
Browse files Browse the repository at this point in the history
Fix frontend issues
  • Loading branch information
bigabig authored Oct 15, 2024
2 parents 874687f + ff07a36 commit 04fc788
Show file tree
Hide file tree
Showing 100 changed files with 1,254 additions and 1,288 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""add id to timeline analysis filter
Revision ID: 312438bf1885
Revises: 5bcc9d14725a
Create Date: 2024-10-15 12:29:23.410076
"""

import uuid
from typing import Any, Sequence, Union

import sqlalchemy as sa
import srsly

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "312438bf1885"
down_revision: Union[str, None] = "5bcc9d14725a"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# we need to update all existing timeline analysis columns' concept field to include the id
conn = op.get_bind()
res = conn.execute(
sa.text("SELECT id, concepts FROM timelineanalysis WHERE concepts IS NOT NULL")
)

def add_id_to_filter(filter: Any):
filter["id"] = str(uuid.uuid4())
if "items" in filter:
for item in filter["items"]:
add_id_to_filter(item)

for row in res:
idx = row[0]
concepts = row[1]

concepts: Any = srsly.json_loads(concepts)
for concept in concepts:
add_id_to_filter(concept["filter"])

conn.execute(
sa.text(
"UPDATE timelineanalysis SET concepts = :concepts WHERE id = :id"
).bindparams(concepts=srsly.json_dumps(concepts), id=idx)
)


def downgrade() -> None:
pass
35 changes: 35 additions & 0 deletions backend/src/api/endpoints/document_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,41 @@ def set_document_tags_batch(
)


@router.patch(
"/bulk/update",
response_model=int,
summary="Updates SourceDocuments' tags",
)
def update_document_tags_batch(
*,
db: Session = Depends(get_db_session),
sdoc_ids: List[int],
unlink_tag_ids: List[int],
link_tag_ids: List[int],
authz_user: AuthzUser = Depends(),
validate: Validate = Depends(),
) -> int:
authz_user.assert_in_same_project_as_many(Crud.SOURCE_DOCUMENT, sdoc_ids)
authz_user.assert_in_same_project_as_many(Crud.DOCUMENT_TAG, link_tag_ids)

validate.validate_objects_in_same_project(
[(Crud.SOURCE_DOCUMENT, sdoc_id) for sdoc_id in sdoc_ids]
+ [(Crud.DOCUMENT_TAG, tag_id) for tag_id in link_tag_ids]
)

modifications = crud_document_tag.link_multiple_document_tags(
db=db,
sdoc_ids=sdoc_ids,
tag_ids=link_tag_ids,
)
modifications += crud_document_tag.unlink_multiple_document_tags(
db=db,
sdoc_ids=sdoc_ids,
tag_ids=unlink_tag_ids,
)
return modifications


@router.get(
"/{tag_id}",
response_model=DocumentTagRead,
Expand Down
13 changes: 2 additions & 11 deletions backend/src/api/endpoints/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def create_feedback(


@router.get(
"/{feedback_id}",
"/by_id/{feedback_id}",
response_model=FeedbackRead,
summary="Returns the Feedback with the given ID.",
)
Expand All @@ -60,7 +60,7 @@ def get_by_id(*, feedback_id: str, authz_user: AuthzUser = Depends()) -> Feedbac


@router.get(
"",
"/all",
response_model=List[FeedbackRead],
summary="Returns all Feedback items of the current user. If logged in as the system user, return feedback of all users.",
)
Expand All @@ -71,15 +71,6 @@ def get_all(authz_user: AuthzUser = Depends()) -> List[FeedbackRead]:
return RedisService().get_all_feedbacks_of_user(authz_user.user.id)


@router.get(
"/user",
response_model=List[FeedbackRead],
summary="Returns the Feedback of the logged-in User.",
)
def get_all_by_user(*, authz_user: AuthzUser = Depends()) -> List[FeedbackRead]:
return RedisService().get_all_feedbacks_of_user(authz_user.user.id)


@router.post(
"/reply_to/{feedback_id}",
response_model=str,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/api/endpoints/source_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def get_all_span_annotations_bulk(
*,
db: Session = Depends(get_db_session),
sdoc_id: int,
user_id: Annotated[list[int], Query()],
user_id: Annotated[List[int], Query(default_factory=list)],
resolve_code: bool = Depends(resolve_code_param),
authz_user: AuthzUser = Depends(),
) -> Union[List[SpanAnnotationRead], List[SpanAnnotationReadResolved]]:
Expand Down Expand Up @@ -411,7 +411,7 @@ def get_all_bbox_annotations_bulk(
*,
db: Session = Depends(get_db_session),
sdoc_id: int,
user_id: Annotated[list[int], Query()],
user_id: Annotated[List[int], Query(default_factory=list)],
skip_limit: Dict[str, int] = Depends(skip_limit_params),
resolve_code: bool = Depends(resolve_code_param),
authz_user: AuthzUser = Depends(),
Expand Down
20 changes: 11 additions & 9 deletions backend/src/app/core/data/crud/document_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def link_multiple_document_tags(
"""
Links all SDocs with all DocTags
"""
if len(sdoc_ids) == 0 or len(tag_ids) == 0:
return 0

# create before state
from app.core.data.crud.source_document import crud_sdoc
Expand Down Expand Up @@ -107,6 +109,9 @@ def unlink_multiple_document_tags(
"""
Unlinks all DocTags with all SDocs
"""
if len(sdoc_ids) == 0 or len(tag_ids) == 0:
return 0

# create before state
from app.core.data.crud.source_document import crud_sdoc

Expand Down Expand Up @@ -162,15 +167,12 @@ def set_document_tags(
add_tag_ids = list(set(tag_ids) - set(current_tag_ids))
del_tag_ids = list(set(current_tag_ids) - set(tag_ids))

modifications = 0
if len(del_tag_ids) > 0:
modifications += self.unlink_multiple_document_tags(
db, sdoc_ids=[sdoc_id], tag_ids=del_tag_ids
)
if len(add_tag_ids) > 0:
modifications += self.link_multiple_document_tags(
db, sdoc_ids=[sdoc_id], tag_ids=add_tag_ids
)
modifications = self.unlink_multiple_document_tags(
db, sdoc_ids=[sdoc_id], tag_ids=del_tag_ids
)
modifications += self.link_multiple_document_tags(
db, sdoc_ids=[sdoc_id], tag_ids=add_tag_ids
)

return modifications

Expand Down
2 changes: 2 additions & 0 deletions backend/src/app/core/filters/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def get_sqlalchemy_operator(self):


class FilterExpression(BaseModel, Generic[T]):
id: str
column: Union[T, int]
operator: Union[
IDOperator,
Expand Down Expand Up @@ -81,6 +82,7 @@ class Filter(BaseModel, Generic[T]):
"""A tree of column expressions for filtering on many database columns using various
comparisons."""

id: str
items: List[Union[FilterExpression[T], "Filter[T]"]]
logic_operator: LogicalOperator

Expand Down
Loading

0 comments on commit 04fc788

Please sign in to comment.