Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced unencrypted columns of user data credentials in moodle config #1988

Merged
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Change Log
Unreleased
----------

[4.10.2]
--------

feat: removed unencrypted user credentials data columns


[4.10.1]
--------

Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.10.1"
__version__ = "4.10.2"
18 changes: 3 additions & 15 deletions integrated_channels/moodle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import requests

from django.apps import apps
from django.conf import settings

from integrated_channels.exceptions import ClientError
from integrated_channels.integrated_channel.client import IntegratedChannelApiClient
Expand Down Expand Up @@ -135,12 +134,7 @@ def __init__(self, enterprise_configuration):
"""
super().__init__(enterprise_configuration)
self.config = apps.get_app_config('moodle')
token = (
enterprise_configuration.decrypted_token
if getattr(settings, 'FEATURES', {}).get('USE_ENCRYPTED_USER_DATA', False)
else enterprise_configuration.token
)
self.token = token or self._get_access_token()
self.token = enterprise_configuration.decrypted_token or self._get_access_token()
self.api_url = urljoin(self.enterprise_configuration.moodle_base_url, self.MOODLE_API_PATH)

def _post(self, additional_params):
Expand Down Expand Up @@ -180,12 +174,6 @@ def _get_access_token(self):
'service': self.enterprise_configuration.service_short_name
}

decrypted_username = self.enterprise_configuration.decrypted_username
username = self.enterprise_configuration.username
decrypted_password = self.enterprise_configuration.decrypted_password
password = self.enterprise_configuration.password
use_encrypted_user_data = getattr(settings, 'FEATURES', {}).get('USE_ENCRYPTED_USER_DATA', False)

response = requests.post(
urljoin(
self.enterprise_configuration.moodle_base_url,
Expand All @@ -196,8 +184,8 @@ def _get_access_token(self):
'Content-Type': 'application/x-www-form-urlencoded',
},
data={
"username": decrypted_username if use_encrypted_user_data else username,
"password": decrypted_password if use_encrypted_user_data else password,
"username": self.enterprise_configuration.decrypted_username,
"password": self.enterprise_configuration.decrypted_password,
},
)

Expand Down
37 changes: 37 additions & 0 deletions integrated_channels/moodle/migrations/0032_auto_20240117_1202.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 3.2.23 on 2024-01-17 12:02

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('moodle', '0031_moodlelearnerdatatransmissionaudit_transmission_status'),
]

operations = [
migrations.RemoveField(
model_name='historicalmoodleenterprisecustomerconfiguration',
name='password',
),
migrations.RemoveField(
model_name='historicalmoodleenterprisecustomerconfiguration',
name='token',
),
migrations.RemoveField(
model_name='historicalmoodleenterprisecustomerconfiguration',
name='username',
),
migrations.RemoveField(
model_name='moodleenterprisecustomerconfiguration',
name='password',
),
migrations.RemoveField(
model_name='moodleenterprisecustomerconfiguration',
name='token',
),
migrations.RemoveField(
model_name='moodleenterprisecustomerconfiguration',
name='username',
),
]
27 changes: 0 additions & 27 deletions integrated_channels/moodle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ class MoodleEnterpriseCustomerConfiguration(EnterpriseCustomerPluginConfiguratio
)
)

username = models.CharField(
max_length=255,
verbose_name="Webservice Username",
blank=True,
help_text=_(
"The API user's username used to obtain new tokens."
)
)

decrypted_username = EncryptedCharField(
max_length=255,
verbose_name="Encrypted Webservice Username",
Expand Down Expand Up @@ -100,15 +91,6 @@ def encrypted_username(self, value):
"""
self.decrypted_username = value

password = models.CharField(
max_length=255,
blank=True,
verbose_name="Webservice Password",
help_text=_(
"The API user's password used to obtain new tokens."
)
)

decrypted_password = EncryptedCharField(
max_length=255,
verbose_name="Encrypted Webservice Password",
Expand Down Expand Up @@ -143,15 +125,6 @@ def encrypted_password(self, value):
"""
self.decrypted_password = value

token = models.CharField(
max_length=255,
blank=True,
verbose_name="Webservice User Token",
help_text=_(
"The user's token for the Moodle webservice."
)
)

decrypted_token = EncryptedCharField(
max_length=255,
verbose_name="Encrypted Webservice Token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ def test_is_valid_field(self, mock_current_request):
self.moodle_config.decrypted_token = ''
self.moodle_config.decrypted_username = ''
self.moodle_config.decrypted_password = ''
self.moodle_config.token = ''
self.moodle_config.username = ''
self.moodle_config.password = ''
self.moodle_config.moodle_base_url = ''
self.moodle_config.service_short_name = ''
self.moodle_config.save()
Expand All @@ -158,9 +155,6 @@ def test_is_valid_field(self, mock_current_request):
self.moodle_config.decrypted_username = 'lmao'
self.moodle_config.decrypted_password = 'foobar'
self.moodle_config.decrypted_token = 'baa'
self.moodle_config.username = 'lmao'
self.moodle_config.password = 'foobar'
self.moodle_config.token = 'baa'
self.moodle_config.moodle_base_url = 'http://lovely.com'
self.moodle_config.service_short_name = 'short'
self.moodle_config.display_name = '1234!@#$'
Expand Down
6 changes: 0 additions & 6 deletions tests/test_integrated_channels/test_moodle/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,12 @@ def setUp(self):
decrypted_username=self.user,
decrypted_password=self.password,
decrypted_token=self.token,
username=self.user,
password=self.password,
token=self.token,
)
self.enterprise_custom_config = factories.MoodleEnterpriseCustomerConfigurationFactory(
moodle_base_url=self.custom_moodle_base_url,
decrypted_username=self.user,
decrypted_password=self.password,
decrypted_token=self.token,
username=self.user,
password=self.password,
token=self.token,
grade_scale=10,
grade_assignment_name='edX Grade Test'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def setUp(self):
moodle_base_url='foobar',
service_short_name='shortname',
category_id=1,
username='username',
password='password',
token='token',
decrypted_username='username',
decrypted_password='password',
decrypted_token='token',
)

@mock.patch('enterprise.api_client.discovery.CourseCatalogApiServiceClient')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ def setUp(self):
decrypted_username=self.user,
decrypted_password=self.password,
decrypted_token=self.api_token,
username=self.user,
password=self.password,
token=self.api_token,
)

def test_prepare_items_for_transmission(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ def setUp(self):
decrypted_username='username',
decrypted_password='password',
decrypted_token='token',
username='username',
password='password',
token='token',
)
self.payload = MoodleLearnerDataTransmissionAudit(
moodle_user_email=self.enterprise_customer.contact_email,
Expand Down
Loading