Skip to content

Commit

Permalink
fix: Include missing related drafts in IPR searches (#7836)
Browse files Browse the repository at this point in the history
* fix: Include missing related drafts in IPR searches

* refactor: extract drafts, sort docs

* chore: indent loop and conditionals to improve readability

* test: handle whitespaces added to IPR search result page

---------

Co-authored-by: Robert Sparks <[email protected]>
  • Loading branch information
microamp and rjsparks authored Sep 10, 2024
1 parent d8d52ee commit 80599f2
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
33 changes: 33 additions & 0 deletions ietf/ipr/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
RfcFactory,
NewRevisionDocEventFactory
)
from ietf.doc.utils import prettify_std_name
from ietf.group.factories import RoleFactory
from ietf.ipr.factories import (
HolderIprDisclosureFactory,
Expand Down Expand Up @@ -192,6 +193,38 @@ def test_search(self):
r = self.client.get(url + "?submit=rfc&rfc=321")
self.assertContains(r, ipr.title)

rfc_new = RfcFactory(rfc_number=322)
rfc_new.relateddocument_set.create(relationship_id="obs", target=rfc)

# find RFC 322 which obsoletes RFC 321 whose draft has IPR
r = self.client.get(url + "?submit=rfc&rfc=322")
self.assertContains(r, ipr.title)
self.assertContains(r, "Total number of IPR disclosures found: <b>1</b>")
self.assertContains(r, "Total number of documents searched: <b>3</b>.")
self.assertContains(
r,
f"""Results for <a href="/doc/{rfc_new.name}/">{prettify_std_name(rfc_new.name)}</a>
("{rfc_new.title}")""",
)
self.assertContains(
r,
f"""Results for <a href="/doc/{rfc.name}/">{prettify_std_name(rfc.name)}</a>
("{rfc.title}"), which
was obsoleted by
<a href="/doc/{rfc_new.name}/">{prettify_std_name(rfc_new.name)}</a>
("{rfc_new.title}")""",
)
self.assertContains(
r,
f"""Results for <a href="/doc/{draft.name}/">{prettify_std_name(draft.name)}</a>
("{draft.title}"), which
became rfc
<a href="/doc/{rfc.name}/">{prettify_std_name(rfc.name)}</a>
("{rfc.title}")""",
)

# find by patent owner
r = self.client.get(url + "?submit=holder&holder=%s" % ipr.holder_legal_name)
self.assertContains(r, ipr.title)
Expand Down
38 changes: 34 additions & 4 deletions ietf/ipr/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,41 @@ def search(request):
if len(start) == 1:
first = start[0]
doc = first
docs = related_docs(first)
iprs = iprs_from_docs(docs,states=states)
docs = set([first])
docs.update(
related_docs(
first, relationship=("replaces", "obs"), reverse_relationship=()
)
)
docs.update(
set(
[
draft
for drafts in [
related_docs(
d, relationship=(), reverse_relationship=("became_rfc",)
)
for d in docs
]
for draft in drafts
]
)
)
docs.discard(None)
docs = sorted(
docs,
key=lambda d: (
d.rfc_number if d.rfc_number is not None else 0,
d.became_rfc().rfc_number if d.became_rfc() else 0,
),
reverse=True,
)
iprs = iprs_from_docs(docs, states=states)
template = "ipr/search_doc_result.html"
updated_docs = related_docs(first, ('updates',))
related_iprs = list(set(iprs_from_docs(updated_docs, states=states)) - set(iprs))
updated_docs = related_docs(first, ("updates",))
related_iprs = list(
set(iprs_from_docs(updated_docs, states=states)) - set(iprs)
)
# multiple matches, select just one
elif start:
docs = start
Expand Down
19 changes: 15 additions & 4 deletions ietf/templates/ipr/search_doc_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,27 @@
</tr>
</thead>

{% for doc in docs %}
{% for d in docs %}
<tbody>
<tr>
<th scope="col" class="table-info" colspan="3">
Results for {{ doc.name|prettystdname|urlize_ietf_docs }} ("{{ doc.title }}"){% if not forloop.first %}{% if doc.related %}, which was {{ doc.relation|lower }} {{ doc.related.source|prettystdname|urlize_ietf_docs }} ("{{ doc.related.source.title }}"){% endif %}{% endif %}
Results for {{ d.name|prettystdname|urlize_ietf_docs }}
("{{ d.title }}"){% if d != doc and d.related %}, which
{% if d == d.related.source %}
{{ d.relation|lower }}
{{ d.related.target|prettystdname|urlize_ietf_docs }}
("{{ d.related.target.title }}")
{% else %}
was {{ d.relation|lower }}
{{ d.related.source|prettystdname|urlize_ietf_docs }}
("{{ d.related.source.title }}")
{% endif %}
{% endif %}
</th>
</tr>
</tbody>
<tbody>
{% with doc.iprdocrel_set.all as doc_iprs %}
{% with d.iprdocrel_set.all as doc_iprs %}
{% if doc_iprs %}
{% for ipr in doc_iprs %}
{% if ipr.disclosure.state_id in states %}
Expand All @@ -81,7 +92,7 @@
<td></td>
<td></td>
<td>
No IPR disclosures have been submitted directly on {{ doc.name|prettystdname|urlize_ietf_docs }}{% if iprs %},
No IPR disclosures have been submitted directly on {{ d.name|prettystdname|urlize_ietf_docs }}{% if iprs %},
but there are disclosures on {% if docs|length == 2 %}a related document{% else %}related documents{% endif %}, listed on this page{% endif %}.
</td>
</tr>
Expand Down

0 comments on commit 80599f2

Please sign in to comment.