Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 5 additions & 7 deletions specifyweb/backend/context/collection_resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from specifyweb.backend.context.app_resource import get_usertype
from specifyweb.specify.models import Spappresource, Spappresourcedir
from specifyweb.specify.views import openapi
from specifyweb.specify.views import openapi, login_maybe_required
from specifyweb.backend.context.resources import Resource, Resources

collection_resources = openapi(schema={
Expand Down Expand Up @@ -71,7 +69,7 @@
}
}
}
})(Resources.as_view(_spappresourcedirfilter= lambda request: {
})(login_maybe_required(Resources.as_view(_spappresourcedirfilter= lambda request: {
'ispersonal': False,
'specifyuser__isnull': True,
'usertype__isnull': True,
Expand All @@ -83,7 +81,7 @@
'specifyuser': request.specify_user
},_spappresourcedircreate=lambda request:{
'ispersonal': False
}))
})))


collection_resource = openapi(schema={
Expand Down Expand Up @@ -139,9 +137,9 @@
"204": {"description": "The resource was deleted.",}
}
}
})(Resource.as_view(_spappresourcefilter= lambda request: {
})(login_maybe_required(Resource.as_view(_spappresourcefilter= lambda request: {
'spappresourcedir__ispersonal': False,
}))
})))



Expand Down
49 changes: 30 additions & 19 deletions specifyweb/backend/inheritance/api.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from typing import Callable
from __future__ import annotations
from typing import TYPE_CHECKING, Callable, Iterable

from specifyweb.backend.inheritance.utils import get_cat_num_inheritance_setting, get_parent_cat_num_inheritance_setting
from specifyweb.specify.models import Collectionobjectgroupjoin, Component

# This likely isn't entirely needed, but there is little harm in this as
# QueryField is only needed as a type, so in the case there would be a cyclical
# import it would already be handled.
if TYPE_CHECKING:
from specifyweb.backend.stored_queries.queryfield import QueryField
Comment thread
melton-jason marked this conversation as resolved.
Dismissed


def do_nothing[T](items: T) -> T:
return items


def parent_inheritance_query_processor(tableid, field_specs, collection, user) -> Callable[[list], list]:
first_field_names = [fs.fieldspec.join_path[0].name for fs in field_specs if fs.fieldspec.join_path]
def parent_inheritance_query_processor(tableid: int, query_fields: "list[QueryField]", collection, user) -> Callable[[list], list]:
first_field_names = [qf.fieldspec.join_path[0].name for qf in query_fields if qf.fieldspec.join_path]
if tableid != 1029 or 'catalogNumber' not in first_field_names:
return do_nothing

Expand All @@ -20,7 +27,7 @@ def parent_inheritance_query_processor(tableid, field_specs, collection, user) -
catalog_number_field_index = first_field_names.index('catalogNumber') + 1

# op_num 1 is refering to the filter equal, the inheritance will only work if we have cat num equal, other operators will not function
if field_specs[catalog_number_field_index - 1].op_num != 1:
if query_fields[catalog_number_field_index - 1].op_num != 1:
return do_nothing

def _processor(row: list):
Expand All @@ -39,11 +46,11 @@ def _processor(row: list):
return _processor


def cog_inheritance_query_processor(tableid, field_specs, collection, user) -> Callable[[list], list]:
def cog_inheritance_query_processor(tableid: int, query_fields: list[QueryField], collection, user) -> Callable[[list], list]:
first_field_names = [
fs.fieldspec.join_path[0].name.lower()
for fs in field_specs
if fs.fieldspec.join_path
qf.fieldspec.join_path[0].name.lower()
for qf in query_fields
if qf.fieldspec.join_path
]
if tableid != 1 or 'catalognumber' not in first_field_names:
return do_nothing
Expand All @@ -55,7 +62,7 @@ def cog_inheritance_query_processor(tableid, field_specs, collection, user) -> C
catalog_number_field_index = first_field_names.index('catalognumber') + 1

# op_num 1 is refering to the filter equal, the inheritance will only work if we have cat num equal, other operators will not function
if field_specs[catalog_number_field_index - 1].op_num != 1:
if query_fields[catalog_number_field_index - 1].op_num != 1:
return do_nothing

# For a given result, replace null catalog numbers with the collection
Expand All @@ -81,15 +88,19 @@ def _processor(row: list):
return _processor


def DefaultQueryProcessors(tableid, field_specs, collection, user) -> list[Callable[[list], list]]:
visible_field_specs = list(filter(lambda qfield: qfield.display, field_specs))
kwargs = {
"tableid": tableid,
"field_specs": visible_field_specs,
"collection": collection,
"user": user
}
def DefaultQueryProcessors(tableid: int, query_fields: Iterable[QueryField], collection, user) -> list[Callable[[list], list]]:
visible_query_fields = list(filter(lambda qfield: qfield.display, query_fields))
return [
parent_inheritance_query_processor(**kwargs),
cog_inheritance_query_processor(**kwargs)
parent_inheritance_query_processor(
tableid=tableid,
query_fields=visible_query_fields,
collection=collection,
user=user
),
cog_inheritance_query_processor(
tableid=tableid,
query_fields=visible_query_fields,
collection=collection,
user=user
)
]
2 changes: 1 addition & 1 deletion specifyweb/backend/stored_queries/batch_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ def run_batch_edit_query(props: BatchEditProps):
series=False,
search_synonymy=False,
count_only=False,
field_specs=query_with_hidden,
query_fields=query_with_hidden,
limit=limit,
offset=offset,
recordsetid=recordsetid,
Expand Down
Loading
Loading