Skip to content

Commit

Permalink
[#190] rename va_identifier to recipient_identifier, va_identifier_ty…
Browse files Browse the repository at this point in the history
…pe to id_type, and va_identifier_value to id_value for consistency across DB, model, and code
  • Loading branch information
marisahoenig committed Oct 27, 2020
1 parent e265ff9 commit 4da6d3f
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 87 deletions.
10 changes: 5 additions & 5 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ class Notification(db.Model):
""")

recipient_identifiers = db.relationship('RecipientIdentifier',
collection_class=attribute_mapped_collection('va_identifier_type'),
collection_class=attribute_mapped_collection('id_type'),
cascade='all, delete-orphan')

__table_args__ = (
Expand Down Expand Up @@ -1729,7 +1729,7 @@ class ScheduledNotification(db.Model):
PID = 'PID'
ICN = 'ICN'

VA_IDENTIFIER_TYPES = [
RECIPIENT_IDENTIFIER_TYPES = [
VA_PROFILE_ID,
PID,
ICN
Expand All @@ -1740,12 +1740,12 @@ class RecipientIdentifier(db.Model):
__tablename__ = 'recipient_identifiers'
notification_id = db.Column(UUID(as_uuid=True), db.ForeignKey('notifications.id', ondelete="cascade"),
primary_key=True, nullable=False)
va_identifier_type = db.Column(
db.Enum(*VA_IDENTIFIER_TYPES, name='va_identifier_types'),
id_type = db.Column(
db.Enum(*RECIPIENT_IDENTIFIER_TYPES, name='id_types'),
primary_key=True,
nullable=False,
default=VA_PROFILE_ID)
va_identifier_value = db.Column(db.String, primary_key=True, nullable=False)
id_value = db.Column(db.String, primary_key=True, nullable=False)


INVITE_PENDING = 'pending'
Expand Down
8 changes: 4 additions & 4 deletions app/notifications/process_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def persist_notification(
if accept_recipient_identifiers_enabled(current_app) and recipient_identifier:
_recipient_identifier = RecipientIdentifier(
notification_id=notification_id,
va_identifier_type=recipient_identifier['id_type'],
va_identifier_value=recipient_identifier['value']
id_type=recipient_identifier['id_type'],
id_value=recipient_identifier['value']
)
notification.recipient_identifiers.set(_recipient_identifier)

Expand Down Expand Up @@ -160,8 +160,8 @@ def send_notification_to_queue(notification, research_mode, queue=None):
queue))


def send_to_queue_for_recipient_info_based_on_recipient_identifier(notification, va_identifier_type):
if va_identifier_type == VA_PROFILE_ID:
def send_to_queue_for_recipient_info_based_on_recipient_identifier(notification, id_type):
if id_type == VA_PROFILE_ID:
queue = QueueNames.LOOKUP_CONTACT_INFO
task = contact_information_tasks.lookup_contact_info
else:
Expand Down
18 changes: 9 additions & 9 deletions app/v2/notifications/notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
NOTIFICATION_STATUS_LETTER_ACCEPTED,
NOTIFICATION_STATUS_LETTER_RECEIVED,
TEMPLATE_TYPES,
VA_IDENTIFIER_TYPES)
RECIPIENT_IDENTIFIER_TYPES)
from app.schema_validation.definitions import (uuid, personalisation, letter_personalisation)


Expand Down Expand Up @@ -126,15 +126,15 @@

}

va_identifier = {"type": "object", "properties": {
recipient_identifier = {"type": "object", "properties": {
"id_type": {
"type": "string",
"enum": VA_IDENTIFIER_TYPES
"enum": RECIPIENT_IDENTIFIER_TYPES
},
"value": {
"id_value": {
"type": "string"
}
}, "required": ["id_type", "value"]}
}, "required": ["id_type", "id_value"]}

post_sms_request = {
"$schema": "http://json-schema.org/draft-04/schema#",
Expand All @@ -144,7 +144,7 @@
"properties": {
"reference": {"type": "string"},
"phone_number": {"type": "string", "format": "phone_number"},
"va_identifier": va_identifier,
"recipient_identifier": recipient_identifier,
"template_id": uuid,
"personalisation": personalisation,
"scheduled_for": {"type": ["string", "null"], "format": "datetime_within_next_day"},
Expand All @@ -153,7 +153,7 @@
"required": ["template_id"],
"anyOf": [
{"required": ["phone_number"]},
{"required": ["va_identifier"]}
{"required": ["recipient_identifier"]}
],
"additionalProperties": False
}
Expand Down Expand Up @@ -195,7 +195,7 @@
"properties": {
"reference": {"type": "string"},
"email_address": {"type": "string", "format": "email_address"},
"va_identifier": va_identifier,
"recipient_identifier": recipient_identifier,
"template_id": uuid,
"personalisation": personalisation,
"scheduled_for": {"type": ["string", "null"], "format": "datetime_within_next_day"},
Expand All @@ -204,7 +204,7 @@
"required": ["template_id"],
"anyOf": [
{"required": ["email_address"]},
{"required": ["va_identifier"]}
{"required": ["recipient_identifier"]}
],
"additionalProperties": False
}
Expand Down
6 changes: 3 additions & 3 deletions app/v2/notifications/post_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def process_sms_or_email_notification(*, form, notification_type, api_key, templ
client_reference=form.get('reference', None),
simulated=simulated,
reply_to_text=reply_to_text,
recipient_identifier=form.get('va_identifier', None)
recipient_identifier=form.get('recipient_identifier', None)
)

scheduled_for = form.get("scheduled_for", None)
Expand Down Expand Up @@ -256,12 +256,12 @@ def process_notification_with_recipient_identifier(*, form, notification_type, a
key_type=api_key.key_type,
client_reference=form.get('reference', None),
reply_to_text=reply_to_text,
recipient_identifier=form.get('va_identifier', None)
recipient_identifier=form.get('recipient_identifier', None)
)

send_to_queue_for_recipient_info_based_on_recipient_identifier(
notification=notification,
va_identifier_type=form['va_identifier']['id_type']
id_type=form['recipient_identifier']['id_type']
)

return notification
Expand Down
2 changes: 1 addition & 1 deletion documents/contact-info-lookup-sequence-diagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ activate api
note right of consumer
""{""
"" templated_id: abcd""
"" va_identifier: {""
"" recipient_identifier: {""
"" id_type: ICN""
"" value: efgh""
"" }""
Expand Down
16 changes: 8 additions & 8 deletions documents/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ components:
example: "+19876543210"
required: [phone_number]
- properties:
va_identifier:
recipient_identifier:
type: object
properties:
id_type:
Expand All @@ -1323,12 +1323,12 @@ components:
- VAPROFILEID
- PID
- ICN
value:
id_value:
type: string
required:
- id_type
- value
required: [va_identifier]
- id_value
required: [recipient_identifier]
EmailNotificationRequest:
allOf:
- $ref: '#/components/schemas/NotificationRequest'
Expand All @@ -1343,7 +1343,7 @@ components:
format: email_address
required: [email_address]
- properties:
va_identifier:
recipient_identifier:
type: object
properties:
id_type:
Expand All @@ -1352,12 +1352,12 @@ components:
- VAPROFILEID
- PID
- ICN
value:
id_value:
type: string
required:
- id_type
- value
required: [va_identifier]
- id_value
required: [recipient_identifier]
Notification:
type: object
properties:
Expand Down
6 changes: 3 additions & 3 deletions migrations/versions/0312_recipient_identifiers_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def upgrade():
op.create_table(
'recipient_identifiers',
sa.Column('notification_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('va_identifier_type', sa.Enum('VAPROFILEID', 'PID', 'ICN', name='va_identifier_types'),
sa.Column('id_type', sa.Enum('VAPROFILEID', 'PID', 'ICN', name='id_types'),
nullable=False),
sa.Column('va_identifier_value', sa.String(), nullable=False),
sa.Column('id_value', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('notification_id', 'va_identifier_type', 'va_identifier_value')
sa.PrimaryKeyConstraint('notification_id', 'id_type', 'id_value')
)


Expand Down
8 changes: 4 additions & 4 deletions scripts/postman/notification-api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@
"response": []
},
{
"name": "send sms with va_identifier",
"name": "send sms with recipient_identifier",
"event": [
{
"listen": "prerequest",
Expand Down Expand Up @@ -2014,7 +2014,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"template_id\": \"{{template-id}}\",\n \"va_identifier\": {\n \"id_type\": \"VAPROFILEID\",\n \"value\": \"example\"\n }\n}"
"raw": "{\n \"template_id\": \"{{template-id}}\",\n \"recipient_identifier\": {\n \"id_type\": \"VAPROFILEID\",\n \"id_value\": \"example\"\n }\n}"
},
"url": {
"raw": "https://{{notification-api-url}}/v2/notifications/sms",
Expand Down Expand Up @@ -2146,7 +2146,7 @@
"response": []
},
{
"name": "send email with va_identifier",
"name": "send email with recipient_identifier",
"event": [
{
"listen": "prerequest",
Expand Down Expand Up @@ -2240,7 +2240,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"template_id\": \"{{template-id}}\",\n \"va_identifier\": {\n \"id_type\": \"VAPROFILEID\",\n \"value\": \"example\"\n }\n}"
"raw": "{\n \"template_id\": \"{{template-id}}\",\n \"recipient_identifier\": {\n \"id_type\": \"VAPROFILEID\",\n \"id_value\": \"example\"\n }\n}"
},
"url": {
"raw": "https://{{notification-api-url}}/v2/notifications/email",
Expand Down
8 changes: 4 additions & 4 deletions tests/app/notifications/test_process_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,12 @@ def test_persist_notification_persists_recipient_identifiers(
assert RecipientIdentifier.query.get((notification.id, id_type, id_value)) \
.notification_id == notification.id
assert RecipientIdentifier.query.get((notification.id, id_type, id_value)) \
.va_identifier_type == id_type
.id_type == id_type
assert RecipientIdentifier.query.get((notification.id, id_type, id_value)) \
.va_identifier_value == id_value
.id_value == id_value

assert notification.recipient_identifiers[id_type].va_identifier_value == id_value
assert notification.recipient_identifiers[id_type].va_identifier_type == id_type
assert notification.recipient_identifiers[id_type].id_value == id_value
assert notification.recipient_identifiers[id_type].id_type == id_type


@pytest.mark.parametrize('recipient_identifiers_enabled, recipient_identifier', [
Expand Down
Loading

0 comments on commit 4da6d3f

Please sign in to comment.