Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airlock Notifier: Provide a link to the request in the UI in the email #2754

Merged
merged 15 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.54"
tanya-borisova marked this conversation as resolved.
Show resolved Hide resolved
__version__ = "0.5.0"
6 changes: 3 additions & 3 deletions api_app/event_grid/event_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ async def send_status_changed_event(airlock_request: AirlockRequest, previous_st
async def send_airlock_notification_event(airlock_request: AirlockRequest, emails: Dict):
request_id = airlock_request.id
status = airlock_request.status.value
short_workspace_id = airlock_request.workspaceId[-4:]
workspace_id = airlock_request.workspaceId
snake_case_emails = {re.sub(r'(?<!^)(?=[A-Z])', '_', role_name).lower(): role_id for role_name, role_id in emails.items()}

airlock_notification = EventGridEvent(
event_type="airlockNotification",
data=AirlockNotificationData(request_id=request_id, event_type="status_changed", event_value=status, emails=snake_case_emails, workspace_id=short_workspace_id).__dict__,
data=AirlockNotificationData(request_id=request_id, event_type="status_changed", event_value=status, emails=snake_case_emails, workspace_id=workspace_id).__dict__,
tanya-borisova marked this conversation as resolved.
Show resolved Hide resolved
subject=f"{request_id}/airlockNotification",
data_version="2.0"
data_version="3.0"
)
logging.info(f"Sending airlock notification event with request ID {request_id}, status: {status}")
await publish_event(airlock_notification, config.EVENT_GRID_AIRLOCK_NOTIFICATION_TOPIC_ENDPOINT)
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def sample_status_changed_event(new_status="draft", previous_status=None):
def sample_airlock_notification_event(status="draft"):
status_changed_event = EventGridEvent(
event_type="airlockNotification",
data=AirlockNotificationData(request_id=AIRLOCK_REQUEST_ID, event_type="status_changed", event_value=status, emails={"workspace_researcher": ["researcher@outlook.com"], "workspace_owner": ["owner@outlook.com"], "airlock_manager": ["manager@outlook.com"]}, workspace_id=WORKSPACE_ID[-4:]).__dict__,
data=AirlockNotificationData(request_id=AIRLOCK_REQUEST_ID, event_type="status_changed", event_value=status, emails={"workspace_researcher": ["researcher@outlook.com"], "workspace_owner": ["owner@outlook.com"], "airlock_manager": ["manager@outlook.com"]}, workspace_id=WORKSPACE_ID).__dict__,
subject=f"{AIRLOCK_REQUEST_ID}/airlockNotification",
data_version="2.0"
)
Expand Down
1 change: 1 addition & 0 deletions templates/shared_services/airlock_notifier/.env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TRE_ID=__CHANGE_ME__
TRE_URL=__CHANGE_ME__
SMTP_SERVER_ADDRESS="__CHANGE_ME__"
SMTP_USERNAME="__CHANGE_ME__"
SMTP_PASSWORD="__CHANGE_ME__"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"Send_Email_with_SMTP": {
"inputs": {
"body": {
"Body": "<p>Airlock request id: @{body('Parse_JSON')?['data']?['request_id']}<br>\nWorkspace id: @{body('Parse_JSON')?['data']?['workspace_id']}</p>",
"Body": "<a href=\"@{parameters('tre_url')}/workspaces/@{body('Parse_JSON')?['data']?['workspace_id']}/requests/@{body('Parse_JSON')?['data']?['request_id']}\">View the request</a>",
"From": "@parameters('smtp_from_email')",
"Subject": "@variables('message')",
"To": "@{join(variables('recipients'), ';')}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"smtp_from_email": {
"type": "String",
"value": "@appsetting('smtp_from_email')"
},
"tre_url": {
"type": "String",
"value": "@appsetting('tre_url')"
}
}
6 changes: 6 additions & 0 deletions templates/shared_services/airlock_notifier/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
"env": "TRE_ID"
}
},
{
"name": "tre_url",
"source": {
"env": "TRE_URL"
}
},
{
"name": "id",
"source": {
Expand Down
8 changes: 7 additions & 1 deletion templates/shared_services/airlock_notifier/porter.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: tre-shared-service-airlock-notifier
version: 0.2.1
version: 0.2.2
description: "A shared service notifying on Airlock Operations"
registry: azuretre
dockerfile: Dockerfile.tmpl
Expand All @@ -19,6 +19,10 @@ parameters:
- name: tre_id
type: string
description: "The ID of the parent TRE instance e.g., mytre-dev-3142"
- name: tre_url
type: string
description: "The URL of the parent TRE instance, e.g. https://mytre-dev-3142.uksouth.cloudapp.com"
default: ""
- name: id
type: string
description: "Resource ID"
Expand Down Expand Up @@ -63,6 +67,7 @@ install:
vars:
tre_id: "{{ bundle.parameters.tre_id }}"
tre_resource_id: "{{ bundle.parameters.id }}"
tre_url: "{{ bundle.parameters.tre_url }}"
smtp_server_address: "{{ bundle.parameters.smtp_server_address }}"
smtp_username: "{{ bundle.parameters.smtp_username }}"
smtp_password: "{{ bundle.parameters.smtp_password }}"
Expand Down Expand Up @@ -113,6 +118,7 @@ uninstall:
vars:
tre_id: "{{ bundle.parameters.tre_id }}"
tre_resource_id: "{{ bundle.parameters.id }}"
tre_url: "{{ bundle.parameters.tre_url }}"
smtp_server_address: "{{ bundle.parameters.smtp_server_address }}"
smtp_username: "{{ bundle.parameters.smtp_username }}"
smtp_password: "{{ bundle.parameters.smtp_password }}"
Expand Down
14 changes: 13 additions & 1 deletion templates/shared_services/airlock_notifier/template_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,26 @@
"type": "string",
"title": "SMTP Password",
"description": "SMTP Password",
"updateable": false
"updateable": false,
"sensitive": true
},
"smtp_from_email": {
"$id": "#/properties/smtp_from_email",
"type": "string",
"title": "SMTP From Email",
"description": "SMTP From Email",
"updateable": false
},
"tre_url": {
"$id": "#/properties/tre_url",
"type": "string",
"title": "TRE URL",
"description": "If your TRE URL is different from ${TRE_ID}.${LOCATION}.cloudapp.azure.com, please enter it here",
tamirkamara marked this conversation as resolved.
Show resolved Hide resolved
"updateable": false,
"pattern": "^(https:|http:|www\\.)\\S*",
"examples": [
"https://mytre.westeurope.cloudapp.azure.com"
]
}
},
"pipeline": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ resource "azurerm_logic_app_standard" "logic_app" {
"resource_group" = data.azurerm_resource_group.core.name
"smtp_connection_runtime_url" = jsondecode(azurerm_resource_group_template_deployment.smtp_api_connection.output_content).connectionRuntimeUrl.value
"smtp_from_email" = var.smtp_from_email
"tre_url" = var.tre_url != "" ? var.tre_url : local.default_tre_url
"APPLICATIONINSIGHTS_CONNECTION_STRING" = data.azurerm_application_insights.core.connection_string
}
site_config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ locals {
tre_id = var.tre_id
tre_shared_service_id = var.tre_resource_id
}
default_tre_url = "https://${var.tre_id}.${data.azurerm_resource_group.core.location}.cloudapp.azure.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ variable "tre_resource_id" {
description = "Resource ID"
}

variable "tre_url" {
type = string
description = "TRE URL"
default = ""
}

variable "smtp_server_address" {
type = string
}
Expand Down