Skip to content

Commit

Permalink
Merge branch 'MueezKhan/Remove-Blackboard-Unencrypted-Columns-ENT8010…
Browse files Browse the repository at this point in the history
…' of github.com:openedx/edx-enterprise into MueezKhan/Remove-Blackboard-Unencrypted-Columns-From-Models-ENT8010
  • Loading branch information
MueezKhan246 committed May 7, 2024
2 parents 1b0d3c5 + bec3546 commit eec9c13
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions integrated_channels/blackboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,17 @@ class Meta:
@property
def oauth_authorization_url(self):
"""
Returns: the oauth authorization url when the blackboard_base_url and client_id are available.
Returns: the oauth authorization url when the blackboard_base_url and decrypted_client_id are available.
Args:
obj: The instance of BlackboardEnterpriseCustomerConfiguration
being rendered with this admin form.
"""
if self.blackboard_base_url and self.client_id:
if self.blackboard_base_url and self.decrypted_client_id:
return (f'{self.blackboard_base_url}/learn/api/public/v1/oauth2/authorizationcode'
f'?redirect_uri={LMS_OAUTH_REDIRECT_URL}&'
f'scope=read%20write%20delete%20offline&response_type=code&'
f'client_id={self.client_id}&state={self.uuid}')
f'client_id={self.decrypted_client_id}&state={self.uuid}')
else:
return None

Expand Down
6 changes: 4 additions & 2 deletions integrated_channels/blackboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def populate_decrypted_fields_blackboard(apps, schema_editor=None): # pylint: d
)

for blackboard_enterprise_configuration in BlackboardEnterpriseCustomerConfiguration.objects.all():
blackboard_enterprise_configuration.decrypted_client_id = blackboard_enterprise_configuration.client_id
blackboard_enterprise_configuration.decrypted_client_secret = blackboard_enterprise_configuration.client_secret
blackboard_enterprise_configuration.decrypted_client_id = getattr(
blackboard_enterprise_configuration, 'client_id', '')
blackboard_enterprise_configuration.decrypted_client_secret = getattr(
blackboard_enterprise_configuration, 'client_secret', '')
blackboard_enterprise_configuration.save()
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import json
from unittest import mock

from django.apps import apps
from django.urls import reverse

from enterprise.constants import ENTERPRISE_ADMIN_ROLE
from enterprise.utils import localized_utcnow
from integrated_channels.blackboard.models import BlackboardEnterpriseCustomerConfiguration
from integrated_channels.blackboard.utils import populate_decrypted_fields_blackboard
from test_utils import FAKE_UUIDS, APITest, factories


Expand Down Expand Up @@ -129,6 +131,26 @@ def test_update(self, mock_current_request):
self.assertEqual(self.enterprise_customer_conf.blackboard_base_url, 'http://testing2')
self.assertEqual(response.status_code, 200)

@mock.patch('enterprise.rules.crum.get_current_request')
def test_populate_decrypted_fields(self, mock_current_request):
mock_current_request.return_value = self.get_request_with_jwt_cookie(
system_wide_role=ENTERPRISE_ADMIN_ROLE,
context=self.enterprise_customer.uuid,
)
url = reverse('api:v1:blackboard:configuration-detail', args=[self.enterprise_customer_conf.id])
client_secret = getattr(self.enterprise_customer_conf, 'client_id', '')
payload = {
'encrypted_client_secret': '1000',
'enterprise_customer': FAKE_UUIDS[0],
}
self.client.put(url, payload)
self.enterprise_customer_conf.refresh_from_db()
self.assertEqual(self.enterprise_customer_conf.decrypted_client_secret, '1000')
populate_decrypted_fields_blackboard(apps)
self.enterprise_customer_conf.refresh_from_db()
self.assertEqual(self.enterprise_customer_conf.encrypted_client_secret, client_secret)
self.assertEqual(self.enterprise_customer_conf.encrypted_client_id, '')

@mock.patch('enterprise.rules.crum.get_current_request')
def test_partial_update(self, mock_current_request):
mock_current_request.return_value = self.get_request_with_jwt_cookie(
Expand Down

0 comments on commit eec9c13

Please sign in to comment.