Skip to content
Open
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: 11 additions & 1 deletion data-tool/flows/auth/inspect_auth_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
invite_expiry_days: int = 7
invite_expiry_cutoff: datetime | None = None
invite_criteria: InviteCriteria | None = None

file_cnt_last_2yrs: int | None = None
@property
def run_verify(self) -> bool:
"""Return False so shared Auth batches only read Auth state."""
Expand Down Expand Up @@ -176,7 +176,7 @@
) from exc


def validate_inspect_config(config: Any) -> InspectAuthSettings:

Check failure on line 179 in data-tool/flows/auth/inspect_auth_flow.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=bcgov_lear&issues=AaCRM9CNdyqHvadXT1Gc&open=AaCRM9CNdyqHvadXT1Gc&pullRequest=4776
"""Validate inspect-auth config before database connections are opened."""
batches = _coerce_int_setting(config, "AUTH_REPORT_BATCHES")
if batches <= 0:
Expand All @@ -187,6 +187,15 @@
raise ValueError("AUTH_REPORT_BATCH_SIZE must be greater than 0")

inspect_filter = parse_inspect_filter(getattr(config, "INSPECT_AUTH_FILTER", None), "INSPECT_AUTH_FILTER")
file_cnt_raw = blank_to_none(getattr(config, "INSPECT_AUTH_FILE_CNT_LAST_2YRS", None))
file_cnt_last_2yrs = None
if file_cnt_raw is not None:
try:
file_cnt_last_2yrs = int(file_cnt_raw)
except (TypeError, ValueError) as exc:
raise ValueError("INSPECT_AUTH_FILE_CNT_LAST_2YRS must be a non-negative integer") from exc
if file_cnt_last_2yrs < 0:
raise ValueError("INSPECT_AUTH_FILE_CNT_LAST_2YRS must be a non-negative integer")
invite_expiry_days = parse_invite_expiry_days(
getattr(config, "INSPECT_AUTH_INVITE_EXPIRY_DAYS", None)
)
Expand Down Expand Up @@ -266,6 +275,7 @@
invite_expiry_days=invite_expiry_days,
invite_expiry_cutoff=invite_expiry_cutoff,
invite_criteria=invite_criteria,
file_cnt_last_2yrs=file_cnt_last_2yrs,
)


Expand Down
10 changes: 10 additions & 0 deletions data-tool/flows/auth/verify_auth_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,16 @@ def build_candidate_queries(config: Any, settings: AuthCandidateSettings | None
auth_mig_group_ids=settings.auth_mig_group_ids,
auth_mig_batch_ids=settings.auth_mig_batch_ids,
).strip()
file_cnt_gt = getattr(settings, "file_cnt_last_2yrs", None)
if file_cnt_gt is not None:
base_sql = f"""
SELECT candidates.corp_num
FROM (
{base_sql}
) candidates
INNER JOIN mv_legacy_corps_data lcd ON lcd.corp_num = candidates.corp_num
WHERE lcd.file_cnt_last_2yrs > {int(file_cnt_gt)}
""".strip()

count_sql = f"""
SELECT COUNT(*)
Expand Down
1 change: 1 addition & 0 deletions data-tool/flows/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class _Config(): # pylint: disable=too-few-public-methods
# inspect Auth flow. HAS_CONTACT / ENTITY_WITHOUT_CONTACT mean usable contact email,
# not merely any raw contact row.
INSPECT_AUTH_FILTER = (os.getenv('INSPECT_AUTH_FILTER') or 'ALL').strip() or 'ALL'
INSPECT_AUTH_FILE_CNT_LAST_2YRS = os.getenv('INSPECT_AUTH_FILE_CNT_LAST_2YRS')
# Invitation settings stay raw here and are validated only by inspect-auth.
# INSPECT_AUTH_INVITE_CRITERIA is an AND-composed clause list such as
# count>=3, all_expired, age[1]>=90, newest_age>30. Positions are chronological
Expand Down