Skip to content

Commit

Permalink
Merge pull request #10308 from archesproject/10307-6_concept_outside_…
Browse files Browse the repository at this point in the history
…collection

Prevent concept widget from allowing selection of concepts outside collection
  • Loading branch information
johnatawnclementawn authored Nov 29, 2023
2 parents 981bd1b + 990e742 commit d87c16e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
8 changes: 8 additions & 0 deletions arches/app/models/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,13 @@ def get_child_edges(
FROM children c
JOIN values ON(values.conceptid = c.conceptidto)
WHERE LOWER(values.value) like %(query)s
AND values.valuetype in ('prefLabel')
AND LOWER(values.value) != %(match)s
UNION
SELECT c.conceptidfrom, c.conceptidto, '0' as row, c.depth, c.collector
FROM children c
JOIN values ON(values.conceptid = c.conceptidto)
WHERE LOWER(values.value) = %(match)s
AND values.valuetype in ('prefLabel')
UNION
SELECT c.conceptidfrom, c.conceptidto, c.row, c.depth, c.collector
Expand All @@ -662,6 +669,7 @@ def get_child_edges(
"limit": limit,
"offset": offset,
"query": "%" + query.lower() + "%",
"match": query.lower(),
"recursive_table": AsIs(recursive_table),
"languageid": languageid,
"short_languageid": languageid.split("-")[0] + "%",
Expand Down
37 changes: 0 additions & 37 deletions arches/app/views/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,43 +392,6 @@ def paged_dropdown(request):
for d in data
]

# This try/except block trys to find an exact match to the concept the user is searching and if found
# it will insert it into the results as the first item so that users don't have to scroll to find it.
# See: https://github.com/archesproject/arches/issues/8355
try:
if page == 1:
found = False
for i, d in enumerate(data):
if i <= 7 and d["text"].lower() == query.lower():
found = True
break
if not found:
languageid = get_language().lower()
cursor = connection.cursor()
cursor.execute(
"""
SELECT value, valueid
FROM
(
SELECT *, CASE WHEN LOWER(languageid) = %(languageid)s THEN 10
WHEN LOWER(languageid) like %(short_languageid)s THEN 5
ELSE 0
END score
FROM values
) as vals
WHERE LOWER(value)=%(query)s AND score > 0
AND valuetype in ('prefLabel')
ORDER BY score desc limit 1
""",
{"languageid": languageid, "short_languageid": languageid.split("-")[0] + "%", "query": query.lower()},
)
rows = cursor.fetchall()

if len(rows) == 1:
data.insert(0, {"id": str(rows[0][1]), "text": rows[0][0], "depth": 1, "collector": False})
except:
pass

return JSONResponse({"results": data, "more": offset + limit < total_count})


Expand Down

0 comments on commit d87c16e

Please sign in to comment.