Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
206f73d0
Unverified
Commit
206f73d0
authored
7 years ago
by
Bill Filler
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #17812 from edx/ibrahimahmed443/WL-1491
Ibrahimahmed443/wl 1491
parents
028ad2eb
45831a07
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openedx/features/enterprise_support/api.py
+27
-1
27 additions, 1 deletion
openedx/features/enterprise_support/api.py
openedx/features/enterprise_support/tests/test_api.py
+27
-0
27 additions, 0 deletions
openedx/features/enterprise_support/tests/test_api.py
with
54 additions
and
1 deletion
openedx/features/enterprise_support/api.py
+
27
−
1
View file @
206f73d0
...
...
@@ -22,7 +22,8 @@ from third_party_auth.pipeline import get as get_partial_pipeline
from
third_party_auth.provider
import
Registry
try
:
from
enterprise.models
import
EnterpriseCustomer
from
consent.models
import
DataSharingConsent
from
enterprise.models
import
EnterpriseCustomer
,
EnterpriseCustomerUser
except
ImportError
:
pass
...
...
@@ -430,6 +431,31 @@ def consent_needed_for_course(request, user, course_id, enrollment_exists=False)
return
consent_needed
def
get_consent_required_courses
(
user
,
course_ids
):
"""
Returns a set of course_ids that require consent
Note that this function makes use of the Enterprise models directly instead of using the API calls
"""
result
=
set
()
if
not
enterprise_enabled
():
return
result
enterprise_learner
=
EnterpriseCustomerUser
.
objects
.
filter
(
user_id
=
user
.
id
).
first
()
if
not
enterprise_learner
or
not
enterprise_learner
.
enterprise_customer
:
return
result
enterprise_uuid
=
enterprise_learner
.
enterprise_customer
.
uuid
data_sharing_consent
=
DataSharingConsent
.
objects
.
filter
(
username
=
user
.
username
,
course_id__in
=
course_ids
,
enterprise_customer__uuid
=
enterprise_uuid
)
for
consent
in
data_sharing_consent
:
if
consent
.
consent_required
():
result
.
add
(
consent
.
course_id
)
return
result
def
get_enterprise_consent_url
(
request
,
course_id
,
user
=
None
,
return_to
=
None
,
enrollment_exists
=
False
):
"""
Build a URL to redirect the user to the Enterprise app to provide data sharing
...
...
This diff is collapsed.
Click to expand it.
openedx/features/enterprise_support/tests/test_api.py
+
27
−
0
View file @
206f73d0
...
...
@@ -14,11 +14,13 @@ from django.core.urlresolvers import reverse
from
django.http
import
HttpResponseRedirect
from
django.test.utils
import
override_settings
from
consent.models
import
DataSharingConsent
from
openedx.core.djangolib.testing.utils
import
CacheIsolationTestCase
from
openedx.features.enterprise_support.api
import
(
ConsentApiClient
,
ConsentApiServiceClient
,
consent_needed_for_course
,
get_consent_required_courses
,
data_sharing_consent_required
,
EnterpriseApiClient
,
EnterpriseApiServiceClient
,
...
...
@@ -28,6 +30,7 @@ from openedx.features.enterprise_support.api import (
insert_enterprise_pipeline_elements
,
enterprise_enabled
,
)
from
openedx.features.enterprise_support.tests.factories
import
EnterpriseCustomerUserFactory
from
openedx.features.enterprise_support.tests.mixins.enterprise
import
EnterpriseServiceMockMixin
from
openedx.features.enterprise_support.utils
import
get_cache_key
from
student.tests.factories
import
UserFactory
...
...
@@ -183,6 +186,30 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
httpretty
.
reset
()
self
.
assertFalse
(
consent_needed_for_course
(
request
,
user
,
'
fake-course
'
))
@httpretty.activate
@mock.patch
(
'
enterprise.models.EnterpriseCustomer.catalog_contains_course
'
)
def
test_get_consent_required_courses
(
self
,
mock_catalog_contains_course
):
mock_catalog_contains_course
.
return_value
=
True
user
=
UserFactory
()
enterprise_customer_user
=
EnterpriseCustomerUserFactory
(
user_id
=
user
.
id
)
course_id
=
'
fake-course
'
data_sharing_consent
=
DataSharingConsent
(
course_id
=
course_id
,
enterprise_customer
=
enterprise_customer_user
.
enterprise_customer
,
username
=
user
.
username
,
granted
=
False
)
data_sharing_consent
.
save
()
consent_required
=
get_consent_required_courses
(
user
,
[
course_id
])
self
.
assertTrue
(
course_id
in
consent_required
)
# now grant consent and call our method again
data_sharing_consent
.
granted
=
True
data_sharing_consent
.
save
()
consent_required
=
get_consent_required_courses
(
user
,
[
course_id
])
self
.
assertFalse
(
course_id
in
consent_required
)
@httpretty.activate
@mock.patch
(
'
openedx.features.enterprise_support.api.get_enterprise_learner_data
'
)
@mock.patch
(
'
openedx.features.enterprise_support.api.EnterpriseCustomer
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment