Merge pull request #18018 from edx/revert-17967-gbabey/revert-ENT-924

[ENT-924] Revert "Revert "Show Enterprise display name if we should hide sensit…
This commit is contained in:
Uman Shahzad
2018-04-24 05:43:49 +05:00
committed by GitHub
10 changed files with 118 additions and 75 deletions

View File

@@ -205,10 +205,14 @@ class WikiRedirectTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCas
self.assertEqual(resp.status_code, 200)
@patch.dict("django.conf.settings.FEATURES", {'ALLOW_WIKI_ROOT_ACCESS': True})
def test_consent_required(self):
@patch('openedx.features.enterprise_support.api.enterprise_customer_for_request')
def test_consent_required(self, mock_enterprise_customer_for_request):
"""
Test that enterprise data sharing consent is required when enabled for the various courseware views.
"""
# ENT-924: Temporary solution to replace sensitive SSO usernames.
mock_enterprise_customer_for_request.return_value = None
# Public wikis can be accessed by non-enrolled users, and so direct access is not gated by the consent page
course = CourseFactory.create()
course.allow_public_wiki_access = False

View File

@@ -68,12 +68,16 @@ class CourseInfoTestCase(EnterpriseTestConsentRequired, LoginEnrollmentTestCase,
self.assertNotIn("You are not currently enrolled in this course", resp.content)
# TODO: LEARNER-611: If this is only tested under Course Info, does this need to move?
def test_redirection_missing_enterprise_consent(self):
@mock.patch('openedx.features.enterprise_support.api.enterprise_customer_for_request')
def test_redirection_missing_enterprise_consent(self, mock_enterprise_customer_for_request):
"""
Verify that users viewing the course info who are enrolled, but have not provided
data sharing consent, are first redirected to a consent page, and then, once they've
provided consent, are able to view the course info.
"""
# ENT-924: Temporary solution to replace sensitive SSO usernames.
mock_enterprise_customer_for_request.return_value = None
self.setup_user()
self.enroll(self.course)

View File

@@ -2596,10 +2596,14 @@ class EnterpriseConsentTestCase(EnterpriseTestConsentRequired, ModuleStoreTestCa
CourseOverview.load_from_module_store(self.course.id)
CourseEnrollmentFactory(user=self.user, course_id=self.course.id)
def test_consent_required(self):
@patch('openedx.features.enterprise_support.api.enterprise_customer_for_request')
def test_consent_required(self, mock_enterprise_customer_for_request):
"""
Test that enterprise data sharing consent is required when enabled for the various courseware views.
"""
# ENT-924: Temporary solution to replace sensitive SSO usernames.
mock_enterprise_customer_for_request.return_value = None
course_id = unicode(self.course.id)
for url in (
reverse("courseware", kwargs=dict(course_id=course_id)),

View File

@@ -1659,10 +1659,14 @@ class EnterpriseConsentTestCase(EnterpriseTestConsentRequired, ForumsEnableMixin
self.addCleanup(translation.deactivate)
def test_consent_required(self, mock_request):
@patch('openedx.features.enterprise_support.api.enterprise_customer_for_request')
def test_consent_required(self, mock_enterprise_customer_for_request, mock_request):
"""
Test that enterprise data sharing consent is required when enabled for the various discussion views.
"""
# ENT-924: Temporary solution to replace sensitive SSO usernames.
mock_enterprise_customer_for_request.return_value = None
thread_id = 'dummy'
course_id = unicode(self.course.id)
mock_request.side_effect = make_mock_request_impl(course=self.course, text='dummy', thread_id=thread_id)

View File

@@ -11,7 +11,14 @@ from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils.http import urlquote_plus
from six import text_type
from openedx.features.enterprise_support.utils import get_enterprise_learner_generic_name
%>
<%
username = get_enterprise_learner_generic_name(request) or student.username
%>
<%block name="bodyclass">view-in-course view-progress</%block>
<%block name="headextra">
@@ -54,7 +61,7 @@ from six import text_type
</div>
% endif
<h2 class="hd hd-2 progress-certificates-title">
${_("Course Progress for Student '{username}' ({email})").format(username=student.username, email=student.email)}
${_("Course Progress for Student '{username}' ({email})").format(username=username, email=student.email)}
</h2>
<div class="wrapper-msg wrapper-auto-cert">

View File

@@ -2,32 +2,29 @@
<%page expression_filter="h"/>
<%namespace name='static' file='static_content.html'/>
## This template should not use the target student's details when masquerading, see TNL-4895
<%
self.real_user = getattr(user, 'real_user', user)
%>
<%!
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_urls_for_user
from openedx.core.djangoapps.user_api.accounts.utils import retrieve_last_sitewide_block_completed
from openedx.features.enterprise_support.utils import get_enterprise_learner_generic_name
%>
<%
profile_image_url = get_profile_image_urls_for_user(self.real_user)['medium']
username = self.real_user.username
resume_block = retrieve_last_sitewide_block_completed(username)
## This template should not use the target student's details when masquerading, see TNL-4895
self.real_user = getattr(user, 'real_user', user)
profile_image_url = get_profile_image_urls_for_user(self.real_user)['medium']
username = self.real_user.username
resume_block = retrieve_last_sitewide_block_completed(username)
displayname = get_enterprise_learner_generic_name(request) or username
%>
<div class="nav-item hidden-mobile">
<a href="${reverse('dashboard')}" class="menu-title">
<img class="user-image-frame" src="${profile_image_url}" alt="">
<span class="sr-only">${_("Dashboard for:")}</span>
<span class="username">${username}</span>
<span class="username">${displayname}</span>
</a>
</div>
<div class="nav-item hidden-mobile nav-item-dropdown" tabindex="-1">

View File

@@ -2,19 +2,21 @@
<%page expression_filter="h"/>
<%namespace name='static' file='static_content.html'/>
## This template should not use the target student's details when masquerading, see TNL-4895
<%
self.real_user = getattr(user, 'real_user', user)
username = self.real_user.username
profile_image_url = get_profile_image_urls_for_user(self.real_user)['medium']
%>
<%!
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_urls_for_user
from openedx.features.enterprise_support.utils import get_enterprise_learner_generic_name
%>
<%
## This template should not use the target student's details when masquerading, see TNL-4895
self.real_user = getattr(user, 'real_user', user)
username = get_enterprise_learner_generic_name(request) or self.real_user.username
profile_image_url = get_profile_image_urls_for_user(self.real_user)['medium']
%>
% if uses_bootstrap:
<div class="nav-item nav-item-hidden-collapsed container">
<div class="nav align-items-center">

View File

@@ -169,65 +169,64 @@ class EnterpriseApiClient(object):
fetch_enterprise_learner_data(user)
Argument:
site: (Site) site instance
user: (User) django auth user
Returns:
dict: {
"enterprise_api_response_for_learner": {
"count": 1,
"num_pages": 1,
"current_page": 1,
"results": [
{
"enterprise_customer": {
"uuid": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"name": "TestShib",
"catalog": 2,
"active": true,
"site": {
"domain": "example.com",
"name": "example.com"
},
"enable_data_sharing_consent": true,
"enforce_data_sharing_consent": "at_login",
"branding_configuration": {
"enterprise_customer": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"logo": "https://open.edx.org/sites/all/themes/edx_open/logo.png"
},
"enterprise_customer_entitlements": [
{
"enterprise_customer": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"entitlement_id": 69
}
]
dict:
{
"count": 1,
"num_pages": 1,
"current_page": 1,
"next": null,
"start": 0,
"previous": null
"results": [
{
"enterprise_customer": {
"uuid": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"name": "TestShib",
"catalog": 2,
"active": true,
"site": {
"domain": "example.com",
"name": "example.com"
},
"user_id": 5,
"user": {
"username": "staff",
"first_name": "",
"last_name": "",
"email": "staff@example.com",
"is_staff": true,
"is_active": true,
"date_joined": "2016-09-01T19:18:26.026495Z"
"enable_data_sharing_consent": true,
"enforce_data_sharing_consent": "at_login",
"branding_configuration": {
"enterprise_customer": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"logo": "https://open.edx.org/sites/all/themes/edx_open/logo.png"
},
"data_sharing_consent_records": [
"enterprise_customer_entitlements": [
{
"username": "staff",
"enterprise_customer_uuid": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"exists": true,
"course_id": "course-v1:edX DemoX Demo_Course",
"consent_provided": true,
"consent_required": false
"enterprise_customer": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"entitlement_id": 69
}
]
}
],
"next": null,
"start": 0,
"previous": null
}
],
"replace_sensitive_sso_username": False,
},
"user_id": 5,
"user": {
"username": "staff",
"first_name": "",
"last_name": "",
"email": "staff@example.com",
"is_staff": true,
"is_active": true,
"date_joined": "2016-09-01T19:18:26.026495Z"
},
"data_sharing_consent_records": [
{
"username": "staff",
"enterprise_customer_uuid": "cf246b88-d5f6-4908-a522-fc307e0b0c59",
"exists": true,
"course_id": "course-v1:edX DemoX Demo_Course",
"consent_provided": true,
"consent_required": false
}
]
}
],
}
Raises:

View File

@@ -223,6 +223,7 @@ class EnterpriseTestConsentRequired(SimpleTestCase):
Mixin to help test the data_sharing_consent_required decorator.
"""
@mock.patch('openedx.features.enterprise_support.utils.get_enterprise_learner_generic_name')
@mock.patch('openedx.features.enterprise_support.api.enterprise_customer_from_api')
@mock.patch('openedx.features.enterprise_support.api.enterprise_customer_uuid_for_request')
@mock.patch('openedx.features.enterprise_support.api.reverse')
@@ -237,6 +238,7 @@ class EnterpriseTestConsentRequired(SimpleTestCase):
mock_reverse,
mock_enterprise_customer_uuid_for_request,
mock_enterprise_customer_from_api,
mock_get_enterprise_learner_generic_name,
status_code=200,
):
"""
@@ -249,6 +251,9 @@ class EnterpriseTestConsentRequired(SimpleTestCase):
return '/enterprise/grant_data_sharing_permissions'
return reverse(*args, **kwargs)
# ENT-924: Temporary solution to replace sensitive SSO usernames.
mock_get_enterprise_learner_generic_name.return_value = ''
mock_reverse.side_effect = mock_consent_reverse
mock_enterprise_enabled.return_value = True
mock_enterprise_customer_uuid_for_request.return_value = 'fake-uuid'

View File

@@ -220,3 +220,20 @@ def update_account_settings_context_for_enterprise(context, enterprise_customer)
enterprise_context['sync_learner_profile_data'] = identity_provider.sync_learner_profile_data
context.update(enterprise_context)
def get_enterprise_learner_generic_name(request):
"""
Get a generic name concatenating the Enterprise Customer name and 'Learner'.
ENT-924: Temporary solution for hiding potentially sensitive SSO names.
When a more complete solution is put in place, delete this function and all of its uses.
"""
# Prevent a circular import. This function makes sense to be in this module though. And see function description.
from openedx.features.enterprise_support.api import enterprise_customer_for_request
enterprise_customer = enterprise_customer_for_request(request)
return (
enterprise_customer['name'] + 'Learner'
if enterprise_customer and enterprise_customer['replace_sensitive_sso_username']
else ''
)