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

Helpdesk integration #2159

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
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
19 changes: 9 additions & 10 deletions .envs/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ S3_POLICY_DOCUMENT_TEMPLATE_BASE64=e30=
S3_PERMISSIONS_BOUNDARY_ARN=my-arn
S3_ROLE_PREFIX=my-prefix

ZENDESK_EMAIL=test@test.com
# ZENDESK_SUBDOMAIN just requires the subdomain part not the full url
# i.e. for subdomain.zendesk.com the value should be subdomain
ZENDESK_SUBDOMAIN=subdomain
ZENDESK_TOKEN=abcd

# ZENDESK_SERVICE_FIELD_ID is a numeric value for a custom field within zendesk which is
# set to the ZENDESK_SERVIE_FIELD_VALUE when requesting access to datasets zendesk.py
ZENDESK_SERVICE_FIELD_ID=numeric_field_id
ZENDESK_SERVICE_FIELD_VALUE=field_value
# HELP_DESK_SERVICE_FIELD_ID is a numeric value for a custom field within the help desk which is
# set to the HELPDESK_SERVICE_FIELD_VALUE when requesting access to datasets help_desk.py
HELP_DESK_EMAIL=test@test.com
HELP_DESK_SERVICE_FIELD_ID=numeric_field_id
HELP_DESK_SERVICE_FIELD_VALUE=field_value

# helpdesk abstraction
HELP_DESK_INTERFACE=helpdesk_client.interfaces.HelpDeskStubbed
HELP_DESK_CREDS=xxx

NOTIFY_API_KEY=notify-token
FERNET_EMAIL_TOKEN_KEY=generate-using-fernet-generate-key
Expand Down
11 changes: 6 additions & 5 deletions .envs/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ AWS_ECR_ENDPOINT_URL=http://api.ecr.my-region-1.amazonaws.com:8008/
PROMETHEUS_DOMAIN=some.domain.com
METRICS_SERVICE_DISCOVERY_BASIC_AUTH_USER=user
METRICS_SERVICE_DISCOVERY_BASIC_AUTH_PASSWORD=password
ZENDESK_EMAIL=test@test.com
ZENDESK_SUBDOMAIN=subdomain
ZENDESK_TOKEN=abcd
ZENDESK_SERVICE_FIELD_ID=654321
ZENDESK_SERVICE_FIELD_VALUE=field_value
HELP_DESK_EMAIL=test@test.com
HELP_DESK_SERVICE_FIELD_ID=654321
HELP_DESK_SERVICE_FIELD_VALUE=field_value
S3_ASSUME_ROLE_POLICY_DOCUMENT_BASE64=e30=
S3_POLICY_NAME=my-policy
S3_POLICY_DOCUMENT_TEMPLATE_BASE64=e30=
Expand All @@ -67,6 +65,9 @@ S3_ROLE_PREFIX=my-prefix

ALLOWED_HOSTS='dataworkspace.test'

HELP_DESK_INTERFACE=helpdesk_client.interfaces.HelpDeskStubbed


UPLOADS_BUCKET=an-upload-bucket
MIRROR_REMOTE_ROOT=http://127.0.0.1:8006/some-remote-folder/

Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ docker-test-unit: docker-build

.PHONY: docker-test-integration
docker-test-integration: docker-build
docker-compose -f docker-compose-test.yml -p data-workspace-test run data-workspace-test pytest test/

docker-compose -f docker-compose-test.yml -p data-workspace-test run -e DJANGO_SETTINGS_MODULE=dataworkspace.settings.integration_tests data-workspace-test pytest test/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the integration settings module as an env var as this command was using the base settings originally.


.PHONY: docker-test
docker-test: docker-test-integration docker-test-unit
Expand Down
4 changes: 2 additions & 2 deletions dataworkspace/dataworkspace/apps/applications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
from dataworkspace.apps.eventlog.models import EventLog
from dataworkspace.apps.eventlog.utils import log_event
from dataworkspace.notify import decrypt_token, send_email
from dataworkspace.zendesk import update_zendesk_ticket
from dataworkspace.help_desk import update_helpdesk_ticket

TOOL_LOADING_MESSAGES = [
{
Expand Down Expand Up @@ -726,7 +726,7 @@ def error(email_address_error):
return error(f"{user.get_full_name()} already has access")

if email_address == token_data.get("email", "").strip().lower():
update_zendesk_ticket(
update_helpdesk_ticket(
token_data["ticket"],
comment=f"Access granted by {request.user.email}",
status="solved",
Expand Down
6 changes: 3 additions & 3 deletions dataworkspace/dataworkspace/apps/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
from dataworkspace.apps.eventlog.models import EventLog
from dataworkspace.apps.eventlog.utils import log_event
from dataworkspace.zendesk import create_support_request
from dataworkspace.help_desk import create_support_request

logger = logging.getLogger("app")

Expand Down Expand Up @@ -101,7 +101,7 @@ class SupportView(FormView):
form_class = SupportForm
template_name = "core/support.html"

ZENDESK_TAGS = {"data-request": "data_request"}
HELP_DESK_TAGS = {"data-request": "data_request"}

def get_context_data(self, **kwargs):
ctx = super().get_context_data()
Expand All @@ -122,7 +122,7 @@ def form_valid(self, form):
if cleaned["support_type"] == form.SupportTypes.TECH_SUPPORT:
return HttpResponseRedirect(f'{reverse("technical-support")}?email={cleaned["email"]}')

tag = self.ZENDESK_TAGS.get(self.request.GET.get("tag"))
tag = self.HELP_DESK_TAGS.get(self.request.GET.get("tag"))
ticket_id = create_support_request(
self.request.user, cleaned["email"], cleaned["message"], tag=tag
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.15 on 2022-09-26 17:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("request_access", "0004_alter_accessrequest_training_screenshot"),
]

operations = [
migrations.RenameField(
model_name="accessrequest",
old_name="zendesk_reference_number",
new_name="help_desk_reference_number",
),
]
4 changes: 2 additions & 2 deletions dataworkspace/dataworkspace/apps/request_access/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class AccessRequest(TimeStampedModel):
spss_and_stata = models.BooleanField(default=False, blank=True)
line_manager_email_address = models.CharField(max_length=256, null=True)
reason_for_spss_and_stata = models.TextField(null=True)
zendesk_reference_number = models.CharField(max_length=256, null=True)
help_desk_reference_number = models.CharField(max_length=256, null=True)

def __str__(self):
return f"{self.requester} - Zendesk reference number: {self.zendesk_reference_number}"
return f"{self.requester} - Help desk reference number: {self.help_desk_reference_number}"

@property
def journey(self):
Expand Down
14 changes: 7 additions & 7 deletions dataworkspace/dataworkspace/apps/request_access/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)

from dataworkspace.apps.request_access import models
from dataworkspace import zendesk
from dataworkspace import help_desk


class DatasetAccessRequest(CreateView):
Expand Down Expand Up @@ -173,7 +173,7 @@ class AccessRequestConfirmationPage(RequestAccessMixin, DetailView):

def get(self, request, *args, **kwargs):
access_request = self.get_object()
if not access_request.zendesk_reference_number:
if not access_request.help_desk_reference_number:
catalogue_item = (
find_dataset(access_request.catalogue_item_id, self.request.user)
if access_request.catalogue_item_id
Expand All @@ -184,15 +184,15 @@ def get(self, request, *args, **kwargs):
isinstance(catalogue_item, VisualisationCatalogueItem)
and catalogue_item.visualisation_template is not None
):
access_request.zendesk_reference_number = (
zendesk.notify_visualisation_access_request(
access_request.help_desk_reference_number = (
help_desk.notify_visualisation_access_request(
request,
access_request,
catalogue_item,
)
)
else:
access_request.zendesk_reference_number = zendesk.create_zendesk_ticket(
access_request.help_desk_reference_number = help_desk.create_help_desk_ticket(
request,
access_request,
catalogue_item,
Expand All @@ -205,15 +205,15 @@ def get(self, request, *args, **kwargs):
EventLog.TYPE_DATASET_ACCESS_REQUEST,
catalogue_item,
extra={
"ticket_reference": access_request.zendesk_reference_number,
"ticket_reference": access_request.help_desk_reference_number,
},
)
else:
log_event(
request.user,
EventLog.TYPE_TOOLS_ACCESS_REQUEST,
extra={
"ticket_reference": access_request.zendesk_reference_number,
"ticket_reference": access_request.help_desk_reference_number,
},
)
return super().get(request, *args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.15 on 2022-09-26 17:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("request_data", "0004_datarequest_data_licence"),
]

operations = [
migrations.RenameField(
model_name="datarequest",
old_name="zendesk_ticket_id",
new_name="help_desk_ticket_id",
),
]
2 changes: 1 addition & 1 deletion dataworkspace/dataworkspace/apps/request_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ class DataRequest(TimeStampedModel):
choices=DataRequestStatus.choices,
default=DataRequestStatus.draft,
)
zendesk_ticket_id = models.CharField(max_length=256)
help_desk_ticket_id = models.CharField(max_length=256)
15 changes: 10 additions & 5 deletions dataworkspace/dataworkspace/apps/request_data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
RoleType,
DataRequestStatus,
)
from dataworkspace.zendesk import create_support_request # pylint: disable=import-error
from dataworkspace.help_desk import create_support_request # pylint: disable=import-error


class RequestData(TemplateView):
Expand Down Expand Up @@ -249,11 +249,11 @@ def post(self, request, *args, **kwargs):

# If they've hacked the URL, some required fields might be blank.
try:
obj.clean_fields(exclude=["zendesk_ticket_id"])
obj.clean_fields(exclude=["help_desk_ticket_id"])
except ValidationError:
return HttpResponseBadRequest()

zendesk_message = f"""
help_desk_message = f"""
A request for a new dataset on Data Workspace has been submitted. Here are the details:

# Request details
Expand Down Expand Up @@ -288,16 +288,21 @@ def post(self, request, *args, **kwargs):
{obj.requester.email}
"""

from django.conf import settings

print("settings:::", flush=True)
print(settings.HELP_DESK_INTERFACE, flush=True)

ticket_id = create_support_request(
obj.requester,
obj.requester.email,
zendesk_message,
help_desk_message,
tag="request-for-data",
subject="Request for new dataset on Data Workspace",
)

obj.status = DataRequestStatus.submitted
obj.zendesk_ticket_id = ticket_id
obj.help_desk_ticket_id = ticket_id
obj.save()

return HttpResponseRedirect(
Expand Down
2 changes: 1 addition & 1 deletion dataworkspace/dataworkspace/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def common(request):
"NOTIFY_ON_MASTER_DATASET_CHANGE_FLAG": settings.NOTIFY_ON_MASTER_DATASET_CHANGE_FLAG,
"NOTIFY_ON_DATACUT_CHANGE_FLAG": settings.NOTIFY_ON_DATACUT_CHANGE_FLAG,
"NOTIFY_ON_REFERENCE_DATASET_CHANGE_FLAG": settings.NOTIFY_ON_REFERENCE_DATASET_CHANGE_FLAG,
"ZENDESK_EMAIL": settings.ZENDESK_EMAIL,
"HELP_DESK_EMAIL": settings.HELP_DESK_EMAIL,
"TEAMS_DATA_WORKSPACE_COMMUNITY_URL": settings.TEAMS_DATA_WORKSPACE_COMMUNITY_URL,
"DATA_WORKSPACE_ROADMAP_URL": settings.DATA_WORKSPACE_ROADMAP_URL,
"SSO_USER_ID": request.META.get("HTTP_SSO_PROFILE_USER_ID", ""),
Expand Down
Loading