From 99db7d102f991d8c67597e7c84c3e7933f7e1489 Mon Sep 17 00:00:00 2001 From: Beto Fandino Date: Fri, 17 May 2024 12:58:02 -0400 Subject: [PATCH] feat: refactor old commits --- .../edxapp_wrapper/backends/coursekey_h_v1.py | 56 ------------------- eox_core/middleware.py | 1 - 2 files changed, 57 deletions(-) delete mode 100644 eox_core/edxapp_wrapper/backends/coursekey_h_v1.py diff --git a/eox_core/edxapp_wrapper/backends/coursekey_h_v1.py b/eox_core/edxapp_wrapper/backends/coursekey_h_v1.py deleted file mode 100644 index aa0481543..000000000 --- a/eox_core/edxapp_wrapper/backends/coursekey_h_v1.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" -Backend for the CourseKey validations that works under the open-release/hawthorn.beta1 tag -""" -# pylint: disable=import-error, protected-access -from __future__ import absolute_import, unicode_literals - -import logging - -from django.conf import settings -from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey -from rest_framework.serializers import ValidationError - -LOG = logging.getLogger(__name__) - -try: - from openedx.core.djangoapps.site_configuration.helpers import get_all_orgs, get_current_site_orgs -except ImportError: - get_all_orgs, get_current_site_orgs = object, object # pylint: disable=invalid-name - LOG.error("ImportError while importing on get_all_orgs, get_current_site_orgs") - - -def get_valid_course_key(course_id): - """ - Return the CourseKey if the course_id is valid - """ - try: - return CourseKey.from_string(course_id) - except InvalidKeyError: - raise ValidationError(f"Invalid course_id {course_id}") from InvalidKeyError - - -def validate_org(course_id): - """ - Validate the course organization against all possible orgs for the site - - To determine if the Org is valid we must look at 3 things - 1 Orgs in the current site - 2 Orgs in other sites - 3 flag EOX_CORE_USER_ENABLE_MULTI_TENANCY - """ - - if not settings.EOX_CORE_USER_ENABLE_MULTI_TENANCY: - return True - - course_key = get_valid_course_key(course_id) - current_site_orgs = get_current_site_orgs() or [] - - if not current_site_orgs: # pylint: disable=no-else-return - if course_key.org in get_all_orgs(): - return False - return True - else: - return course_key.org in current_site_orgs diff --git a/eox_core/middleware.py b/eox_core/middleware.py index 1561a8011..dbca630b6 100644 --- a/eox_core/middleware.py +++ b/eox_core/middleware.py @@ -44,7 +44,6 @@ class EoxTenantAuthException: ExceptionMiddleware = get_tpa_exception_middleware() - class PathRedirectionMiddleware(MiddlewareMixin): """ Middleware to create custom responses based on the request path