Skip to content

Commit

Permalink
perf: add Quince support DS-776 (#196)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add compatibility with quince

* chore: update github workflows and tests

* chore: update requirements and remove constraints

* fix: add get_reponse to the test middlewares

* fix: some pylint errors

* fix: remove too-few-public-methods alert and fix f-strings

* fix: restore old format in the get_configurations

* fix: restore the logs to %s format

* fix: pylint tests

* fix: remove the test in python 310 and 11 for backports-zoneinfo

* docs: update doc
  • Loading branch information
MaferMazu authored Feb 27, 2024
1 parent fc5af47 commit c42930b
Show file tree
Hide file tree
Showing 41 changed files with 179 additions and 502 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
previous_tag: ${{ steps.tag_version.outputs.previous_tag }}
bump_commit_sha: ${{ steps.bumpversion.outputs.commit_hash }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.DEDALO_PAT }}
- name: Get next version
Expand All @@ -23,7 +23,7 @@ jobs:
default_prerelease_bump: false
dry_run: true
- name: Set up Python 3.8
uses: actions/setup-python@v4.5.0
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Create bumpversion
Expand All @@ -33,14 +33,14 @@ jobs:
bumpversion --new-version ${{ steps.tag_version.outputs.new_version }} setup.cfg
- name: Update Changelog
if: steps.tag_version.outputs.new_version
uses: stefanzweifel/changelog-updater-action@v1.6.2
uses: stefanzweifel/changelog-updater-action@v1.10.0
with:
latest-version: ${{ steps.tag_version.outputs.new_tag }}
release-notes: ${{ steps.tag_version.outputs.changelog }}
- name: Commit bumpversion
id: bumpversion
if: steps.tag_version.outputs.new_version
uses: stefanzweifel/git-auto-commit-action@v4.16.0
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{ github.ref }}
commit_message: "docs(bumpversion): ${{ steps.tag_version.outputs.previous_tag }} → ${{ steps.tag_version.outputs.new_version }}"
Expand All @@ -53,7 +53,7 @@ jobs:
tag: ${{ steps.tag_version.outputs.new_tag }}
changelog: ${{ steps.tag_version.outputs.changelog }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.DEDALO_PAT }}
- name: Create tag
Expand All @@ -66,7 +66,7 @@ jobs:
default_prerelease_bump: false
- name: Create a GitHub release
if: steps.tag_version.outputs.new_tag
uses: ncipollo/release-action@v1.12.0
uses: ncipollo/release-action@v1.14.0
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v4
6 changes: 3 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4.5.0
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
Expand All @@ -34,7 +34,7 @@ jobs:
run: |
python -m build --sdist --wheel --outdir dist/ .
- name: Publish package
uses: pypa/gh-action-pypi-publish@v1.6.4
uses: pypa/gh-action-pypi-publish@v1.8.11
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
max-parallel: 2
matrix:
python-version: ["3.8", "3.10", "3.11"]
django: ["32"]
python-version: ["3.8"]
django: ["32", "42"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache dependency
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ upgrade: ## update the requirements/*.txt files with the latest packages satisfy
$(PIP_COMPILE) -o requirements/test.txt requirements/test.in
$(PIP_COMPILE) -o requirements/tox.txt requirements/tox.in

grep -e "^django==" requirements/test.txt > requirements/django.txt
grep -e "^django==" requirements/test.txt > requirements/django42.txt
sed '/^[dD]jango==/d;' requirements/test.txt > requirements/test.tmp
mv requirements/test.tmp requirements/test.txt

Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Compatibility Notes
+-------------------+-----------------------+
| Palm | >=v10.0.0 |
+-------------------+-----------------------+
| Quince | >=v11.0.0 |
+-------------------+-----------------------+

**NOTE**: Since 6.2 version, eox-tenant does not support Django 2.2

Expand Down
12 changes: 6 additions & 6 deletions eox_tenant/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def config_link(self, route):
Helper method to display a link to the related config model.
"""
# pylint: disable=protected-access
url = reverse('admin:%s_%s_change' % (route._meta.app_label, "tenantconfig"), args=[route.config.id])
return mark_safe('<a href="%s">%s</a>' % (url, route.config.__unicode__()))
url = reverse(f'admin:{route._meta.app_label}_tenantconfig_change', args=[route.config.id])
return mark_safe(f'<a href="{url}">{route.config.__unicode__()}</a>')

config_link.allow_tags = True
config_link.short_description = "Configuration"
Expand Down Expand Up @@ -224,10 +224,10 @@ def microsites(self, org):

for microsite in microsites:
url = reverse(
'admin:%s_%s_change' % (microsite._meta.app_label, "microsite"), # pylint: disable=protected-access
f'admin:{microsite._meta.app_label}_microsite_change', # pylint: disable=protected-access
args=[microsite.id],
)
domains.append('<a href="%s">%s</a>' % (url, microsite.subdomain))
domains.append(f'<a href="{url}">{microsite.subdomain}</a>')

return mark_safe('\n'.join(domains))

Expand All @@ -245,10 +245,10 @@ def tenants(self, org):

for tenant in tenants:
url = reverse(
'admin:%s_%s_change' % (tenant._meta.app_label, "tenantconfig"), # pylint: disable=protected-access
f'admin:{tenant._meta.app_label}_tenantconfig_change', # pylint: disable=protected-access
args=[tenant.id],
)
domains += ['<a href="%s">%s</a>' % (url, route.domain) for route in tenant.route_set.all()]
domains += [f'<a href="{url}">{route.domain}</a>' for route in tenant.route_set.all()]

return mark_safe('\n'.join(domains))

Expand Down
2 changes: 1 addition & 1 deletion eox_tenant/api/v1/tests/test_microsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUp(self):
subdomain='test.host',
values={'key': 'value'},
)
self.url_detail = '{url}{id}/'.format(url=self.url, id=self.microsite_example.pk)
self.url_detail = f'{self.url}{self.microsite_example.pk}/'

@patch_permissions
def test_get_microsites(self, _):
Expand Down
2 changes: 1 addition & 1 deletion eox_tenant/api/v1/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
domain='domain.host',
config=self.tenant_config,
)
self.url_detail = '{url}{id}/'.format(url=self.url, id=self.route_example.pk)
self.url_detail = f'{self.url}{self.route_example.pk}/'

@patch_permissions
def test_get_routes(self, _):
Expand Down
2 changes: 1 addition & 1 deletion eox_tenant/api/v1/tests/test_tenant_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):
theming_configs={'key': 'value'},
meta={'key': 'value'},
)
self.url_detail = '{url}{id}/'.format(url=self.url, id=self.tenant_config_example.pk)
self.url_detail = f'{self.url}{self.tenant_config_example.pk}/'

@patch_permissions
def test_get_tenant_configs(self, _):
Expand Down
2 changes: 1 addition & 1 deletion eox_tenant/async_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def tenant_from_sync_process(self):
if not host:
LOG.warning(
"Could not find the host information for eox_tenant.signals "
"for the task {sender}".format(sender=self.sender)
"for the task %s", self.sender
)

def get_host(_body):
Expand Down
2 changes: 1 addition & 1 deletion eox_tenant/edxapp_wrapper/backends/branding_api_l_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
try:
from lms.djangoapps.branding import api as branding_api
except ImportError:
branding_api = object
branding_api = object # pylint: disable=invalid-name


def get_branding_api():
Expand Down
2 changes: 1 addition & 1 deletion eox_tenant/management/commands/change_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Command(BaseCommand):
This function will iterate over all microsites objects
to change microsite prod domains to a stage versions.
Usage Example:
python manage.py lms change_domain ".i.stage.ednx.co" ".i.ecom.ednx.co" --signupsources --settings=production
python manage.py lms change_domain ".i.stage.ednx.co" ".i.ecom.ednx.co" --signupsources
"""
suffix_stage_domain = ""
suffix_stage_ecommerce_domain = ""
Expand Down
2 changes: 1 addition & 1 deletion eox_tenant/management/commands/change_signup_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Command(BaseCommand):
signupsources of a given domain with another domain.
Usage Example:
python manage.py lms change_signup_sources --from old.edunext.io --to new.edunext.io --settings=production
python manage.py lms change_signup_sources --from old.edunext.io --to new.edunext.io
"""

def add_arguments(self, parser):
Expand Down
45 changes: 23 additions & 22 deletions eox_tenant/management/commands/create_or_update_tenant_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,53 +88,54 @@ def merge_dict(self, base_dict, override):

return override

def handle(self, *args, **options):
def handle(self, *args, **options): # pylint: disable=too-many-branches
"""
Create or update TenantConfig and link related routes.
"""
external_key = options['external_key']
routes = options['routes']
configuration = options.get('config')
config_file_data = options.get('config_file_data')
tenant_configuration_values = configuration or config_file_data
override = options.get('override')
data = {
"external_key": options['external_key'],
"routes": options['routes'],
"tenant_configuration_values": options.get('config') or options.get('config_file_data'),
"override": options.get('override'),
}
# pylint: disable=no-member,protected-access
external_key_length = TenantConfig._meta.get_field("external_key").max_length
if external_key:
if len(str(external_key)) > external_key_length:
if data["external_key"]:
if len(str(data["external_key"])) > external_key_length:
LOG.warning(
"The external_key %s is too long, truncating to %s"
" characters. Please update external_key in admin.",
external_key,
data["external_key"],
external_key_length
)
# trim name as the column has a limit of 63 characters
external_key = external_key[:external_key_length]
data["external_key"] = data["external_key"][:external_key_length]
tenant, created = TenantConfig.objects.get_or_create(
external_key=external_key,
external_key=data["external_key"],
)
if created:
LOG.info("Tenant does not exist. Created new tenant: '%s'", tenant.external_key)
else:
LOG.info("Found existing tenant for: '%s'", tenant.external_key)

# split out lms, studio, theme, meta from configuration json
if tenant_configuration_values:
if data["tenant_configuration_values"]:
for field in TenantConfig._meta.get_fields():
if isinstance(field, JSONField):
name = field.name
value = tenant_configuration_values.get(name)
if value is not None:
if override:
setattr(tenant, name, value)
else:
base_value = getattr(tenant, name, {})
merged = self.merge_dict(base_value, value)
setattr(tenant, name, merged)
value = data["tenant_configuration_values"].get(name)
if not value:
continue
if data["override"]:
setattr(tenant, name, value)
else:
base_value = getattr(tenant, name, {})
merged = self.merge_dict(base_value, value)
setattr(tenant, name, merged)

tenant.save()
# next add routes and link them
for route in routes:
for route in data["routes"]:
route, created = Route.objects.update_or_create(
domain=route,
defaults={"config": tenant}
Expand Down
6 changes: 3 additions & 3 deletions eox_tenant/management/commands/edit_microsite_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def handle(self, *args, **options):

LOGGER.info("This command will affect the following sites:")
for tenant in query:
LOGGER.info("{} on: {}".format(tenant, tenant.subdomain))
LOGGER.info("%s on: %s", tenant, tenant.subdomain)

if not options['force']:
user_response = input("Continue? y/n: ")
Expand Down Expand Up @@ -134,7 +134,7 @@ def action_delete(self, tenant, keys):

tenant.save()
except KeyError:
LOGGER.info("Could not find key: {} on site {}".format(key, tenant))
LOGGER.info("Could not find key: %s on site %s", key, tenant)

def action_add(self, tenant, key, value):
"""
Expand All @@ -158,4 +158,4 @@ def action_add(self, tenant, key, value):

tenant.save()
except Exception: # pylint: disable=broad-except
LOGGER.info("Could not add key {} to site {}".format(key, tenant))
LOGGER.info("Could not add key %s to site %s", key, tenant)
8 changes: 4 additions & 4 deletions eox_tenant/management/commands/synchronize_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def handle(self, *args, **options):
model = getattr(models, valid_model)
queryset = model.objects.all()

LOGGER.info("Synchronize {} {} registers.".format(
len(queryset),
valid_model,
))
LOGGER.info("Synchronize %s %s registers.",
len(queryset),
valid_model,
)

for instance in queryset:
synchronize_tenant_organizations(instance)
Expand Down
2 changes: 2 additions & 0 deletions eox_tenant/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def process_request(self, request):
)
)

return None


class CurrentSiteMiddleware(MiddlewareMixin):
"""
Expand Down
2 changes: 1 addition & 1 deletion eox_tenant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Meta:
app_label = "eox_tenant"

def __str__(self):
return "<Org: {}>".format(self.name)
return f"<Org: {self.name}>"


class Microsite(models.Model):
Expand Down
19 changes: 10 additions & 9 deletions eox_tenant/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ def safer_associate_by_email(backend, details, user=None, *args, **kwargs):
users = list(backend.strategy.storage.user.get_users_by_email(email))
if not users:
return None
elif len(users) > 1:
if len(users) > 1:
raise EoxTenantAuthException(
backend,
'The given email address is associated with another account'
)
else:
if users[0].is_staff or users[0].is_superuser:
raise EoxTenantAuthException(
backend,
'It is not allowed to auto associate staff or admin users'
)
return {'user': users[0],
'is_new': False}
if users[0].is_staff or users[0].is_superuser:
raise EoxTenantAuthException(
backend,
'It is not allowed to auto associate staff or admin users'
)
return {'user': users[0],
'is_new': False}

return None
2 changes: 1 addition & 1 deletion eox_tenant/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Settings for eox_tenant project meant to be called on the edx-platform/*/envs/production.py module
"""

from .common import * # pylint: disable=wildcard-import
from .common import * # pylint: disable=wildcard-import,unused-wildcard-import

EDX_AUTH_BACKEND = \
'openedx.core.djangoapps.oauth_dispatch.dot_overrides.backends.EdxRateLimitedAllowAllUsersModelBackend'
Expand Down
Loading

0 comments on commit c42930b

Please sign in to comment.