Skip to content

Commit

Permalink
Merge pull request #107 from cisagov/improvement/no-csa-bcc-for-fed-o…
Browse files Browse the repository at this point in the history
…r-intl

Exclude federal and international entities from CSA BCC functionality
  • Loading branch information
dav3r authored Apr 9, 2024
2 parents becb2a1 + 8e45028 commit 4e91ec3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ Options:
present then the appropriate CSA
will be BCCd any CyHy reports or
notifications related to a
stakeholder within their region.
stakeholder within their region (federal
and international entities excluded).
--batch-size=SIZE The batch size to use when retrieving
results from the Mongo database. If not
present then the default Mongo batch size
Expand Down
2 changes: 1 addition & 1 deletion cyhy/mailer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""This package contains the cyhy-mailer code."""

__version__ = "1.6.0"
__version__ = "1.7.0"
26 changes: 19 additions & 7 deletions cyhy/mailer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
present then the appropriate CSA
will be BCCd any CyHy reports or
notifications related to a
stakeholder within their region.
stakeholder within their region (federal
and international entities excluded).
--batch-size=SIZE The batch size to use when retrieving
results from the Mongo database. If not
present then the default Mongo batch size
Expand Down Expand Up @@ -91,6 +92,8 @@
from cyhy.mailer.TmailMessage import TmailMessage
from mongo_db_from_config import db_from_config

CSA_BCC_EXCLUDED_ENTITY_TYPES = ["FEDERAL", "INTERNATIONAL"]


class Error(Exception):
"""A base class for exceptions used in this module."""
Expand Down Expand Up @@ -226,6 +229,7 @@ def get_requests_raw(db, query, batch_size=None):
"agency.contacts.name": True,
"agency.contacts.type": True,
"agency.location.state": True,
"agency.type": True,
}

try:
Expand Down Expand Up @@ -746,8 +750,8 @@ def send_cyhy_reports(
Either None or a dict with keys belonging to the set of
two-letter abbreviations for states and territories and values
equal to the email of the corresponding CSA for the region to
which the state or territory belongs. If None then the CSAs
will not be BCCd.
which the state or territory belongs (federal and international
entities excluded). If None then the CSAs will not be BCCd.
dry_run : bool
If True then do not actually send email.
Expand Down Expand Up @@ -793,9 +797,13 @@ def send_cyhy_reports(
if not to_emails:
continue

# Grab the email address of the appropriate CSA.
# Grab the email address of the appropriate CSA for non-federal and
# non-international entities.
csa_email_address = None
if csa_emails is not None:
if (
csa_emails is not None
and request["agency"].get("type") not in CSA_BCC_EXCLUDED_ENTITY_TYPES
):
try:
state = request["agency"]["location"]["state"]
except KeyError:
Expand Down Expand Up @@ -1015,9 +1023,13 @@ def send_cyhy_notifications(
if not to_emails:
continue

# Grab the email address of the appropriate CSA.
# Grab the email address of the appropriate CSA for non-federal and
# non-international entities.
csa_email_address = None
if csa_emails is not None:
if (
csa_emails is not None
and request["agency"].get("type") not in CSA_BCC_EXCLUDED_ENTITY_TYPES
):
try:
state = request["agency"]["location"]["state"]
except KeyError:
Expand Down

0 comments on commit 4e91ec3

Please sign in to comment.