Skip to content

Commit

Permalink
Mark the current learner enterprise-customer active flag to True (#637)
Browse files Browse the repository at this point in the history
* Mark the current learner enterprise-customer active flag to True and all other enterprise-customers active flag to false
  • Loading branch information
zamanafzal authored Nov 26, 2019
1 parent fa42950 commit 902ee52
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Change Log
Unreleased
----------
[2.0.27] - 2019-11-26
---------------------

* Make the SAML enterprise active at login and de-activate other enterprises learner is linked to.

[2.0.26] - 2019-11-26
---------------------

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__ = "2.0.26"
__version__ = "2.0.27"

default_app_config = "enterprise.apps.EnterpriseConfig" # pylint: disable=invalid-name
5 changes: 5 additions & 0 deletions enterprise/tpa_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ def handle_enterprise_logistration(backend, user, **kwargs):
# proceed with the creation of a link between the user and the enterprise customer, then exit.
enterprise_customer_user, _ = EnterpriseCustomerUser.objects.update_or_create(
enterprise_customer=enterprise_customer,
active=True,
user_id=user.id
)
# if learner has activated enterprise we need to de-activate other enterprises learner is linked to
EnterpriseCustomerUser.objects.filter(
user_id=user.id
).exclude(enterprise_customer=enterprise_customer).update(active=False)
enterprise_customer_user.update_session(request)


Expand Down
39 changes: 37 additions & 2 deletions tests/test_tpa_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def test_handle_enterprise_logistration_user_linking(
assert handle_enterprise_logistration(backend, self.user) is None
assert EnterpriseCustomerUser.objects.filter(
enterprise_customer=enterprise_customer,
user_id=self.user.id
user_id=self.user.id,
active=True
).count() == 1

def test_handle_enterprise_logistration_not_user_linking(self):
Expand All @@ -84,9 +85,43 @@ def test_handle_enterprise_logistration_not_user_linking(self):
assert handle_enterprise_logistration(backend, self.user) is None
assert EnterpriseCustomerUser.objects.filter(
enterprise_customer=enterprise_customer,
user_id=self.user.id
user_id=self.user.id,
active=True
).count() == 0

def test_handle_enterprise_logistration_user_multiple_enterprises_linking(self):
"""
Test that if user has multiple enterprise_customers then active status of latest
enterprise_customer with which user is logged in will be marked as True and active
status of other enterprise_customers will be marked as False.
"""
backend = self.get_mocked_sso_backend()
self.user = UserFactory(is_active=True)
with mock.patch('enterprise.tpa_pipeline.get_enterprise_customer_for_running_pipeline') as fake_get_ec:
enterprise_customer = EnterpriseCustomerFactory(
enable_data_sharing_consent=False
)
enterprise_customer_old = EnterpriseCustomerFactory(
enable_data_sharing_consent=False
)
EnterpriseCustomerUser.objects.create(
enterprise_customer=enterprise_customer_old,
user_id=self.user.id,
active=True
)
fake_get_ec.return_value = enterprise_customer
assert handle_enterprise_logistration(backend, self.user) is None
assert EnterpriseCustomerUser.objects.filter(
enterprise_customer=enterprise_customer,
user_id=self.user.id,
active=True
).count() == 1
assert EnterpriseCustomerUser.objects.filter(
enterprise_customer=enterprise_customer_old,
user_id=self.user.id,
active=False
).count() == 1

def test_get_ec_for_pipeline(self):
"""
Test that we get the correct results for a given running pipeline.
Expand Down

0 comments on commit 902ee52

Please sign in to comment.