Skip to content

Commit

Permalink
Merge pull request #537 from edx/ammar/1953-monitoring-for-dsc-flow
Browse files Browse the repository at this point in the history
improve monitoring for DSC flow
  • Loading branch information
muhammad-ammar authored Jul 25, 2019
2 parents 2817b13 + bd1e6d9 commit 3ec1a20
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 90 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Change Log
Unreleased
----------

[1.8.6] - 2019-07-25
--------------------

* Add/Update logs for GrantDataSharingPermissions and DataSharingConsentView views to improve monitoring.

[1.8.5] - 2019-07-25
--------------------

Expand Down
51 changes: 44 additions & 7 deletions consent/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from __future__ import absolute_import, unicode_literals

from logging import getLogger

from edx_rest_framework_extensions.auth.bearer.authentication import BearerAuthentication
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from rest_framework.authentication import SessionAuthentication
Expand All @@ -18,6 +20,8 @@
from enterprise.api.throttles import ServiceUserThrottle
from enterprise.utils import get_request_value

LOGGER = getLogger(__name__)


class DataSharingConsentView(APIView):
"""
Expand Down Expand Up @@ -85,12 +89,29 @@ def get_consent_record(self, request):
Get the consent record relevant to the request at hand.
"""
username, course_id, program_uuid, enterprise_customer_uuid = self.get_required_query_params(request)
return get_data_sharing_consent(
dsc = get_data_sharing_consent(
username,
enterprise_customer_uuid,
course_id=course_id,
program_uuid=program_uuid
)
if not dsc:
log_message = (
'[Enterprise Consent API] The code was unable to get consent data for the user. '
'Course: {course_id}, '
'Program: {program_uuid}, '
'EnterpriseCustomer: {enterprise_customer_uuid}, '
'User: {username}, '
'ErrorCode: {error_code}'.format(
course_id=course_id,
program_uuid=program_uuid,
enterprise_customer_uuid=enterprise_customer_uuid,
username=username,
error_code='ENTGDS001',
)
)
LOGGER.error(log_message)
return dsc

def get_required_query_params(self, request):
"""
Expand All @@ -105,13 +126,29 @@ def get_required_query_params(self, request):
program_uuid = get_request_value(request, self.REQUIRED_PARAM_PROGRAM_UUID, '')
enterprise_customer_uuid = get_request_value(request, self.REQUIRED_PARAM_ENTERPRISE_CUSTOMER)
if not (username and (course_id or program_uuid) and enterprise_customer_uuid):
raise ConsentAPIRequestError(
self.get_missing_params_message([
("'username'", bool(username)),
("'enterprise_customer_uuid'", bool(enterprise_customer_uuid)),
("one of 'course_id' or 'program_uuid'", bool(course_id or program_uuid)),
])
exception_message = self.get_missing_params_message([
("'username'", bool(username)),
("'enterprise_customer_uuid'", bool(enterprise_customer_uuid)),
("one of 'course_id' or 'program_uuid'", bool(course_id or program_uuid)),
])
log_message = (
'[Enterprise Consent API] Required request values missing for action to be carried out. '
'Course: {course_id}, '
'Program: {program_uuid}, '
'EnterpriseCustomer: {enterprise_customer_uuid}, '
'User: {username}, '
'ErrorCode: {error_code}, '
'Message: {message}'.format(
course_id=course_id,
program_uuid=program_uuid,
enterprise_customer_uuid=enterprise_customer_uuid,
username=username,
error_code='ENTGDS000',
message=exception_message,
)
)
LOGGER.error(log_message)
raise ConsentAPIRequestError(exception_message)
return username, course_id, program_uuid, enterprise_customer_uuid

def get_missing_params_message(self, parameter_state):
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = "1.8.5"
__version__ = "1.8.6"

default_app_config = "enterprise.apps.EnterpriseConfig" # pylint: disable=invalid-name
Loading

0 comments on commit 3ec1a20

Please sign in to comment.