From ad5aef491f5f993e212688fc07c0062ea9034169 Mon Sep 17 00:00:00 2001 From: Severin Beauvais Date: Thu, 3 Dec 2026 17:08:12 +0000 Subject: [PATCH 1/5] fix(strr-api): count provisionally approved renewals as approved in the 409 check and /todos (REGBACKLOG-391) A renewal in PROVISIONAL_REVIEW, or in one of its NOC statuses, has already extended the registration, but the 409 check treated it as in progress. It refused the host's next renewal with RENEWAL_ALREADY_IN_PROGRESS, whenever that one was submitted, while /todos still offered Renew. - Add RENEWAL_APPROVED_STATES (including the provisional statuses), RENEWAL_DECLINED_STATES and RENEWAL_FINISHED_STATES; the 409 check now refuses a new renewal only while another is in neither list - /todos hides Renew while a renewal is in progress, whenever it was submitted, matching the 409 check, or once a renewal submitted in this window is approved, provisionally or in full - Bump strr-api to 0.3.50 --- strr-api/pyproject.toml | 2 +- strr-api/src/strr_api/models/application.py | 6 ++-- .../src/strr_api/resources/application.py | 11 ++++--- .../src/strr_api/resources/registrations.py | 31 +++++++++++------- .../strr_api/services/application_service.py | 13 ++++++++ .../unit/resources/test_registrations.py | 2 ++ .../unit/resources/test_renewal_todos_api.py | 17 +++++++--- .../unit/resources/test_renewal_window_api.py | 32 +++++++++++++++++++ 8 files changed, 91 insertions(+), 23 deletions(-) diff --git a/strr-api/pyproject.toml b/strr-api/pyproject.toml index 102c71901..3622256cc 100644 --- a/strr-api/pyproject.toml +++ b/strr-api/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "strr-api" -version = "0.3.49" +version = "0.3.50" description = "" authors = ["thorwolpert "] license = "BSD 3-Clause" diff --git a/strr-api/src/strr_api/models/application.py b/strr-api/src/strr_api/models/application.py index faefba428..de5a23ba0 100644 --- a/strr-api/src/strr_api/models/application.py +++ b/strr-api/src/strr_api/models/application.py @@ -348,9 +348,9 @@ def find_non_terminal_renewal_for_payment_account( cls, payment_account: str | int | None, registration_id: int, - terminal_status_values: tuple[str, ...], + finished_status_values: tuple[str, ...], ) -> Application | None: - """Return a renewal for this account+registration that is not in a terminal status, if any.""" + """Return a renewal for this account+registration that is not in one of the finished statuses, if any.""" if payment_account is None: return None return ( @@ -358,7 +358,7 @@ def find_non_terminal_renewal_for_payment_account( cls.type == ApplicationType.RENEWAL.value, cls.registration_id == registration_id, cls.payment_account == str(payment_account), - ~cls.status.in_(terminal_status_values), + ~cls.status.in_(finished_status_values), ) .order_by(cls.id.desc()) .first() diff --git a/strr-api/src/strr_api/resources/application.py b/strr-api/src/strr_api/resources/application.py index 09c5c863c..3d4a707ed 100644 --- a/strr-api/src/strr_api/resources/application.py +++ b/strr-api/src/strr_api/resources/application.py @@ -79,6 +79,7 @@ APPLICATION_STATES_STAFF_ACTION, APPLICATION_TERMINAL_STATES, APPLICATION_UNPAID_STATES, + RENEWAL_FINISHED_STATES, ) from strr_api.services.examiner_note_service import ExaminerNoteNotAllowedException, ExaminerNoteService from strr_api.utils.renewal_window import RenewalWindow @@ -144,8 +145,9 @@ def create_application(application_number: Optional[str] = None): description: Application not found (when path includes application_number). 409: description: > - Renewal conflict — pathless POST /applications for renewal when a non-terminal renewal - already exists for the same registration and Account-Id (errorCode RENEWAL_ALREADY_IN_PROGRESS). + Renewal conflict — pathless POST /applications for renewal when a renewal that is neither approved + (provisionally or in full) nor declined already exists for the same registration and Account-Id + (errorCode RENEWAL_ALREADY_IN_PROGRESS). 402: description: Payment required (e.g. invoice creation failed on final submit). 502: @@ -227,9 +229,10 @@ def create_application(application_number: Optional[str] = None): ) if application is None: - terminal_status_values = tuple(s.value for s in APPLICATION_TERMINAL_STATES) + # A provisionally approved renewal has extended the registration, so it doesn't block the next one + finished_status_values = tuple(s.value for s in RENEWAL_FINISHED_STATES) conflicting = ApplicationModel.find_non_terminal_renewal_for_payment_account( - account_id, registration_id, terminal_status_values + account_id, registration_id, finished_status_values ) if conflicting: logger.info( diff --git a/strr-api/src/strr_api/resources/registrations.py b/strr-api/src/strr_api/resources/registrations.py index c2b7aa1ec..754f3f938 100644 --- a/strr-api/src/strr_api/resources/registrations.py +++ b/strr-api/src/strr_api/resources/registrations.py @@ -45,6 +45,7 @@ from flasgger import swag_from from flask import Blueprint, current_app, g, jsonify, request, send_file from flask_cors import cross_origin +from sqlalchemy import and_, or_ from werkzeug.utils import secure_filename from strr_api.common.auth import jwt @@ -76,6 +77,7 @@ SnapshotService, UserService, ) +from strr_api.services.application_service import RENEWAL_APPROVED_STATES, RENEWAL_FINISHED_STATES from strr_api.services.examiner_note_service import ExaminerNoteNotAllowedException, ExaminerNoteService from strr_api.services.registration_service import ( REGISTRATION_STATES_STAFF_ACTION, @@ -726,22 +728,29 @@ def get_todos(registration_id): ) todos.append({"task": {"type": todo_type, "detail": renewal_application.application_number}}) else: - # Renew is hidden once a renewal has been submitted in this window. A declined renewal doesn't - # count, so the host can renew again; create_application's 409 check also accepts a new renewal - # after a declined one, because APPLICATION_TERMINAL_STATES includes both declined statuses. + # Renew is hidden while a submitted renewal is still in progress, whenever it was submitted, as + # create_application's 409 check refuses a new renewal then. It's also hidden once a renewal + # submitted in this window is approved, provisionally or in full; an approval from an earlier + # window doesn't count. A declined renewal never counts, so the host can renew again. + finished_statuses = [status.value for status in RENEWAL_FINISHED_STATES] + approved_statuses = [status.value for status in RENEWAL_APPROVED_STATES] submitted_renewal_application = ( Application.query.filter( Application.registration_id == registration.id, Application.type == ApplicationType.RENEWAL.value, - Application.status.notin_( - [ - Application.Status.DRAFT.value, - Application.Status.PAYMENT_DUE.value, - Application.Status.DECLINED.value, - Application.Status.PROVISIONALLY_DECLINED.value, - ] + or_( + Application.status.notin_( + [ + Application.Status.DRAFT.value, + Application.Status.PAYMENT_DUE.value, + *finished_statuses, + ] + ), + and_( + Application.status.in_(approved_statuses), + Application.application_date >= renewal_window.start_utc, + ), ), - Application.application_date >= renewal_window.start_utc, ) .order_by(Application.application_date.desc()) .first() diff --git a/strr-api/src/strr_api/services/application_service.py b/strr-api/src/strr_api/services/application_service.py index 7b73ff68b..db28f5556 100644 --- a/strr-api/src/strr_api/services/application_service.py +++ b/strr-api/src/strr_api/services/application_service.py @@ -66,6 +66,19 @@ Application.Status.ADDITIONAL_INFO_REQUESTED, ] APPLICATION_UNPAID_STATES = [Application.Status.DRAFT, Application.Status.PAYMENT_DUE] +# A renewal in one of these statuses has extended the registration. Provisional approval (PROVISIONAL_REVIEW, and its +# NOC statuses) extends it at once, even though an examiner may still review it, so it counts as approved too. +RENEWAL_APPROVED_STATES = [ + Application.Status.FULL_REVIEW_APPROVED, + Application.Status.PROVISIONALLY_APPROVED, + Application.Status.AUTO_APPROVED, + Application.Status.PROVISIONAL_REVIEW, + Application.Status.PROVISIONAL_REVIEW_NOC_PENDING, + Application.Status.PROVISIONAL_REVIEW_NOC_EXPIRED, +] +RENEWAL_DECLINED_STATES = [Application.Status.DECLINED, Application.Status.PROVISIONALLY_DECLINED] +# A renewal in any other status is still in progress, and blocks a new one +RENEWAL_FINISHED_STATES = RENEWAL_APPROVED_STATES + RENEWAL_DECLINED_STATES APPLICATION_ASSIGN_STATES = [ Application.Status.FULL_REVIEW, Application.Status.PROVISIONAL_REVIEW, diff --git a/strr-api/tests/unit/resources/test_registrations.py b/strr-api/tests/unit/resources/test_registrations.py index 86c58c2f5..06012564b 100644 --- a/strr-api/tests/unit/resources/test_registrations.py +++ b/strr-api/tests/unit/resources/test_registrations.py @@ -833,6 +833,8 @@ def test_get_todos_with_submitted_renewal_recent_and_old(app, session, client, j response_json = rv.json assert response_json.get("todos") == [] + # Last year's renewal, approved: it doesn't hide Renew in this window + recent_application.status = Application.Status.FULL_REVIEW_APPROVED recent_application.application_date = datetime.utcnow() - relativedelta(years=1) - timedelta(days=41) recent_application.save() diff --git a/strr-api/tests/unit/resources/test_renewal_todos_api.py b/strr-api/tests/unit/resources/test_renewal_todos_api.py index 513f6081b..1ee7f1078 100644 --- a/strr-api/tests/unit/resources/test_renewal_todos_api.py +++ b/strr-api/tests/unit/resources/test_renewal_todos_api.py @@ -34,14 +34,23 @@ def test_todos_window_is_open(client, renewal_headers, make_registration): @pytest.mark.parametrize( "status, seconds_after_window_start, renew_offered", [ - (Application.Status.PAID, 0, False), # submitted as the window opened - (Application.Status.FULL_REVIEW_APPROVED, 86400, False), # submitted in this window - (Application.Status.PAID, -1, True), # submitted before this window, eg for the previous one + (Application.Status.PAID, 0, False), # in progress, submitted as the window opened + (Application.Status.PAID, -1, False), # in progress, submitted before this window: a new one would get 409 + (Application.Status.ADDITIONAL_INFO_REQUESTED, -30 * 86400, False), + (Application.Status.NOC_PENDING, -1, False), + (Application.Status.FULL_REVIEW_APPROVED, 86400, False), # approved, submitted in this window + (Application.Status.AUTO_APPROVED, 0, False), + (Application.Status.PROVISIONAL_REVIEW, 0, False), # approved provisionally, in this window + (Application.Status.FULL_REVIEW_APPROVED, -1, True), # approved, submitted before this window + (Application.Status.PROVISIONALLY_APPROVED, -1, True), + (Application.Status.PROVISIONAL_REVIEW, -1, True), # approved provisionally, before this window + (Application.Status.PROVISIONAL_REVIEW_NOC_PENDING, -1, True), + (Application.Status.PROVISIONAL_REVIEW_NOC_EXPIRED, -1, True), (Application.Status.DECLINED, 86400, True), # declined: the host can renew again (Application.Status.PROVISIONALLY_DECLINED, 86400, True), ], ) -def test_todos_renew_hidden_only_after_a_submission_in_this_window( +def test_todos_renew_hidden_while_in_progress_or_approved_in_this_window( client, renewal_headers, make_registration, make_renewal, status, seconds_after_window_start, renew_offered ): registration = make_registration(20) diff --git a/strr-api/tests/unit/resources/test_renewal_window_api.py b/strr-api/tests/unit/resources/test_renewal_window_api.py index 6ffd97cf7..9fa02ba6d 100644 --- a/strr-api/tests/unit/resources/test_renewal_window_api.py +++ b/strr-api/tests/unit/resources/test_renewal_window_api.py @@ -126,3 +126,35 @@ def test_renewal_is_refused_after_window_closes( assert rv.json["errorCode"] == "RENEWAL_WINDOW_CLOSED" assert Application.query.filter_by(registration_id=registration.id).count() == 0 assert mock_invoice.call_count == int(accepted and not is_draft) + + +@pytest.mark.parametrize( + "status, conflict", + [ + (Application.Status.DRAFT, True), + (Application.Status.PAID, True), + (Application.Status.FULL_REVIEW, True), + (Application.Status.NOC_PENDING, True), + (Application.Status.PROVISIONAL_REVIEW, False), # approved provisionally: the registration was extended + (Application.Status.PROVISIONAL_REVIEW_NOC_PENDING, False), + (Application.Status.PROVISIONAL_REVIEW_NOC_EXPIRED, False), + (Application.Status.AUTO_APPROVED, False), + (Application.Status.DECLINED, False), + ], +) +@patch("strr_api.services.strr_pay.create_invoice", return_value=MOCK_INVOICE_RESPONSE) +def test_new_renewal_is_refused_only_while_one_is_in_progress( + mock_invoice, client, renewal_headers, make_registration, make_renewal, status, conflict +): + with open(HOST_REGISTRATION) as f: + base_json = json.load(f) + registration = make_registration(20) + make_renewal(registration, status) # eg the previous cycle's renewal + payload = host_renewal_application_json(registration.id, base_json=base_json) + + rv = client.post("/applications", json=payload, headers={**renewal_headers, "isDraft": True}) + + assert rv.status_code == (HTTPStatus.CONFLICT if conflict else HTTPStatus.OK) + if conflict: + assert rv.json["errorCode"] == "RENEWAL_ALREADY_IN_PROGRESS" + assert Application.query.filter_by(registration_id=registration.id).count() == (1 if conflict else 2) From dd2257abf2f9fd882440fe5db482cbb1ee7a09bc Mon Sep 17 00:00:00 2001 From: Severin Beauvais Date: Thu, 3 Dec 2026 17:51:28 +0000 Subject: [PATCH 2/5] fix(strr-api): keep older provisional renewals in the reviewRenew queue (REGBACKLOG-391) Now that a provisionally approved renewal no longer blocks the next one, a newer renewal (even a draft) became the registration's latest application and hid the older renewal from reviewRenew=true. The queue now matches a registration with no registration-level decider when any of its renewals is in PROVISIONAL_REVIEW or PROVISIONALLY_APPROVED with no decider. Adds a regression test for an older provisional renewal followed by a newer DRAFT or AUTO_APPROVED renewal. --- strr-api/src/strr_api/models/rental.py | 60 ++++++++++--------- .../src/strr_api/resources/registrations.py | 2 +- .../unit/resources/test_registrations.py | 60 +++++++++++++++++++ 3 files changed, 93 insertions(+), 29 deletions(-) diff --git a/strr-api/src/strr_api/models/rental.py b/strr-api/src/strr_api/models/rental.py index 13abd8fbf..970123f55 100644 --- a/strr-api/src/strr_api/models/rental.py +++ b/strr-api/src/strr_api/models/rental.py @@ -302,10 +302,8 @@ def _collect_sub_status_conditions(cls, filter_criteria: RegistrationSearch, que from strr_api.models.application import Application sub_status_conditions = [] - needs_latest_app = bool(filter_criteria.approval_methods) or filter_criteria.review_renew is True - needs_renewal_regs = filter_criteria.review_renew is True or ( - bool(filter_criteria.approval_methods) and filter_criteria.examiner_reviewed is False - ) + needs_latest_app = bool(filter_criteria.approval_methods) + needs_renewal_regs = bool(filter_criteria.approval_methods) and filter_criteria.examiner_reviewed is False latest_app = None if needs_latest_app: @@ -349,7 +347,8 @@ def _collect_sub_status_conditions(cls, filter_criteria: RegistrationSearch, que if filter_criteria.is_set_aside is True: sub_status_conditions.append(Registration.is_set_aside == db.true()) if filter_criteria.review_renew is True: - sub_status_conditions.append(cls._review_renew_condition(latest_app=latest_app, renewal_regs=renewal_regs)) + query, review_renew_condition = cls._review_renew_condition(query) + sub_status_conditions.append(review_renew_condition) return query, sub_status_conditions @classmethod @@ -710,35 +709,40 @@ def _approval_method_condition( return db.or_(*filter_conditions) @classmethod - def _review_renew_condition(cls, latest_app=None, renewal_regs=None): - """Build SQL condition for renewals requiring human review. + def _review_renew_condition(cls, query): + """Join the renewals awaiting review and return the query with the SQL condition for them. + + A registration matches when both are true: + - no registration level decision exists + - one of its renewals is in the provisional review queue with no decision - A registration matches when all are true: - - a renewal is filed - - no registration level or latest application decision exists yet - - latest application is still in provisional review queue + The renewal is looked for among all of the registration's renewals, not only its latest application, so a + newer renewal (even a draft) doesn't hide an older one that still awaits review. """ + # pylint: disable=import-outside-toplevel + from strr_api.enums.enum import ApplicationType from strr_api.models.application import Application - provisional_statuses = [ - Application.Status.PROVISIONALLY_APPROVED.value, - Application.Status.PROVISIONAL_REVIEW.value, - ] - latest_app_decider = ( - latest_app.c.decider_id - if latest_app is not None - else cls._latest_application_field_subquery(Application, Application.decider_id) - ) - has_renewal = ( - renewal_regs.c.registration_id.isnot(None) - if renewal_regs is not None - else cls._has_renewal_filed_condition() + pending_renewal_regs = ( + select(Application.registration_id.label("registration_id")) + .where( + Application.registration_id.isnot(None), + Application.type == ApplicationType.RENEWAL.value, + Application.status.in_( + [ + Application.Status.PROVISIONALLY_APPROVED.value, + Application.Status.PROVISIONAL_REVIEW.value, + ] + ), + Application.decider_id.is_(None), + ) + .distinct() + .subquery("pending_renewal_regs") ) - return db.and_( - has_renewal, + query = query.outerjoin(pending_renewal_regs, pending_renewal_regs.c.registration_id == Registration.id) + return query, db.and_( Registration.decider_id.is_(None), - latest_app_decider.is_(None), - cls._approval_method_condition(provisional_statuses, latest_app=latest_app, renewal_regs=renewal_regs), + pending_renewal_regs.c.registration_id.isnot(None), ) @classmethod diff --git a/strr-api/src/strr_api/resources/registrations.py b/strr-api/src/strr_api/resources/registrations.py index 754f3f938..e45e216d7 100644 --- a/strr-api/src/strr_api/resources/registrations.py +++ b/strr-api/src/strr_api/resources/registrations.py @@ -1241,7 +1241,7 @@ def search_registrations(): - in: query name: reviewRenew type: boolean - description: When true, only return registrations with a filed renewal, no registration-level or latest-application decider, and latest application status in PROVISIONALLY_APPROVED/PROVISIONAL_REVIEW. + description: When true, only return registrations with no registration-level decider and at least one renewal in PROVISIONALLY_APPROVED/PROVISIONAL_REVIEW with no decider, whatever applications came after it. responses: 200: description: diff --git a/strr-api/tests/unit/resources/test_registrations.py b/strr-api/tests/unit/resources/test_registrations.py index 06012564b..9d905cd2b 100644 --- a/strr-api/tests/unit/resources/test_registrations.py +++ b/strr-api/tests/unit/resources/test_registrations.py @@ -2915,6 +2915,66 @@ def test_search_registrations_review_renew_includes_registration_with_filed_rene assert registrations.get("registrations")[0].get("registrationNumber") == registration_number +@pytest.mark.parametrize( + "newer_renewal_status", + [Application.Status.DRAFT.value, Application.Status.AUTO_APPROVED.value], +) +@patch("strr_api.services.strr_pay.create_invoice", return_value=MOCK_INVOICE_RESPONSE) +def test_search_registrations_review_renew_keeps_older_provisional_renewal_after_newer_renewal( + mock_create_invoice, session, client, jwt, newer_renewal_status +): + """Test that reviewRenew=true still returns a registration whose older renewal awaits review after a newer one.""" + from nanoid import generate + + with open(CREATE_HOST_REGISTRATION_REQUEST) as f: + json_data = json.load(f) + headers = create_header(jwt, [PUBLIC_USER], "Account-Id") + headers["Account-Id"] = ACCOUNT_ID + rv = client.post("/applications", json=json_data, headers=headers) + assert HTTPStatus.OK == rv.status_code + application_number = rv.json.get("header").get("applicationNumber") + + application = Application.find_by_application_number(application_number=application_number) + application.payment_status = PaymentStatus.COMPLETED.value + application.status = Application.Status.FULL_REVIEW + application.save() + + staff_headers = create_header(jwt, [STRR_EXAMINER], "Account-Id") + rv = client.put(f"/applications/{application_number}/assign", headers=staff_headers) + assert HTTPStatus.OK == rv.status_code + status_update_request = {"status": Application.Status.FULL_REVIEW_APPROVED} + rv = client.put(f"/applications/{application_number}/status", json=status_update_request, headers=staff_headers) + assert HTTPStatus.OK == rv.status_code + registration_number = rv.json.get("header").get("registrationNumber") + registration = Registration.query.filter_by(registration_number=registration_number).one_or_none() + registration.decider_id = None + registration.save() + + # Last year's renewal still awaits examination, and this year's renewal comes after it. + session.refresh(application) + for offset, status in ((1, Application.Status.PROVISIONAL_REVIEW.value), (2, newer_renewal_status)): + session.add( + Application( + application_json=application.application_json, + application_number=generate(alphabet="0123456789", size=14), + type=ApplicationType.RENEWAL.value, + registration_type=application.registration_type, + status=status, + registration_id=registration.id, + application_date=application.application_date + timedelta(days=offset * 365), + ) + ) + session.commit() + + rv = client.get( + f"/registrations/search?reviewRenew=true&recordNumber={registration_number}&status={RegistrationStatus.ACTIVE.value}", + headers=staff_headers, + ) + assert rv.status_code == HTTPStatus.OK + registrations = rv.json.get("registrations") + assert [r.get("registrationNumber") for r in registrations] == [registration_number] + + @patch("strr_api.services.strr_pay.create_invoice", return_value=MOCK_INVOICE_RESPONSE) def test_search_registrations_review_renew_excludes_registration_without_renewal( mock_create_invoice, session, client, jwt From 5f26b2b4254c07849fa7881342fbfa1f164ead47 Mon Sep 17 00:00:00 2001 From: Severin Beauvais Date: Thu, 3 Dec 2026 21:12:07 +0000 Subject: [PATCH 3/5] fix(strr-examiner-web): show Review Renew for older renewals awaiting review (REGBACKLOG-391) The dashboard row showed Review Renew only when the latest application was a renewal in the provisional review queue. Now that a provisionally approved renewal doesn't block the next one, a newer renewal (draft, unpaid, or approved) hid an older one still awaiting review, so the row was labelled Approved or "-" even though the reviewRenew filter returned it. - isReviewRenew now uses the same rule as the API's reviewRenew filter: no registration-level decider, and any renewal in PROVISIONAL_REVIEW or PROVISIONALLY_APPROVED with no decider. The Renewal badge follows it. - strr-examiner-web goes to 0.2.75. --- strr-examiner-web/app/pages/dashboard.vue | 21 +++++++++++------ strr-examiner-web/package.json | 2 +- .../tests/unit/dashboard.spec.ts | 23 +++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/strr-examiner-web/app/pages/dashboard.vue b/strr-examiner-web/app/pages/dashboard.vue index d2ad78c0b..b3cb146f3 100644 --- a/strr-examiner-web/app/pages/dashboard.vue +++ b/strr-examiner-web/app/pages/dashboard.vue @@ -312,14 +312,21 @@ const getRequirementsColumn = (app: HousApplicationResponse) => { return result } -const hasRenewalApplication = (reg: HousRegistrationResponse): boolean => { - const applications = reg.header?.applications ?? [] - return applications.some(app => app.applicationType === 'renewal') -} - +/** + * Same predicate as the API's reviewRenew filter: no registration-level decider, and any renewal (not only the latest + * application) still in the provisional review queue with no decider. A newer application, such as a draft renewal, + * mustn't hide an older renewal that still awaits review. + */ const isReviewRenew = (reg: HousRegistrationResponse): boolean => { - const latestAppStatus = getLatestRegistrationApplicationStatus(reg) - return hasRenewalApplication(reg) && !hasExaminerReview(reg) && isProvisionalReviewQueueStatus(latestAppStatus) + if (hasDecider(reg.header?.decider)) { + return false + } + const applications = reg.header?.applications ?? [] + return applications.some(app => + app.applicationType === 'renewal' && + isProvisionalReviewQueueStatus(app.applicationStatus as ApplicationStatus | undefined) && + !hasDecider(app.decider) + ) } /** diff --git a/strr-examiner-web/package.json b/strr-examiner-web/package.json index c327b00ec..a5306618e 100644 --- a/strr-examiner-web/package.json +++ b/strr-examiner-web/package.json @@ -2,7 +2,7 @@ "name": "strr-examiner-web", "private": true, "type": "module", - "version": "0.2.74", + "version": "0.2.75", "engines": { "node": ">=24" }, diff --git a/strr-examiner-web/tests/unit/dashboard.spec.ts b/strr-examiner-web/tests/unit/dashboard.spec.ts index 36c639386..05946d9a4 100644 --- a/strr-examiner-web/tests/unit/dashboard.spec.ts +++ b/strr-examiner-web/tests/unit/dashboard.spec.ts @@ -855,6 +855,29 @@ describe('Examiner Dashboard Page', () => { expect(wrapper.vm.getRegistrationSubStatus(reg)).toBe('Approved') }) + // Newest application first, as the API sends them + it.each([ + { newer: ApplicationStatus.DRAFT, decider: {} }, + { newer: ApplicationStatus.PAYMENT_DUE, decider: {} }, + { newer: ApplicationStatus.AUTO_APPROVED, decider: {} }, + { newer: ApplicationStatus.PROVISIONALLY_APPROVED, decider: { username: 'examiner1' } } + ])('shows Review Renew when an older renewal awaits review under a newer $newer renewal', ({ newer, decider }) => { + const reg = { + ...mockHostRegistration, + header: { + ...mockHostRegistration.header, + decider: {}, + applications: [ + { applicationType: 'renewal', applicationStatus: newer, decider }, + { applicationType: 'renewal', applicationStatus: ApplicationStatus.PROVISIONAL_REVIEW, decider: {} } + ] + } + } + + expect(wrapper.vm.getRegistrationSubStatus(reg)).toBe('Review Renew') + expect(wrapper.vm.shouldShowRenewalBadge(reg)).toBe(true) + }) + it('does not show Review Renew when latest status is not provisional queue status', () => { const reg = { ...mockHostRegistration, From 94b33419741cf07928c4778f0d6a7ef74256aafd Mon Sep 17 00:00:00 2001 From: Severin Beauvais Date: Fri, 4 Dec 2026 20:31:53 +0000 Subject: [PATCH 4/5] fix(strr-api): run the duplicate renewal check when a renewal draft is submitted (REGBACKLOG-391) The 409 RENEWAL_ALREADY_IN_PROGRESS check ran only when a renewal was started, so submitting an existing draft created an invoice even while another renewal was in progress. That's how H353013514 paid for two renewals on 2026-06-14, from drafts started before the check went live. In Production, 52 registrations still have a renewal draft beside another unfinished renewal. - The check now also runs when a renewal draft is submitted. Saving a draft still isn't checked, since that creates no invoice. - find_non_terminal_renewal_for_payment_account takes an optional exclude_application_id, so the draft being submitted isn't its own conflict. - Adds test_draft_is_submitted_only_while_no_other_renewal_is_in_progress. Addresses review feedback on #1964. --- strr-api/src/strr_api/models/application.py | 23 +++++++----- .../src/strr_api/resources/application.py | 17 ++++++--- .../unit/resources/test_renewal_window_api.py | 37 +++++++++++++++++++ 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/strr-api/src/strr_api/models/application.py b/strr-api/src/strr_api/models/application.py index de5a23ba0..cd171d776 100644 --- a/strr-api/src/strr_api/models/application.py +++ b/strr-api/src/strr_api/models/application.py @@ -349,20 +349,23 @@ def find_non_terminal_renewal_for_payment_account( payment_account: str | int | None, registration_id: int, finished_status_values: tuple[str, ...], + exclude_application_id: int | None = None, ) -> Application | None: - """Return a renewal for this account+registration that is not in one of the finished statuses, if any.""" + """Return a renewal for this account+registration that is not in one of the finished statuses, if any. + + exclude_application_id leaves out the application being submitted, so a draft isn't its own conflict. + """ if payment_account is None: return None - return ( - cls.query.filter( - cls.type == ApplicationType.RENEWAL.value, - cls.registration_id == registration_id, - cls.payment_account == str(payment_account), - ~cls.status.in_(finished_status_values), - ) - .order_by(cls.id.desc()) - .first() + query = cls.query.filter( + cls.type == ApplicationType.RENEWAL.value, + cls.registration_id == registration_id, + cls.payment_account == str(payment_account), + ~cls.status.in_(finished_status_values), ) + if exclude_application_id is not None: + query = query.filter(cls.id != exclude_application_id) + return query.order_by(cls.id.desc()).first() @classmethod def _filter_by_application_registration_number(cls, search_term: str, query: Query) -> Query: diff --git a/strr-api/src/strr_api/resources/application.py b/strr-api/src/strr_api/resources/application.py index 3d4a707ed..ff2346d72 100644 --- a/strr-api/src/strr_api/resources/application.py +++ b/strr-api/src/strr_api/resources/application.py @@ -145,9 +145,9 @@ def create_application(application_number: Optional[str] = None): description: Application not found (when path includes application_number). 409: description: > - Renewal conflict — pathless POST /applications for renewal when a renewal that is neither approved - (provisionally or in full) nor declined already exists for the same registration and Account-Id - (errorCode RENEWAL_ALREADY_IN_PROGRESS). + Renewal conflict — a renewal is started (pathless POST) or a renewal draft is submitted when another + renewal that is neither approved (provisionally or in full) nor declined already exists for the same + registration and Account-Id (errorCode RENEWAL_ALREADY_IN_PROGRESS). Saving a draft isn't checked. 402: description: Payment required (e.g. invoice creation failed on final submit). 502: @@ -228,15 +228,20 @@ def create_application(application_number: Optional[str] = None): error_code="RENEWAL_WINDOW_CLOSED", ) - if application is None: + # Check when a renewal is started, and again when a draft is submitted, because submitting creates an + # invoice and the draft may predate the renewal now in progress. Saving a draft isn't checked. + if application is None or not is_draft: # A provisionally approved renewal has extended the registration, so it doesn't block the next one finished_status_values = tuple(s.value for s in RENEWAL_FINISHED_STATES) conflicting = ApplicationModel.find_non_terminal_renewal_for_payment_account( - account_id, registration_id, finished_status_values + account_id, + registration_id, + finished_status_values, + exclude_application_id=application.id if application else None, ) if conflicting: logger.info( - "STRR renewal create returned 409: a non-terminal renewal already exists for this " + "STRR renewal create or submit returned 409: a non-terminal renewal already exists for this " "registration and payment account. " "registration_id=%s payment_account=%s existing_renewal_id=%s " "existing_application_number=%s existing_renewal_status=%s error_code=RENEWAL_ALREADY_IN_PROGRESS", diff --git a/strr-api/tests/unit/resources/test_renewal_window_api.py b/strr-api/tests/unit/resources/test_renewal_window_api.py index 9fa02ba6d..78df25342 100644 --- a/strr-api/tests/unit/resources/test_renewal_window_api.py +++ b/strr-api/tests/unit/resources/test_renewal_window_api.py @@ -158,3 +158,40 @@ def test_new_renewal_is_refused_only_while_one_is_in_progress( if conflict: assert rv.json["errorCode"] == "RENEWAL_ALREADY_IN_PROGRESS" assert Application.query.filter_by(registration_id=registration.id).count() == (1 if conflict else 2) + + +@pytest.mark.parametrize( + "other_status, conflict", + [ + (None, False), # no other renewal: the draft isn't its own conflict + (Application.Status.DRAFT, True), + (Application.Status.PAYMENT_DUE, True), + (Application.Status.PAID, True), + (Application.Status.PROVISIONAL_REVIEW, False), + (Application.Status.DECLINED, False), + ], +) +@patch("strr_api.services.strr_pay.create_invoice", return_value=MOCK_INVOICE_RESPONSE) +def test_draft_is_submitted_only_while_no_other_renewal_is_in_progress( + mock_invoice, client, renewal_headers, make_registration, make_renewal, other_status, conflict +): + with open(HOST_REGISTRATION) as f: + base_json = json.load(f) + registration = make_registration(20) + payload = host_renewal_application_json(registration.id, base_json=base_json) + draft_headers = {**renewal_headers, "isDraft": True} + rv = client.post("/applications", json=payload, headers=draft_headers) + assert rv.status_code == HTTPStatus.OK + number = rv.json["header"]["applicationNumber"] + if other_status: + make_renewal(registration, other_status) # eg a renewal started before the check existed + + # Saving the draft is never refused; submitting it is, while another renewal is in progress + assert client.put(f"/applications/{number}", json=payload, headers=draft_headers).status_code == HTTPStatus.OK + rv = client.put(f"/applications/{number}", json=payload, headers=renewal_headers) + + assert rv.status_code == (HTTPStatus.CONFLICT if conflict else HTTPStatus.OK) + if conflict: + assert rv.json["errorCode"] == "RENEWAL_ALREADY_IN_PROGRESS" + assert Application.find_by_application_number(number).status == Application.Status.DRAFT + assert mock_invoice.call_count == int(not conflict) From c1330dc5b9c61cef7cc44cfae6a1707fe2280354 Mon Sep 17 00:00:00 2001 From: Severin Beauvais Date: Fri, 4 Dec 2026 22:46:54 +0000 Subject: [PATCH 5/5] fix(strr-api): keep Review Renew rows out of the Approved filter (REGBACKLOG-391) - The Approved filter now leaves out registrations that the Review Renew filter returns, so a row labelled Review Renew (an older renewal awaiting review, with a newer auto/full-review approved or application-decided renewal) no longer shows under Approved. - Review and Approved selected together now return exactly the union of the two filters, instead of matching on the latest application's status alone. - The Review Renew subquery is joined once and shared by both filters. --- strr-api/src/strr_api/models/rental.py | 49 +++++++++++------ .../src/strr_api/resources/registrations.py | 4 +- .../unit/resources/test_registrations.py | 52 +++++++++++++++---- strr-examiner-web/app/stores/examiner.ts | 3 +- 4 files changed, 77 insertions(+), 31 deletions(-) diff --git a/strr-api/src/strr_api/models/rental.py b/strr-api/src/strr_api/models/rental.py index 970123f55..135b3a247 100644 --- a/strr-api/src/strr_api/models/rental.py +++ b/strr-api/src/strr_api/models/rental.py @@ -303,7 +303,7 @@ def _collect_sub_status_conditions(cls, filter_criteria: RegistrationSearch, que sub_status_conditions = [] needs_latest_app = bool(filter_criteria.approval_methods) - needs_renewal_regs = bool(filter_criteria.approval_methods) and filter_criteria.examiner_reviewed is False + needs_renewal_regs = bool(filter_criteria.approval_methods) and filter_criteria.examiner_reviewed is not True latest_app = None if needs_latest_app: @@ -333,6 +333,11 @@ def _collect_sub_status_conditions(cls, filter_criteria: RegistrationSearch, que ) query = query.outerjoin(renewal_regs, renewal_regs.c.registration_id == Registration.id) + # Built once and shared: the Approved filter excludes the rows that the Review Renew filter selects. + review_renew_condition = None + if filter_criteria.approval_methods or filter_criteria.review_renew is True: + query, review_renew_condition = cls._review_renew_condition(query) + if filter_criteria.approval_methods: sub_status_conditions.append( cls._approval_method_condition( @@ -340,6 +345,7 @@ def _collect_sub_status_conditions(cls, filter_criteria: RegistrationSearch, que filter_criteria.examiner_reviewed, latest_app=latest_app, renewal_regs=renewal_regs, + review_renew_condition=review_renew_condition, ) ) if filter_criteria.noc_statuses: @@ -347,7 +353,6 @@ def _collect_sub_status_conditions(cls, filter_criteria: RegistrationSearch, que if filter_criteria.is_set_aside is True: sub_status_conditions.append(Registration.is_set_aside == db.true()) if filter_criteria.review_renew is True: - query, review_renew_condition = cls._review_renew_condition(query) sub_status_conditions.append(review_renew_condition) return query, sub_status_conditions @@ -637,14 +642,24 @@ def _filter_by_registration_requirement(cls, requirement: list[str], query): return query @classmethod - def _approval_method_condition( + def _approval_method_condition( # pylint: disable=too-many-arguments cls, approval_methods: list[str], examiner_reviewed: bool | None = None, latest_app=None, renewal_regs=None, + review_renew_condition=None, ): - """Build SQL condition for filtering by latest application status and review state.""" + """Build SQL condition for filtering by latest application status and review state. + + The conditions match the examiner dashboard's row labels, so a row is only returned by the filter that has + its label: + - Approved (examiner_reviewed=True): AUTO_APPROVED/FULL_REVIEW_APPROVED, or provisional with a decision + - Review (examiner_reviewed=False): provisional with no decision and no filed renewal + - both (examiner_reviewed=None): either of the above + Review Renew takes precedence over Approved, so registrations matching review_renew_condition are left out of + the approved conditions. Review needs no such exclusion: a registration with a filed renewal never matches it. + """ from strr_api.models.application import Application latest_app_status = ( @@ -652,10 +667,6 @@ def _approval_method_condition( if latest_app is not None else cls._latest_application_field_subquery(Application, Application.status) ) - approval_status_condition = latest_app_status.in_(approval_methods) - if examiner_reviewed is None: - return approval_status_condition - latest_app_decider = ( latest_app.c.decider_id if latest_app is not None @@ -678,6 +689,9 @@ def _approval_method_condition( if renewal_regs is not None else db.not_(cls._has_renewal_filed_condition()) ) + not_review_renew_condition = ( + db.not_(review_renew_condition) if review_renew_condition is not None else db.true() + ) # examinerReviewed only applies to provisional workflow statuses. provisional_statuses = { @@ -690,19 +704,20 @@ def _approval_method_condition( filter_conditions = [] if terminal_approval_methods: # AUTO_APPROVED/FULL_REVIEW_APPROVED are approved regardless of decider. - filter_conditions.append(latest_app_status.in_(terminal_approval_methods)) + filter_conditions.append( + db.and_(latest_app_status.in_(terminal_approval_methods), not_review_renew_condition) + ) if provisional_approval_methods: provisional_status_condition = latest_app_status.in_(provisional_approval_methods) - filter_conditions.append( - db.and_(provisional_status_condition, reviewed_condition) - if examiner_reviewed - else db.and_( - provisional_status_condition, - not_reviewed_condition, - no_renewal_condition, + if examiner_reviewed is not False: + filter_conditions.append( + db.and_(provisional_status_condition, reviewed_condition, not_review_renew_condition) + ) + if examiner_reviewed is not True: + filter_conditions.append( + db.and_(provisional_status_condition, not_reviewed_condition, no_renewal_condition) ) - ) if not filter_conditions: return db.false() diff --git a/strr-api/src/strr_api/resources/registrations.py b/strr-api/src/strr_api/resources/registrations.py index e45e216d7..db2c28072 100644 --- a/strr-api/src/strr_api/resources/registrations.py +++ b/strr-api/src/strr_api/resources/registrations.py @@ -1218,11 +1218,11 @@ def search_registrations(): items: type: string enum: [FULL_REVIEW_APPROVED, AUTO_APPROVED, PROVISIONALLY_APPROVED] - description: Approval method filter. Can provide multiple values. + description: Approval method filter, on the latest application's status. Can provide multiple values. Registrations that reviewRenew would match are left out of the approved results (FULL_REVIEW_APPROVED, AUTO_APPROVED, and provisional with an examiner decision), and provisional records with no examiner decision are only returned when no renewal has been filed. - in: query name: examinerReviewed type: boolean - description: When provided with approvalMethod, filter provisional records by whether an examiner decision exists at either registration level or latest application level. + description: When provided with approvalMethod, filter provisional records by whether an examiner decision exists at either registration level or latest application level. When omitted, provisional records of either kind are returned. - in: query name: nocStatus type: array diff --git a/strr-api/tests/unit/resources/test_registrations.py b/strr-api/tests/unit/resources/test_registrations.py index 9d905cd2b..955a7a122 100644 --- a/strr-api/tests/unit/resources/test_registrations.py +++ b/strr-api/tests/unit/resources/test_registrations.py @@ -2916,14 +2916,22 @@ def test_search_registrations_review_renew_includes_registration_with_filed_rene @pytest.mark.parametrize( - "newer_renewal_status", - [Application.Status.DRAFT.value, Application.Status.AUTO_APPROVED.value], + "newer_renewal_status, newer_renewal_decided", + [ + (Application.Status.DRAFT.value, False), + (Application.Status.AUTO_APPROVED.value, False), + # Legacy flow: the examiner decision is on the newer renewal only. + (Application.Status.PROVISIONALLY_APPROVED.value, True), + ], ) @patch("strr_api.services.strr_pay.create_invoice", return_value=MOCK_INVOICE_RESPONSE) def test_search_registrations_review_renew_keeps_older_provisional_renewal_after_newer_renewal( - mock_create_invoice, session, client, jwt, newer_renewal_status + mock_create_invoice, session, client, jwt, newer_renewal_status, newer_renewal_decided ): - """Test that reviewRenew=true still returns a registration whose older renewal awaits review after a newer one.""" + """Test that a registration whose older renewal awaits review is in Review Renew, and only there. + + The examiner dashboard labels it Review Renew, so the Approved and Review filters mustn't return it. + """ from nanoid import generate with open(CREATE_HOST_REGISTRATION_REQUEST) as f: @@ -2952,7 +2960,11 @@ def test_search_registrations_review_renew_keeps_older_provisional_renewal_after # Last year's renewal still awaits examination, and this year's renewal comes after it. session.refresh(application) - for offset, status in ((1, Application.Status.PROVISIONAL_REVIEW.value), (2, newer_renewal_status)): + newer_renewal_decider = application.reviewer_id if newer_renewal_decided else None + for offset, status, decider_id in ( + (1, Application.Status.PROVISIONAL_REVIEW.value, None), + (2, newer_renewal_status, newer_renewal_decider), + ): session.add( Application( application_json=application.application_json, @@ -2961,18 +2973,36 @@ def test_search_registrations_review_renew_keeps_older_provisional_renewal_after registration_type=application.registration_type, status=status, registration_id=registration.id, + decider_id=decider_id, application_date=application.application_date + timedelta(days=offset * 365), ) ) session.commit() - rv = client.get( - f"/registrations/search?reviewRenew=true&recordNumber={registration_number}&status={RegistrationStatus.ACTIVE.value}", - headers=staff_headers, + # The dashboard's sub-status filters: Approved, Review + Approved, and Approved + Review Renew. + approved = "".join( + f"&approvalMethod={status.value}" + for status in ( + Application.Status.PROVISIONALLY_APPROVED, + Application.Status.PROVISIONAL_REVIEW, + Application.Status.AUTO_APPROVED, + Application.Status.FULL_REVIEW_APPROVED, + ) ) - assert rv.status_code == HTTPStatus.OK - registrations = rv.json.get("registrations") - assert [r.get("registrationNumber") for r in registrations] == [registration_number] + for sub_status_params, expected in ( + ("&reviewRenew=true", [registration_number]), + (f"{approved}&examinerReviewed=true", []), + (approved, []), + (f"{approved}&examinerReviewed=true&reviewRenew=true", [registration_number]), + ): + rv = client.get( + f"/registrations/search?recordNumber={registration_number}&status={RegistrationStatus.ACTIVE.value}" + f"{sub_status_params}", + headers=staff_headers, + ) + assert rv.status_code == HTTPStatus.OK + registrations = rv.json.get("registrations") + assert [r.get("registrationNumber") for r in registrations] == expected, sub_status_params @patch("strr_api.services.strr_pay.create_invoice", return_value=MOCK_INVOICE_RESPONSE) diff --git a/strr-examiner-web/app/stores/examiner.ts b/strr-examiner-web/app/stores/examiner.ts index 45df56387..0f4eb2cca 100644 --- a/strr-examiner-web/app/stores/examiner.ts +++ b/strr-examiner-web/app/stores/examiner.ts @@ -324,7 +324,8 @@ export const useExaminerStore = defineStore('strr/examiner-store', () => { } else if (subStatus === APPROVED_SUB_STATUS) { hasApprovedSubStatus = true // "Approved" includes auto/full approvals and provisionals that were - // reviewed by an examiner. + // reviewed by an examiner, except rows labelled "Review Renew" (the API + // leaves those out). approvalMethods.add(ApplicationStatus.PROVISIONALLY_APPROVED) approvalMethods.add(ApplicationStatus.PROVISIONAL_REVIEW) approvalMethods.add(ApplicationStatus.AUTO_APPROVED)